]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Editing lines by points dragging
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 1 Dec 2014 17:22:23 +0000 (20:22 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 1 Dec 2014 17:22:23 +0000 (20:22 +0300)
src/ModuleBase/ModuleBase_IPropertyPanel.h
src/ModuleBase/ModuleBase_Operation.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_Selection.cpp

index 00ff516b8c3ac9dcca21e7fb545e028d86f90af0..393137e5b6e4822d93ae58bc5517f5020205d1a3 100644 (file)
@@ -19,7 +19,7 @@ class MODULEBASE_EXPORT ModuleBase_IPropertyPanel : public QDockWidget
 {
 Q_OBJECT
 public:
-  ModuleBase_IPropertyPanel(QWidget* theParent) : QDockWidget(theParent) {}
+  ModuleBase_IPropertyPanel(QWidget* theParent) : QDockWidget(theParent), myIsEditing(false) {}
 
   /// Returns currently active widget
   virtual ModuleBase_ModelWidget* activeWidget() const = 0;
@@ -27,6 +27,10 @@ public:
   /// Returns all property panel's widget created by WidgetFactory
   virtual const QList<ModuleBase_ModelWidget*>& modelWidgets() const = 0;
 
+  /// Editing mode depends on mode of current operation. This value is defined by it.
+  void setEditingMode(bool isEditing) { myIsEditing = isEditing; }
+  bool isEditingMode() const { return myIsEditing; }
+
 signals:
   /// The signal about key release on the control, that corresponds to the attribute
   /// \param theEvent key release event
@@ -51,6 +55,9 @@ public slots:
   // highlighting from the previous active widget
   // emits widgetActivated(theWidget) signal
   virtual void activateWidget(ModuleBase_ModelWidget* theWidget) = 0;
+
+protected:
+  bool myIsEditing;
 };
 
 #endif
\ No newline at end of file
index b88becde9d0da6a551319b9e2ef75af5d5d8de1d..0d00b7c3b671b68c598de4911d38c4ab3d38a47c 100644 (file)
@@ -270,18 +270,6 @@ bool ModuleBase_Operation::activateByPreselection()
       return true;
     }
   }
-
-  //ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
-  //if ((myPreSelection.size() > 0) && aActiveWgt) {
-  //  const ModuleBase_ViewerPrs& aPrs = myPreSelection.first();
-  //  ModuleBase_WidgetValueFeature aValue;
-  //  aValue.setObject(aPrs.object());
-  //  if (aActiveWgt->setValue(&aValue)) {
-  //    myPreSelection.removeOne(aPrs);
-  //    myPropertyPanel->activateNextWidget();
-  //  }
-  //  // If preselection is enough to make a valid feature - apply it immediately
-  //}
   return false;
 }
 
@@ -364,6 +352,7 @@ void ModuleBase_Operation::clearPreselection()
 void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) 
 { 
   myPropertyPanel = theProp; 
+  myPropertyPanel->setEditingMode(isEditOperation());
   //connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this,
   //        SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
   if (myPropertyPanel) {
index ba997dcd37879ac691669d57c1304512aecd2242..93f886f13e67b3a78a4029f3ef66e538f8e2e3bb 100644 (file)
 #include <SketchPlugin_ConstraintRigid.h>
 
 #include <Events_Loop.h>
+
 #include <StdSelect_TypeOfFace.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Shape.hxx>
+#include <BRep_Tool.hxx>
 
 #include <QObject>
 #include <QMouseEvent>
@@ -214,9 +219,10 @@ void PartSet_Module::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
 
 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
 {
+  ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
   // Restart last operation type 
   if ((theOperation->id() == myLastOperationId) && myLastFeature) {
-    ModuleBase_ModelWidget* aWgt = theOperation->propertyPanel()->activeWidget();
+    ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
     if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
       // Initialise new line with first point equal to end of previous
       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
@@ -236,19 +242,20 @@ void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
     // Start editing constraint
     if (theOperation->isEditOperation()) {
       std::string aId = theOperation->id().toStdString();
-      if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
-          (aId == SketchPlugin_ConstraintLength::ID()) || 
-          (aId == SketchPlugin_ConstraintDistance::ID())) {
-        ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
-        // Find and activate widget for management of point for dimension line position
-        QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
-        foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
-          PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
-          if (aPntWgt) {
-            aPanel->activateWidget(aPntWgt);
-            return;
+      if (sketchOperationIdList().contains(QString(aId.c_str()))) {
+        if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
+            (aId == SketchPlugin_ConstraintLength::ID()) || 
+            (aId == SketchPlugin_ConstraintDistance::ID())) {
+          // Find and activate widget for management of point for dimension line position
+          QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
+          foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
+            PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
+            if (aPntWgt) {
+              aPanel->activateWidget(aPntWgt);
+              return;
+            }
           }
-        }
+        } 
       }
     }
   }
@@ -275,7 +282,7 @@ void PartSet_Module::onSelectionChanged()
   }
 }
 
