Salome HOME
Result attributes validators created
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index 4999e4f53ef03d6d221634c176eb9ca8563a21c1..6ddaeabe155a71db3cc1c02997f9671e7fa8fee8 100644 (file)
 #endif
 
 
-//const int SKETCH_PLANE_COLOR = Colors::COLOR_BROWN; /// the plane edge color
-const double SKETCH_WIDTH = 4.0; /// the plane edge width
-// face of the square-face displayed for selection of general plane
-const double PLANE_SIZE = 200;
-
-
 /*!Create and return new instance of XGUI_Module*/
 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(XGUI_Workshop* theWshop)
 {
@@ -112,10 +106,6 @@ XGUI_Workshop* PartSet_Module::workshop() const
 
 void PartSet_Module::createFeatures()
 {
-  Config_ModuleReader aXMLReader = Config_ModuleReader();
-  aXMLReader.readAll();
-  myFeaturesInFiles = aXMLReader.featuresInFiles();
-
   //!! Test registering of validators
   PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
@@ -124,6 +114,10 @@ void PartSet_Module::createFeatures()
   aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
   aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
   aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
+
+  Config_ModuleReader aXMLReader = Config_ModuleReader();
+  aXMLReader.readAll();
+  myFeaturesInFiles = aXMLReader.featuresInFiles();
 }
 
 void PartSet_Module::featureCreated(QAction* theFeature)
@@ -229,20 +223,7 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
 
-    PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
-    if (aSketchOp) {
-      if ((!aSketchOp->hasSketchPlane()) && (aSelected.size() > 0)) {
-        Handle(AIS_InteractiveObject) aAIS = aSelected.front().interactive();
-        if ((aAIS == myXPlane->impl<Handle(AIS_InteractiveObject)>()) ||
-            (aAIS == myYPlane->impl<Handle(AIS_InteractiveObject)>()) ||
-            (aAIS == myZPlane->impl<Handle(AIS_InteractiveObject)>()) ) {
-
-          Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(aAIS);
-          aSketchOp->setSketchPlane(aAISShape->Shape());
-        }
-      }
-    } else
-      aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
+    aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
   }
 }
 
@@ -280,7 +261,7 @@ void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
 
 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
 {
-  erasePlanes();
+  //erasePlanes();
   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
   myWorkshop->actionsMgr()->update();
 
@@ -292,10 +273,15 @@ void PartSet_Module::onFitAllView()
   myWorkshop->viewer()->fitAll();
 }
 
-void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeature)
+void PartSet_Module::onLaunchOperation(std::string theName, ObjectPtr theFeature)
 {
+  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
+  if (!aFeature) {
+    qDebug("Warning! Restart operation without feature!");
+    return;
+  }
   ModuleBase_Operation* anOperation = createOperation(theName.c_str(),
-                                                      theFeature ? theFeature->getKind() : "");
+                                                      theFeature ? aFeature->getKind() : "");
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp)
   {
@@ -303,10 +289,10 @@ void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeatur
     // Initialise operation with preliminary selection
     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-    aPreviewOp->initFeature(theFeature);
+    aPreviewOp->initFeature(aFeature);
     aPreviewOp->initSelection(aSelected, aHighlighted);
   } else {
-    anOperation->setEditingFeature(theFeature);
+    anOperation->setEditingFeature(aFeature);
   }
   sendOperation(anOperation);
   myWorkshop->actionsMgr()->updateCheckState();
@@ -318,25 +304,24 @@ void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
   aViewer->enableMultiselection(theEnabled);
 }
 
