Turning on “Editor” Mode in Mechanical SDK

Dmytro Kabenok

July 23, 2020

There are two ways that you can work with Mechanical SDK: "enabler" or "editor" mode. The method you use generally depends on whether you want to work with existing mechanical files and objects as-is or convert them to the current version.

The default mode is "enabler,” which reads and renders a database that contains mechanical entities as-is, without validation checks or creating additional objects. Files of older versions can be rendered incorrectly in enabler mode because Mechanical SDK does not convert all objects to the current mechanical version (this applies primarily to different revisions of symbol standards). No special actions are required to use this mode — just load the mechanical modules.

The other mode is “editor,” which provides full functionality for interacting with mechanical objects: creating, editing, removing, saving to different versions, and so on. If using this mode, all objects during file reading are converted to the latest mechanical version. Missing objects from the basic set are also created for correctly operating with the mechanical database. For using Mechanical SDK in this mode, you must create an OdDbDatabaseMech database object, not an OdDbDatabase object.

The ability to switch modes was added in release 20.8.

Example

In Mechanical SDK code examples, the MyServices class (inherited from the OdDbHostAppService class through intermediaries) is used for specific operations with modules. OdDbHostAppService has a special databaseClass() method that is used for database creation. So if you want to use Mechanical SDK in “editor” mode, just override the databaseClass() method, and that will return the static OdRxClass description for the new database.

class MyServices : public ExSystemServices, public ExHostAppServices
{
protected:
  ODRX_USING_HEAP_OPERATORS(ExSystemServices);
public:
  virtual OdRxClass* databaseClass() const
  {
    return OdDbDatabaseMech::desc();
  };

Next, create a service object, initialize it, and create a database.

// create MyServices object
OdStaticRxObject svcs;

//init ODA Platform
odInitialize(&svcs);

// load Mechanical modules
LoadTeighaMechanicalModules(false);

// next code creates an OdDbDatabaseMech object that allows you to use Mechanical SDK // in “editor” mode
OdDbDatabasePtr pDb = svcs.createDatabase(true, OdDb::kMetric);
pDb-> …