-void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
+void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) 
 {
   if (!(theEvent->buttons() & Qt::LeftButton))
     return;
@@ -301,12 +308,23 @@ void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent*
     // Remember highlighted objects for editing
     ModuleBase_ISelection* aSelect = myWorkshop->selection();
     QList<ModuleBase_ViewerPrs> aObjects = aSelect->getHighlighted();
-     myEditingFeatures.clear();
+    myEditingFeatures.clear();
+    myEditingAttr.clear();
     if (aObjects.size() > 0) {
       foreach(ModuleBase_ViewerPrs aPrs, aObjects) {
         FeaturePtr aFeature = ModelAPI_Feature::feature(aObjects.first().object());
-        if (aFeature)
+        if (aFeature) {
           myEditingFeatures.append(aFeature);
+          TopoDS_Shape aShape = aPrs.shape();
+          if (!aShape.IsNull()) {
+            if (aShape.ShapeType() == TopAbs_VERTEX) {
+              AttributePtr aAttr = PartSet_Tools::findAttributeBy2dPoint(myEditingFeatures.first(), 
+                                                                         aShape, myCurrentSketch);
+              if (aAttr)
+                myEditingAttr.append(aAttr);
+            }
+          }
+        }
       }
     } 
     // If nothing highlighted - return
@@ -314,12 +332,6 @@ void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent*
       return;
 
     if (isSketcher) {
-      CompositeFeaturePtr aSketch = 
-        std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aOperation->feature());
-      if (!PartSet_Tools::sketchPlane(aSketch))
-        return;
-      
-      //myCurrentSketch = aOperation->feature();
       myIsDragging = true;
       get2dPoint(theWnd, theEvent, myCurX, myCurY);
       myDragDone = false;
@@ -328,6 +340,7 @@ void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent*
       launchEditing();
 
     } else if (isSketchOpe && isEditing) {
+      // If selected another object
       aOperation->abort();
 
       myIsDragging = true;
@@ -376,9 +389,9 @@ ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeat
 
 void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  myWorkshop->viewer()->enableSelection(true);
   if (myIsDragging) {
     myIsDragging = false;
-    myWorkshop->viewer()->enableSelection(true);
     if (myDragDone)
       myWorkshop->currentOperation()->commit();
   }
@@ -400,22 +413,33 @@ void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* t
     double dX =  aX - myCurX;
     double dY =  aY - myCurY;
 
-    std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
-      std::dynamic_pointer_cast<SketchPlugin_Feature>(aOperation->feature());
-    if (aSketchFeature) { 
-      aSketchFeature->move(dX, dY);
-      ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
-      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-    }/* else { // Alternative case for moving
+    if ((aOperation->id().toStdString() == SketchPlugin_Line::ID()) &&
+        (myEditingAttr.size() > 0) && 
+        myEditingAttr.first()) {
+      // probably we have prehighlighted point
+      AttributePtr aAttr = myEditingAttr.first();
+      std::string aAttrId = aAttr->id();
       ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
       QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
-      foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
-        PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
-        if (aWgt2d) {
-          aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
+      // Find corresponded widget to provide dragging
+      foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
+        if (aWgt->attributeID() == aAttrId) {
+          PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
+          if (aWgt2d) {
+            aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
+            break;
+          }
         }
       }
-    }*/
+    } else {
+      std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+        std::dynamic_pointer_cast<SketchPlugin_Feature>(aOperation->feature());
+      if (aSketchFeature) { 
+        aSketchFeature->move(dX, dY);
+        ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
+        Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+      }
+    }
     myDragDone = true;
     myCurX = aX;
     myCurY = aY;