-void PartSet_Module::onStopSelection(const QFeatureList& theFeatures, const bool isStop)
+void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
 {
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   if (!isStop) {
-    QFeatureList::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
-    for (; anIt != aLast; anIt++) {
-      activateFeature((*anIt), false);
+    foreach(ObjectPtr aObject, theFeatures) {
+      activateFeature(aObject, false);
     }
   }
-  QResultList aResults;
-  foreach(FeaturePtr aFeature, theFeatures) {
-    if (aFeature->results().size() > 0) {
-      std::list<ResultPtr>& aResList = aFeature->results();
-      std::list<ResultPtr>::iterator aIt;
-      for (aIt = aResList.begin(); aIt != aResList.end(); ++aIt)
+  //ObjectPtr aResults;
+  //foreach(ObjectPtr aFeature, theFeatures) {
+/* TODO    if (aFeature->results().size() > 0) {
+      const std::list<ResultPtr>& aResList = aFeature->results();
+      std::list<ResultPtr>::const_iterator aIt;
+      for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt)
         aResults.append(*aIt);
     }
-  }
-  aDisplayer->stopSelection(aResults, isStop, false);
+  }*/
+  aDisplayer->stopSelection(theFeatures, isStop, false);
 
   XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
   aViewer->enableSelection(!isStop);
@@ -344,7 +329,7 @@ void PartSet_Module::onStopSelection(const QFeatureList& theFeatures, const bool
   aDisplayer->updateViewer();
 }
 
-void PartSet_Module::onSetSelection(const QResultList& theFeatures)
+void PartSet_Module::onSetSelection(const QList<ObjectPtr>& theFeatures)
 {
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   aDisplayer->setSelected(theFeatures, false);
@@ -359,7 +344,38 @@ void PartSet_Module::onCloseLocalContext()
 
 void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode)
 {
-  bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
+//  bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
+//  if (isDisplay) {
+    ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
+    PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
+    if (aPrevOp) {
+      std::list<FeaturePtr> aList = aPrevOp->subFeatures();
+      XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+      std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
+      std::list<FeaturePtr>::iterator aSFIt; 
+      for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
+        std::list<ResultPtr> aResults = (*aSFIt)->results();
+        std::list<ResultPtr>::iterator aIt;
+        for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
+          aDisplayer->activateInLocalContext((*aIt), aModes, false);
+        }
+      }
+    }
+/*      FeaturePtr aFeature = aPrevOp->feature();
+      if (aFeature) {
+        std::list<ResultPtr> aResList = aFeature->results();
+        std::list<ResultPtr>::iterator aIt;
+        for (aIt = aResList.begin(); aIt != aResList.end(); ++aIt) {
+          aDisplayer->deactivate((*aIt), false);
+        }
+      }
+    }*/
+    ModelAPI_EventCreator::get()->sendUpdated(theFeature, 
+        Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+//  }
+//  else
+//    ->erase(theFeature->firstResult(), true);
+/*  bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
   // TODO visualizePreview(theFeature, isDisplay, false);
   if (!isDisplay) {
     ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
@@ -372,15 +388,15 @@ void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode)
 
       std::list<FeaturePtr>::const_iterator anIt = aList.begin(),
                                             aLast = aList.end();
-      for (; anIt != aLast; anIt++)
-        visualizePreview((*anIt), false, false);
-      aDisplayer->updateViewer();
+      //TODO for (; anIt != aLast; anIt++)
+      //  visualizePreview((*anIt), false, false);
+      //aDisplayer->updateViewer();
     }
   }
 
   if (theMode == PartSet_OperationSketchBase::FM_Activation ||
       theMode == PartSet_OperationSketchBase::FM_Deactivation)
-    activateFeature(theFeature, true);
+    activateFeature(theFeature, true);*/
 }
 
 ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
@@ -435,15 +451,15 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   if (aPreviewOp) {
     connect(aPreviewOp, SIGNAL(featureConstructed(FeaturePtr, int)),
             this, SLOT(onFeatureConstructed(FeaturePtr, int)));
-    connect(aPreviewOp, SIGNAL(launchOperation(std::string, FeaturePtr)),
-            this, SLOT(onLaunchOperation(std::string, FeaturePtr)));
+    connect(aPreviewOp, SIGNAL(launchOperation(std::string, ObjectPtr)),
+            this, SLOT(onLaunchOperation(std::string, ObjectPtr)));
     connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
             this, SLOT(onMultiSelectionEnabled(bool)));
 
-    connect(aPreviewOp, SIGNAL(stopSelection(const QFeatureList&, const bool)),
-            this, SLOT(onStopSelection(const QFeatureList&, const bool)));
-    connect(aPreviewOp, SIGNAL(setSelection(const QFeatureList&)),
-            this, SLOT(onSetSelection(const QFeatureList&)));
+    connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)),
+            this, SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
+    connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)),
+            this, SLOT(onSetSelection(const QList<ObjectPtr>&)));
 
      connect(aPreviewOp, SIGNAL(closeLocalContext()),
              this, SLOT(onCloseLocalContext()));
