]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/XGUI/XGUI_Workshop.cpp
Salome HOME
Task 5.1.7: To be able to export a part to a file and import it into an existing...
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index 3e552186df412c9db79d1f4484239e18c2992397..8198f5f1131d2dd80e5f329d87c23deb907ccf9c 100644 (file)
@@ -67,6 +67,7 @@
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Feature.h>
@@ -87,6 +88,9 @@
 #include <Events_InfoMessage.h>
 #include <Events_LongOp.h>
 
+#include <ExchangePlugin_ExportPart.h>
+#include <ExchangePlugin_ImportPart.h>
+
 #include <GeomAPI_Pnt.h>
 
 #include <ModuleBase_IModule.h>
@@ -183,6 +187,8 @@ static QString MyFilter2(QObject::tr("CAD Builder files (*.cadbld)"));
 static QString MyExtension(".cadbld");
 #endif
 
+static QString MyImportPartFilter(QObject::tr("Part files (*.shaperpart);;All files (*.*)"));
+
 
 //******************************************************
 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
@@ -470,6 +476,19 @@ void XGUI_Workshop::initMenu()
   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
   salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
 
+  aAction = salomeConnector()->addDesktopCommand("EXPORT_PART_CMD", tr("Export part..."),
+                                          tr("Export a part of the current document into a file"),
+                                          QIcon(), QKeySequence(),
+                                          false, "MEN_DESK_FILE");
+  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportPart()));
+
+  aAction = salomeConnector()->addDesktopCommand("IMPORT_PART_CMD", tr("Import part..."),
+                                          tr("Import structure of a part"),
+                                          QIcon(), QKeySequence(),
+                                          false, "MEN_DESK_FILE");
+  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportPart()));
+  salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
+
 #else
   // File commands group
   AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
@@ -1243,6 +1262,42 @@ void XGUI_Workshop::onWidgetObjectUpdated()
   myDisplayer->updateViewer();
 }
 
+//******************************************************
+void XGUI_Workshop::onImportPart()
+{
+  if (!abortAllOperations())
+    return;
+
+  //show file dialog, check if readable and open
+  qreal aRatio = ModuleBase_Tools::currentPixelRatio();
+  // If the ratio is > 1 (HD screen) then QT has a bug in
+  // displaying of system open file dialog (too small)
+  QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Import part"), QString(),
+        MyImportPartFilter, Q_NULLPTR,
+        ((aRatio > 1) ? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
+  if (!aFile.isNull()) {
+    ModuleBase_OperationFeature* anImportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
+        module()->createOperation(ExchangePlugin_ImportPart::ID()));
+    if (operationMgr()->startOperation(anImportPartOp)) {
+      // initialize the filename to be imported
+      FeaturePtr aFeature = anImportPartOp->feature();
+      aFeature->string(ExchangePlugin_ImportPart::FILE_PATH_ID())->setValue(aFile.toStdString());
+      ModuleBase_Tools::flushUpdated(aFeature);
+      operationMgr()->commitOperation();
+    }
+  }
+}
+
+//******************************************************
+void XGUI_Workshop::onExportPart()
+{
+  if (abortAllOperations()) {
+    ModuleBase_OperationFeature* anExportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
+        module()->createOperation(ExchangePlugin_ExportPart::ID()));
+    operationMgr()->startOperation(anExportPartOp);
+  }
+}
+
 //******************************************************
 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
 {