]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Construction elements are auxiliary entities:
authornds <natalia.donis@opencascade.com>
Wed, 4 Mar 2015 09:52:23 +0000 (12:52 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 4 Mar 2015 09:52:23 +0000 (12:52 +0300)
Construction change through a context popup menu.
Customize presentation by redisplay feature

src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/SketchPlugin/SketchPlugin_Feature.h
src/XGUI/XGUI_Displayer.cpp

index d31bf8f7c65fa5894e17120e87272916c46ac7ca..ec85146bc7249b2739cf6e6a5972d8da26db9baf 100644 (file)
@@ -38,6 +38,7 @@
 #include <XGUI_OperationMgr.h>
 #include <XGUI_PropertyPanel.h>
 #include <XGUI_ModuleConnector.h>
+#include <XGUI_ContextMenuMgr.h>
 #include <XGUI_Tools.h>
 
 #include <SketchPlugin_Feature.h>
@@ -293,8 +294,19 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const
         hasFeature = true;
       }
     }
-    if (hasFeature)
+    if (hasFeature) {
+      XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
+      XGUI_Workshop* aWorkshop = aConnector->workshop();
+      QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
+      theMenu->addAction(anAction);
       theMenu->addAction(action("DELETE_PARTSET_CMD"));
+    }
+  }
+  bool isConstruction;
+  if (mySketchMgr->canChangeConstruction(isConstruction)) {
+    QAction* anAction = action("CONSTRUCTION_CMD");
+    theMenu->addAction(anAction);
+    anAction->setChecked(isConstruction);
   }
 }
 
@@ -478,8 +490,14 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
 
 void PartSet_Module::createActions()
 {
-  QAction* aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
-  addAction("DELETE_PARTSET_CMD", aAction);
+  QAction* anAction;
+
+  anAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
+  addAction("DELETE_PARTSET_CMD", anAction);
+
+  anAction = new QAction(tr("Construction"), this);
+  anAction->setCheckable(true);
+  addAction("CONSTRUCTION_CMD", anAction);
 }
 
 QAction* PartSet_Module::action(const QString& theId) const
@@ -506,6 +524,9 @@ void PartSet_Module::onAction(bool isChecked)
   if (anId == "DELETE_PARTSET_CMD") {
     deleteObjects();
   }
+  if (anId == "CONSTRUCTION_CMD") {
+    mySketchMgr->setConstruction(isChecked);
+  }
 }
 
 void PartSet_Module::deleteObjects()
index 30f1523b975c0a7b427234c22bf4dedde442742f..1cfe39ac0319a8e87dcecfe3be01880b42bc57da 100644 (file)
@@ -572,6 +572,21 @@ bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOpera
          PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
 }
 
+bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
+{
+  return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
+}
+
+bool PartSet_SketcherMgr::isEntityOperation(ModuleBase_Operation* theOperation)
+{
+  std::string aId = theOperation ? theOperation->id().toStdString() : "";
+
+  return (aId == SketchPlugin_Line::ID()) ||
+         (aId == SketchPlugin_Point::ID()) ||
+         (aId == SketchPlugin_Arc::ID()) ||
+         (aId == SketchPlugin_Circle::ID());
+}
+
 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
 {
   std::string aId = theOperation ? theOperation->id().toStdString() : "";
@@ -717,6 +732,48 @@ bool PartSet_SketcherMgr::canDisplayObject() const
   return aCanDisplay;
 }
 
+bool PartSet_SketcherMgr::canChangeConstruction(bool& isConstruction) const
+{
+  ModuleBase_Operation* anOperation = getCurrentOperation();
+
+  bool anEnabled = PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
+                   PartSet_SketcherMgr::isEntityOperation(anOperation);
+  if (anEnabled) {
+    std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+            std::dynamic_pointer_cast<SketchPlugin_Feature>(anOperation->feature());
+    if (aSketchFeature.get() != NULL) {
+      std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
+
+      std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr = 
+        std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
+
+      isConstruction = aConstructionAttr->value();
+    }
+  }
+  return anEnabled;
+}
+  
+void PartSet_SketcherMgr::setConstruction(const bool isChecked)
+{
+  ModuleBase_Operation* anOperation = getCurrentOperation();
+  std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+          std::dynamic_pointer_cast<SketchPlugin_Feature>(anOperation->feature());
+  if (aSketchFeature.get() != NULL) {
+    std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
+
+    std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr = 
+      std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
+    aConstructionAttr->setValue(isChecked);
+
+    // ModuleBase_ModelWidget::updateObject
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+    
+    static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+    ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
+    Events_Loop::loop()->flush(anEvent);
+  }
+}
+
 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
 {
   myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
@@ -877,11 +934,6 @@ ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
   return myModule->workshop()->currentOperation();
 }
 
-bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation) const
-{
-  return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
-}
-
 void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
                                            const bool isToDisplay)
 {
index 9f2f81051437d25e75161509d0288f81993b007e..57f17840fda7e640a7901c350c246531a5483b48 100644 (file)
@@ -87,7 +87,17 @@ public:
   /// \return the boolean result
   static bool isNestedSketchOperation(ModuleBase_Operation* theOperation);
 
-  /// Returns whethe the current operation is a sketch distance - lenght, distance or radius
+  /// Returns true if the operation is a create nested feature one
+  /// \param theOperation a checked operation
+  //// \return boolean value
+  static bool isNestedCreateOperation(ModuleBase_Operation* theOperation);
+
+  /// Returns whether the current operation is a sketch entity - line, point, arc or circle
+  /// \param the operation
+  /// \return a boolean value
+  static bool isEntityOperation(ModuleBase_Operation* theOperation);
+
+  /// Returns whether the current operation is a sketch distance - lenght, distance or radius
   /// \param the operation
   /// \return a boolean value
   static bool isDistanceOperation(ModuleBase_Operation* theOperation);
@@ -127,6 +137,15 @@ public:
   /// \param theObject a model object
   bool canDisplayObject() const;
 
+  /// Returns true if the current operation is sketch entity create operation
+  /// \param isConstruction the current construction state
+  /// \return the boolean result
+  bool canChangeConstruction(bool& isConstruction) const;
+  
+  /// Changes the sketcher entity construction argument value
+  /// \param isChecked if true, the feature is a construction
+  void setConstruction(const bool isChecked);
+
 public slots:
   /// Process sketch plane selected event
   void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
@@ -211,11 +230,6 @@ private:
   /// \return an operation
   ModuleBase_Operation* getCurrentOperation() const;
 
-  /// Returns true if the operation is a create nested feature one
-  /// \param theOperation a checked operation
-  //// \return boolean value
-  bool isNestedCreateOperation(ModuleBase_Operation* theOperation) const;
-
   /// Erase or display the feature of the current operation. If the mouse over the active view or
   /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
   /// \param theOperation an operation which feature is to be displayed, it is nested create operation
index a81a7f2c5a3c870da653d926d1fb402d05abe3b7..4915eec35201537b768103594bef64ad398602b6 100644 (file)
@@ -241,6 +241,10 @@ bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView,
 
 void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  // the contex menu release by the right button should not be processed by this widget
+  if (theEvent->button() != Qt::LeftButton)
+    return;
+
   XGUI_Selection* aSelection = myWorkshop->selector()->selection();
   Handle(V3d_View) aView = theWnd->v3dView();
   // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
index 9e22b9ce812c3472fd1fe948c55b4ec6106cb57e..607f66725fd652e53a5f197cc0aee2f38746b6ec 100644 (file)
@@ -92,11 +92,13 @@ class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
     if (aShapeType == 6) { // if this is an edge
       if (isConstruction) {
         thePrs->setWidth(1);
+        thePrs->setLineStyle(3);
         aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
                                          SKETCH_CONSTRUCTION_COLOR);
       }
       else {
         thePrs->setWidth(3);
+        thePrs->setLineStyle(0);
         if (isExternal()) {
           // Set color from preferences
           aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
index 401d1d3cafeb4997285ac69078ff9fbc24e625bc..6fc47e170982976ac55392ddddb624d2b90f9ced 100644 (file)
@@ -222,8 +222,12 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
     // Check that the visualized shape is the same and the redisplay is not necessary
     // Redisplay of AIS object leads to this object selection compute and the selection 
     // in the browser is lost
-    // become
-    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+
+    // this check is not necessary anymore because the selection store/restore is realized
+    // before and after the values modification.
+    // Moreother, this check avoids customize and redisplay presentation if the presentable
+    // parameter is changed.
+    /*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
     if (aResult.get() != NULL) {
       Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
       if (!aShapePrs.IsNull()) {
@@ -237,7 +241,15 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
             return;
         }
       }
+    }*/
+    // Customization of presentation
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+    if (aFeature.get() != NULL) {
+      GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
+      if (aCustPrs.get() != NULL)
+        aCustPrs->customisePresentation(aAISObj);
     }
+
     aContext->Redisplay(aAISIO, false);
     if (isUpdateViewer)
       updateViewer();