Control the view
There are several techniques you can use to control how the model is displayed in the main Thermal Desktop window:- Use the ThermalDesktop.VisibilityManager to get and set item and item label visibility.
- Use an object’s Layer member to change what layer it is on, perhaps moving it to or from a frozen layer.
- Use ThermalDesktop.GetLayers or .GetLayer to get an existing layer, then change its color, frozen status, and so on.
- Use an object’s ColorIndex member to directly change its color.
- Use ThermalDesktop.RestoreIsoView to set the view to one of the standard isometric views.
- Use ThermalDesktop.RestoreOrthoView to set the view to one of the standard orthographic views.
- Use ThermalDesktop.RestoreView to set the view to a pre-defined, custom named view. These can also contain layer settings. Create named views in the GUI using the AutoCAD “view” command.
- Use ThermalDesktop.SetView and either an IsoViews enum, an OrthoViews enum, or a string representing a named view to set the view.
- Use ThermalDesktop.SetVisualStyle to select wireframe, hidden, shaded, and more.
- Use ThermalDesktop.ResetGraphics to redraw everything in the main window.
- Display contour plots using the ThermalDesktop.DatasetManager. See the Reading result section.
Capture graphics area
Once you have set up the main TD view using the techniques discussed above, you may wish to capture the graphics area as a bitmap for use elsewhere. To do this, use the ThermalDesktop.CaptureGraphicsArea method, with the following signature: System.Drawing.Bitmap ThermalDesktop.CaptureGraphicsArea() The Bitmap object it returns can be saved to a file, or further processed within your program. Known issue: if AutoCAD is in fast-shaded mode then this command will return an all-black image if the visual style is set to SHADED, SHADED_W_EDGES, or WIRE.Working with the selection set
OpenTD allows you to ask the end user to select entities on screen, just like a TD command. It also allows you to do the opposite: set the selection set programmatically. These two operations are performed with the ThermalDesktop.GetSelection and SetSelection methods, respectively. There is also a ClearSelection method. GetSelection returns a list of EntityDescriptors, each containing a Connection for a selected entity and a string called RawType from AutoCAD describing what it is. For example, if the user selected a node, the RawType would be “RcNode”. EntityDescriptors are also returned by the ThermalDesktop.GetEntityType and GetEntityTypes methods, which can be used to determine entity types from handles. The following program demonstrates working with selection sets. It also uses the LINQ query syntax (for example: ‘from node in td.GetNodes() where node.Submodel == “MAIN”…’), which is a declarative syntax that can be easier to read than the method syntax we have used previously.Using loggers
Using log files to record program operations and errors can be a helpful technique, especially when debugging problems. OpenTD offers access to a powerful logging framework, the same one used by us within TD. To use the logging framework, you will create an OpenTD.Logging.Logger object, then call various methods on it to send messages to log files. The messages have one of the following levels assigned to them, from most to least important: Error, Warning, Information, and Verbose. Loggers are created using the LoggerFactory class, usually as a static member of a class. For example, here is the one we use internally for the ThermalDesktop class:%localappdata%\ThermalDesktop directory.
Two types of objects are defined in the configuration file: loggers and listeners. Loggers emit messages, while listeners route them to destinations. In each case, they only act on messages that are at or above the level they are defined at.
You’ll note that in the default configuration file, we have defined several loggers for various versions of OpenTD. For example:
%localappdata%\ThermalDesktop\log\OpenTD.Client.log, while listener ErrorLog will only write Error-level messages to OpenTD.Client.Error.log. And the OpenTDDemos listener will write any-level messages to OpenTDDemos.log.
Using the default configuration file, let’s look at some examples of how messages are routed to files.
Example 1
The Logger called “OpenTD.ThermalDesktop” sends an Error-level message:Example 2
The Logger called “OpenTD.ThermalDesktop” sends a Verbose-level message:Example 3
A logger in a client program is defined with the name “SatelliteBuilder.BusBuilder”:Miscellaneous end-user interaction techniques
- ThermalDesktop.ProgressBar can be used to show a progress bar and message in the TD window during long calculations.
- ThermalDesktop.Print prints a message to the AutoCAD console.
- The User Coordinate System (UCS) can be queried or set using the ThermalDesktop.UCS property.
- Model Browser visibility can be controlled using the ThermalDesktop.ShowModelBrowser and HideModelBrowser methods.
- Get a System.Windows.Forms.NativeWindow representing the main AutoCAD window using the ThermalDesktop.GetMainWindow() method. NativeWindow implements the IWin32Window interface, so this object can be used anywhere your application requires an IWin32Window that represents the main AutoCAD window.