index 305cd88e7f6b09487f9a19c0e01e8a5c37b3f6cb..eb8fb58217b6c900be22d30e7a413247540a44ba 100644 (file)
@@ -8,6 +8,7 @@
 #include <ModuleBase_ViewerFilters.h>
 #include <XGUI_Command.h>
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Attribute.h>
 #include <ModelAPI_CompositeFeature.h>
 
 #include <StdSelect_FaceFilter.hxx>
@@ -106,6 +107,7 @@ protected slots:
    double myCurX, myCurY;
    CompositeFeaturePtr myCurrentSketch;
    QList<FeaturePtr> myEditingFeatures;
+   QList<AttributePtr> myEditingAttr;
 
    Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
 };
index 04655869a267485433239823aba809a68e8a63ac..001224625b2a41b7a689b00a5e7491dd3ce71df1 100644 (file)
@@ -150,6 +150,11 @@ void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
 
 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
 {
+  // TO CHECK: Editing operation does not have automatical activation of widgets
+  if (isEditingMode()) {
+    activateWidget(NULL);
+    return;
+  }
   ModuleBase_ModelWidget* aNextWidget = 0;
   QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
   bool isFoundWidget = false;
@@ -210,6 +215,6 @@ void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
   myActiveWidget = theWidget;
   if (myActiveWidget)
     emit widgetActivated(theWidget);
-  else
+  else if (!isEditingMode())
     emit noMoreWidgets();
 }
index 0fcd179b8529a89d6562ebe77876ec6c5caae7e7..a2db13b1e69f334164a1c59e59120e66fcd105ee 100644 (file)
@@ -21,7 +21,8 @@ XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop)
 
 QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
 {
-  //std::set<ObjectPtr> aPrsFeatures;
+  QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
+
   QList<ModuleBase_ViewerPrs> aPresentations;
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
 
@@ -29,17 +30,16 @@ QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip)
   if (aContext->HasOpenedContext()) {
     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
       ModuleBase_ViewerPrs aPrs;
-
       Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
+      if (aSelectedIds.contains((long)anIO.Access()))
+        continue;
+    
+      aSelectedIds.append((long)anIO.Access());
       aPrs.setInteractive(anIO);
 
       ObjectPtr aFeature = aDisplayer->getObject(anIO);
       // we should not check the appearance of this feature because there can be some selected shapes
       // for one feature
-      //if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) {
-      aPrs.setFeature(aFeature);
-        //aPrsFeatures.insert(aFeature);
-      //}
       TopoDS_Shape aShape = aContext->SelectedShape();
       if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
         aPrs.setShape(aShape);
@@ -50,17 +50,15 @@ QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip)
   } else {
     for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) {
       ModuleBase_ViewerPrs aPrs;
-
       Handle(AIS_InteractiveObject) anIO = aContext->Current();
+      if (aSelectedIds.contains((long)anIO.Access()))
+        continue;
+    
+      aSelectedIds.append((long)anIO.Access());
       aPrs.setInteractive(anIO);
 
       ObjectPtr aFeature = aDisplayer->getObject(anIO);
-      // we should not check the appearance of this feature because there can be some selected shapes
-      // for one feature
-      //if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) {
       aPrs.setFeature(aFeature);
-        //aPrsFeatures.insert(aFeature);
-      //}
       aPresentations.append(aPrs);
     }
   }
@@ -69,7 +67,7 @@ QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip)
 
 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
 {
-  //std::set<ObjectPtr> aPrsFeatures;
+  QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
   QList<ModuleBase_ViewerPrs> aPresentations;
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
 
@@ -77,15 +75,16 @@ QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSki
   for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
     ModuleBase_ViewerPrs aPrs;
     Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
+    if (aSelectedIds.contains((long)anIO.Access()))
+      continue;
+    
+    aSelectedIds.append((long)anIO.Access());
     aPrs.setInteractive(anIO);
 
     ObjectPtr aResult = aDisplayer->getObject(anIO);
     // we should not check the appearance of this feature because there can be some selected shapes
     // for one feature
-    //if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) {
-      aPrs.setFeature(aResult);
-      //aPrsFeatures.insert(aResult);
-    //}
+    aPrs.setFeature(aResult);
     if (aContext->HasOpenedContext()) {
       TopoDS_Shape aShape = aContext->DetectedShape();
       if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)