@@ -468,54 +484,8 @@ void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
   Events_Loop::loop()->send(aMessage);
 }
 
-boost::shared_ptr<GeomAPI_Shape> getPlane(double theX, double theY, double theZ)
-{
-  boost::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
-  boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(theX, theY, theZ));
-  return GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
-}
 
-void PartSet_Module::showPlanes()
-{
-  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-  // Show selection planes
-  if (!myXPlane) {
-    boost::shared_ptr<GeomAPI_Shape> aPlaneX = getPlane(1, 0, 0);
-    myXPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
-    myXPlane->createShape(aPlaneX);
-    myXPlane->setColor(Colors::COLOR_RED);
-    myXPlane->setWidth(SKETCH_WIDTH);
-  }
-  if (!myYPlane) {
-    boost::shared_ptr<GeomAPI_Shape> aPlaneY = getPlane(0, 1, 0);
-    myYPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
-    myYPlane->createShape(aPlaneY);
-    myYPlane->setColor(Colors::COLOR_GREEN);
-    myYPlane->setWidth(SKETCH_WIDTH);
-  }
-  if (!myZPlane) {
-    boost::shared_ptr<GeomAPI_Shape> aPlaneZ = getPlane(0, 0, 1);
-    myZPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
-    myZPlane->createShape(aPlaneZ);
-    myZPlane->setColor(Colors::COLOR_BLUE);
-    myZPlane->setWidth(SKETCH_WIDTH);
-  }
-  aDisplayer->display(myXPlane, false);
-  aDisplayer->display(myYPlane, false);
-  aDisplayer->display(myZPlane, false);
-  aDisplayer->updateViewer();
-}
-
-void PartSet_Module::erasePlanes()
-{
-  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-  aDisplayer->erase(myXPlane, false);
-  aDisplayer->erase(myYPlane, false);
-  aDisplayer->erase(myZPlane, false);
-  aDisplayer->updateViewer();
-}
-
-void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
+/*void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
                                       const bool isUpdateViewer)
 {
   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
@@ -532,10 +502,9 @@ void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
     boost::shared_ptr<SketchPlugin_Feature> aSPFeature = 
       boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
     if (aSPFeature) {
-      showPlanes();
-      //boost::shared_ptr<GeomAPI_AISObject> anAIS = 
-      //  aSPFeature->getAISObject(aDisplayer->getAISObject(aResult));
-      //aDisplayer->redisplay(aResult, anAIS, false);
+      PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+      if (aSketchOp && !aSketchOp->hasSketchPlane())
+        showPlanes();
     }
   }
   else
@@ -543,17 +512,17 @@ void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
 
   if (isUpdateViewer)
     aDisplayer->updateViewer();
-}
+}*/
 
-void PartSet_Module::activateFeature(FeaturePtr theFeature, const bool isUpdateViewer)
+void PartSet_Module::activateFeature(ObjectPtr theFeature, const bool isUpdateViewer)
 {
   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-/* TODO  if (aPreviewOp) {
+  if (aPreviewOp) {
     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-    aDisplayer->activateInLocalContext(theFeature->firstResult(), aPreviewOp->getSelectionModes(theFeature),
-                                       isUpdateViewer);
-  }*/
+    std::list<int> aModes = aPreviewOp->getSelectionModes(theFeature);
+    aDisplayer->activateInLocalContext(theFeature, aModes, isUpdateViewer);
+  }
 }
 
 void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
@@ -581,8 +550,8 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
       boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
     if (!aSPFeature)
       continue;
-    visualizePreview((*anIt), true, false);
-    aDisplayer->activateInLocalContext((*anIt)->firstResult(), aModes, false);
+    //visualizePreview((*anIt), true, false);
+    aDisplayer->activateInLocalContext((*anIt), aModes, false);
   }
   aDisplayer->updateViewer();
 }
@@ -644,7 +613,7 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
                          Config_WidgetAPI* theWidgetApi, QList<ModuleBase_ModelWidget*>& theModelWidgets)
 {
   if (theType == "sketch-start-label") {
-    PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi);
+    PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, "");
     aWgt->setOperationsMgr(myWorkshop->operationMgr());
     theModelWidgets.append(aWgt);
     return aWgt->getControl();