Class: Layout::Document
- Inherits:
-
Object
- Object
- Layout::Document
Overview
A layout document embedded within a model. Each model has one, obtained via ModraUp::Model#layout_document; accessing it after the model is closed throws a TypeError. The layout is saved with the model and does not have a separate .layout file.
Class Method Summary # collapse
-
.templates ⇒ Array<Hash>
Lists system drawing templates and user .osklt files, excluding the built-in blank template. Each entry is a Hash with string keys "name" and "path". System and user templates are each sorted by filename. Use #apply_template to apply a template.
Instance Method Summary # collapse
-
#apply_template(name_or_path) ⇒ Layout::Document
Apply a template to a document that has no drawings: import the page size, margins, border frames, grids, dynamic text, title block fields, layers, dimension styles, and page objects from the template; subsequently, Layout::Pages#add new pages will use the paper size and objects from the first interior page of the template. Templates without a cover page will use the first page.
-
#pages ⇒ Layout::Pages
All drawing pages in the order of the drawings.
-
#layers ⇒ Layout::Layers
The layer list is ordered with the first layer on top. A new document starts with a default layer and a shared layer named "Every Page Display".
-
#path ⇒ String
The file path of the model's layout document, which is an empty string if the document is not saved.
-
#page_info ⇒ Layout::PageInfo
The paper size and margins of the drawing sheet; all pages share a single set, applied to every page.
-
#add_entity(entity, layer, page) ⇒ Layout::Document
Place the newly created object on the drawing sheet, with one-step undo. If no page is given, layer must be a shared layer. If the object extends beyond the sheet edges, it is clipped back within the sheet boundaries. If the object is larger than the sheet, an ArgumentError is raised. After placement, the object's bounds can be retrieved using Layout::Entity#bounds.
-
#remove_entity(entity) ⇒ Layout::Document
Remove the entity, with one-step undo. When deleting a section or detail view, the section symbol or detail box on the source viewport is also removed, consistent with the interface.
-
#shared_entities ⇒ Layout::Entities
Objects on shared layers (displayed on every page).
-
#title_block ⇒ Layout::TitleBlock
Title block common fields (displayed in the title block by the template): project, company, designer, checker, approver, date.
-
#get_attribute(dictionary, key, default = nil) ⇒ Object
Read document-level plugin data.
-
#set_attribute(dictionary, key, value) ⇒ Object
Write document-level plugin data with a single undo step. The value can only be nil, true, false, a number, a string, an Array, or a Hash (with Hash keys as strings).
-
#delete_attribute(dictionary) ⇒ Boolean
Delete a key or an entire dictionary.
-
#export(file_path, options = nil) ⇒ nil
Exports sheets to PDF using the same process as the Export dialog. Missing or stale model views in the selected range are updated before the file is written. Failure, cancellation, or a model change during export preserves the original file. The call returns immediately. On completion, the block receives ok, indicating whether the file was written, and message, the result shown in the interface. On success the message includes vector and raster view counts. On failure it gives the reason. The block may call export again.
-
#== ⇒ Boolean
Is the drawing sheet for the same model document.
-
#inspect ⇒ String
A brief description.
-
#select_tool(tool) ⇒ Layout::Document
Select the paper tool. tool must be an object (with the same name and parameters) that implements ModraUp::Tool callback methods (ModraUp::Tool.activate, ModraUp::Tool.deactivate, ModraUp::Tool.onMouseMove, ModraUp::Tool.onLButtonDown, ModraUp::Tool.onLButtonUp, ModraUp::Tool.onLButtonDoubleClick, ModraUp::Tool.onRButtonDown, ModraUp::Tool.onRButtonUp, ModraUp::Tool.onKeyDown, ModraUp::Tool.onKeyUp, ModraUp::Tool.onReturn, ModraUp::Tool.onCancel, ModraUp::Tool.onUserText, ModraUp::Tool.enableVCB?, ModraUp::Tool.draw). The view parameter in the callback is a Layout::PaperView, and x and y are logical pixels within the paper area, which can be converted to paper coordinates using Layout::PaperView#paper_point. Entering this tool will take you to the drawing workspace; passing nil will return to the document selection tool.
-
#tool ⇒ Object, nil
The currently selected viewport tool; nil if none is selected.
-
#add_observer(observer) ⇒ Boolean
Add a drawing observer. Observers need only implement the methods they are interested in, with the first parameter always being the document:
-
#remove_observer(observer) ⇒ Boolean
Remove the document observer.
-
#selection ⇒ Array<Layout::Entity>
The current selection in the drawing workspace consists of the primary paper objects. If the document is not the current document being displayed in the workspace, the selection is an empty array.
-
#selection= ⇒ Layout::Entity, Array<Layout::Entity>, nil
Set the sheet selection. Accept an object, array of objects, or nil (to clear). The objects must be on the same drawing sheet (objects on shared layers are considered on each sheet); if not on the current sheet, switch to that sheet. This does not affect the undo history.
-
#active_page ⇒ Layout::Page, nil
The drawing sheet currently displayed in the Layout::Document active_page. Returns nil if the document is not the active page or there is no drawing sheet.
-
#active_page= ⇒ Layout::Page
Displays a different sheet in the drawing workspace and clears the paper-space selection. This change does not add an undo step.
Class Method Details
Layout::Document.templates ⇒ Array<Hash>
Lists system drawing templates and user .osklt files, excluding the built-in blank template. Each entry is a Hash with string keys "name" and "path". System and user templates are each sorted by filename. Use #apply_template to apply a template.
Instance Method Details
document.apply_template(name_or_path) ⇒ document
Apply a template to a document that has no drawings: import the page size, margins, border frames, grids, dynamic text, title block fields, layers, dimension styles, and page objects from the template; subsequently, Layout::Pages#add new pages will use the paper size and objects from the first interior page of the template. Templates without a cover page will use the first page.
These settings are overall taken from the template: any layers, grids, and title block fields added to the document are replaced, except for their extended attributes (#set_attribute). One-step undo.
document.pages ⇒ Layout::Pages
All drawing pages in the order of the drawings.
document.layers ⇒ Layout::Layers
The layer list is ordered with the first layer on top. A new document starts with a default layer and a shared layer named "Every Page Display".
document.path ⇒ String
The file path of the model's layout document, which is an empty string if the document is not saved.
document.page_info ⇒ Layout::PageInfo
The paper size and margins of the drawing sheet; all pages share a single set, applied to every page.
document.add_entity(entity, layer, page) ⇒ Layout::Documentdocument.add_entity(entity, shared_layer) ⇒ Layout::Document
Place the newly created object on the drawing sheet, with one-step undo. If no page is given, layer must be a shared layer. If the object extends beyond the sheet edges, it is clipped back within the sheet boundaries. If the object is larger than the sheet, an ArgumentError is raised. After placement, the object's bounds can be retrieved using Layout::Entity#bounds.
document.remove_entity(entity) ⇒ Layout::Document
Remove the entity, with one-step undo. When deleting a section or detail view, the section symbol or detail box on the source viewport is also removed, consistent with the interface.
document.title_block ⇒ Layout::TitleBlock
Title block common fields (displayed in the title block by the template): project, company, designer, checker, approver, date.
document.get_attribute(dictionary, key, default = nil) ⇒ Object
Read document-level plugin data.
document.set_attribute(dictionary, key, value) ⇒ Object
Write document-level plugin data with a single undo step. The value can only be nil, true, false, a number, a string, an Array, or a Hash (with Hash keys as strings).
document.delete_attribute(dictionary) ⇒ Booleandocument.delete_attribute(dictionary, key) ⇒ Boolean
Delete a key or an entire dictionary.
document.export(file_path, options = nil) ⇒ nildocument.export(file_path, options = nil) { |ok, message| ... } ⇒ nil
Exports sheets to PDF using the same process as the Export dialog. Missing or stale model views in the selected range are updated before the file is written. Failure, cancellation, or a model change during export preserves the original file. The call returns immediately. On completion, the block receives ok, indicating whether the file was written, and message, the result shown in the interface. On success the message includes vector and raster view counts. On failure it gives the reason. The block may call export again.
Option keys may be strings or symbols. start_page and end_page select a 1-based inclusive range, defaulting to all sheets. update_views defaults to true. When false, the exporter reuses previews, except that it still renders views with size or camera mismatches. prefer_vector defaults to true and prioritizes vector lines and annotations. The exporter accepts output_resolution, compress_images, and compress_quality without applying them. update_views and prefer_vector are ModraUp extensions.
document == other ⇒ Boolean
Is the drawing sheet for the same model document.
document.inspect ⇒ String
A brief description.
document.select_tool(tool) ⇒ Layout::Document
Select the paper tool. tool must be an object (with the same name and parameters) that implements ModraUp::Tool callback methods (ModraUp::Tool.activate, ModraUp::Tool.deactivate, ModraUp::Tool.onMouseMove, ModraUp::Tool.onLButtonDown, ModraUp::Tool.onLButtonUp, ModraUp::Tool.onLButtonDoubleClick, ModraUp::Tool.onRButtonDown, ModraUp::Tool.onRButtonUp, ModraUp::Tool.onKeyDown, ModraUp::Tool.onKeyUp, ModraUp::Tool.onReturn, ModraUp::Tool.onCancel, ModraUp::Tool.onUserText, ModraUp::Tool.enableVCB?, ModraUp::Tool.draw). The view parameter in the callback is a Layout::PaperView, and x and y are logical pixels within the paper area, which can be converted to paper coordinates using Layout::PaperView#paper_point. Entering this tool will take you to the drawing workspace; passing nil will return to the document selection tool.
The paper tool does not affect 3D tools in the model. The deactivate method is called when space is pressed, the built-in drawing tool is selected, the model is selected, or the document is switched. Middle mouse drag and scroll wheel zoom are still handled by the paper tool.
document.tool ⇒ Object or nil
The currently selected viewport tool; nil if none is selected.
document.add_observer(observer) ⇒ Boolean
Add a drawing observer. Observers need only implement the methods they are interested in, with the first parameter always being the document:
- onDocumentChanged(document): The drawing definition is modified, including UI edits, Ruby writes, undo, and redo. - onSelectionChanged(document): The sheet selection changes, see #selection. - onActivePageChanged(document, page): The current drawing changes, page may be nil. - onWorkspaceChanged(document, active): Entering (true) or leaving (false) the drawing workspace. - onViewsUpdated(document): A batch of model views are updated in the background (excluding exports). - onExportComplete(document, path, ok, message): The PDF export is complete, including UI-initiated exports.
Notifications are delivered in the event loop at a later time, and multiple consecutive changes may be merged into one. Only the document currently displayed in the drawing workspace (the active model) receives notifications; switching documents does not send notifications. Observers are automatically removed when the model is closed.
document.remove_observer(observer) ⇒ Boolean
Remove the document observer.
document.selection ⇒ Array<Layout::Entity>
The current selection in the drawing workspace consists of the primary paper objects. If the document is not the current document being displayed in the workspace, the selection is an empty array.
document.selection = entities
Set the sheet selection. Accept an object, array of objects, or nil (to clear). The objects must be on the same drawing sheet (objects on shared layers are considered on each sheet); if not on the current sheet, switch to that sheet. This does not affect the undo history.
document.active_page ⇒ Layout::Page or nil
The drawing sheet currently displayed in the Layout::Document active_page. Returns nil if the document is not the active page or there is no drawing sheet.
document.active_page = page
Displays a different sheet in the drawing workspace and clears the paper-space selection. This change does not add an undo step.