]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issues #248, #235 The obtaining of the point from the TopoDS_Vertex shape during...
authornds <natalia.donis@opencascade.com>
Fri, 7 Nov 2014 16:09:17 +0000 (19:09 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 7 Nov 2014 16:09:17 +0000 (19:09 +0300)
Moving the algorithm of a point get from a Vertex shape into a tool method to be called where it is necessary.

src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/PartSet/PartSet_OperationFeatureBase.cpp
src/PartSet/PartSet_OperationFeatureBase.h
src/PartSet/PartSet_OperationFeatureCreate.cpp
src/PartSet/PartSet_OperationFeatureEdit.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h

index b3bf0b07572308f26b62a2fc2c177a4ae2eb24dc..e6a2e3d0a35bb7dc1417441bf6f7f225f97139e2 100644 (file)
@@ -13,6 +13,7 @@
 #include "ModuleBase_ViewerPrs.h"
 #include "ModuleBase_IPropertyPanel.h"
 #include "ModuleBase_ISelection.h"
+#include "ModuleBase_IViewer.h"
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Document.h>
@@ -48,6 +49,7 @@ ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* thePar
 ModuleBase_Operation::~ModuleBase_Operation()
 {
   delete myDescription;
+  clearPreselection();
 }
 
 QString ModuleBase_Operation::id() const
@@ -255,21 +257,15 @@ bool ModuleBase_Operation::activateByPreselection()
     return false;
   
   ModuleBase_ModelWidget* aWgt, *aFilledWgt = 0;
-  ModuleBase_ViewerPrs aPrs;
   QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
-  QList<ModuleBase_ViewerPrs>::const_iterator aPIt;
+  QList<ModuleBase_WidgetValueFeature*>::const_iterator aPIt;
   bool isSet = false;
   for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin();
        (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd());
        ++aWIt, ++aPIt) {
     aWgt = (*aWIt);
-    aPrs = (*aPIt);
-    ModuleBase_WidgetValueFeature aValue;
-    aValue.setObject(aPrs.object());
-    // Check if the selection has a selected point
-    // for today it is impossible to do because
-    // the selected point demands convertation to Sketch plane 2d
-    if (!aWgt->setValue(&aValue)) {
+    ModuleBase_WidgetValueFeature* aValue = (*aPIt);
+    if (!aWgt->setValue(aValue)) {
       isSet = false;
       break;
     } else {
@@ -305,14 +301,16 @@ bool ModuleBase_Operation::activateByPreselection()
 }
 
 void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection,
-                                         ModuleBase_IViewer* /*theViewer*/)
+                                         ModuleBase_IViewer* theViewer)
 {
-  myPreSelection.clear();
+  clearPreselection();
 
+  QList<ModuleBase_ViewerPrs> aPreSelected;
   // Check that the selected result are not results of operation feature
-  QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
   FeaturePtr aFeature = feature();
   if (aFeature) {
+    QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+
     std::list<ResultPtr> aResults = aFeature->results();
     QList<ObjectPtr> aResList;
     std::list<ResultPtr>::const_iterator aIt;
@@ -321,10 +319,23 @@ void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection,
 
     foreach (ModuleBase_ViewerPrs aPrs, aSelected) {
       if ((!aResList.contains(aPrs.object())) && (aPrs.object() != aFeature))
-        myPreSelection.append(aPrs);
+        aPreSelected.append(aPrs);
     }
   } else
-    myPreSelection = aSelected;
+    aPreSelected = theSelection->getSelected();
+
+  // convert the selection values to the values, which are set to the operation widgets
+
+  Handle(V3d_View) aView = theViewer->activeView();
+  foreach (ModuleBase_ViewerPrs aPrs, aPreSelected) {
+    ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
+    aValue->setObject(aPrs.object());
+
+    double aX, anY;
+    if (getViewerPoint(aPrs, theViewer, aX, anY))
+      aValue->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
+    myPreSelection.append(aValue);
+  }
 }
 
 void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
@@ -351,6 +362,19 @@ bool ModuleBase_Operation::setWidgetValue(ObjectPtr theFeature, double theX, dou
   return isApplyed;
 }
 
+bool ModuleBase_Operation::getViewerPoint(ModuleBase_ViewerPrs thePrs,
+                                               ModuleBase_IViewer* theViewer,
+                                               double& theX, double& theY)
+{
+  return false;
+}
+
+void ModuleBase_Operation::clearPreselection()
+{
+  while (!myPreSelection.isEmpty()) {
+    delete myPreSelection.takeFirst();
+  }
+}
 
 void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) 
 { 
index 07b413218a832b294cee888c56e5553b58cbee02..cf92faa43ae2191e0419561c1bd3cba22089320d 100644 (file)
@@ -23,6 +23,7 @@ class ModuleBase_OperationDescription;
 class ModuleBase_IPropertyPanel;
 class ModuleBase_ISelection;
 class ModuleBase_IViewer;
+class ModuleBase_WidgetValueFeature;
 
 class QKeyEvent;
 
@@ -217,6 +218,20 @@ signals:
   /// \return true if the point is set
   virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
 
+  /// Return a widget value point by the selection and the viewer position
+  /// The default realization returns false
+  /// \param thePrs the presentation
+  /// \param theViewer a viewer to have the viewer the eye position
+  /// \param theX the horizontal coordinate
+  /// \param theY the vertical coordinate
+  /// \return true if the point exits in the selection
+  virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs,
+                                   ModuleBase_IViewer* theViewer,
+                                   double& theX, double& theY);
+
+  // Removes the preselection information and clears the map of preselection
+  void clearPreselection();
+
  protected:
   FeaturePtr myFeature;  /// the operation feature to be handled
 
@@ -233,7 +248,7 @@ signals:
   QStringList myNestedFeatures;
 
   /// List of pre-selected object 
-  QList<ModuleBase_ViewerPrs> myPreSelection;
+  QList<ModuleBase_WidgetValueFeature*> myPreSelection;
 
   /// Access to property panel
   ModuleBase_IPropertyPanel* myPropertyPanel;
index 6beb71ca409f2489b5d150de498434d5c0623600..2d06659a08638a18b69c809ed9595ce4936f1dc5 100644 (file)
@@ -73,19 +73,13 @@ void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, ModuleBa
     PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
   } else {
     ModuleBase_ViewerPrs aPrs = aSelected.first();
+    if (getViewerPoint(aPrs, theViewer, aX, anY)) {
+      ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+      PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
+    }
     const TopoDS_Shape& aShape = aPrs.shape();
-    if (!aShape.IsNull()) {
-      if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
-        const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
-        if (!aVertex.IsNull()) {
-          aPoint = BRep_Tool::Pnt(aVertex);
-          PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
-          ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
-          PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
-        }
-      } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
-        PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
-      }
+    if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
+      PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
     }
   }
   ObjectPtr aFeature;
@@ -110,6 +104,14 @@ void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, ModuleBa
     commit();
 }
 
+bool PartSet_OperationFeatureBase::getViewerPoint(ModuleBase_ViewerPrs thePrs,
+                                                       ModuleBase_IViewer* theViewer,
+                                                       double& theX, double& theY)
+{
+  return PartSet_Tools::hasVertexShape(thePrs, sketch(), theViewer->activeView(),
+                                       theX, theY);
+}
+
 /*bool PartSet_OperationFeatureBase::setWidgetValue(ObjectPtr theFeature, double theX, double theY)
 {
   ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
index bb74a4431642c6c76b314c2a0e6103840d7bd7bf..ee290dd44cbfdffe130c7ecfefcfd7328c176a2f 100644 (file)
@@ -45,6 +45,16 @@ Q_OBJECT
   virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
                              ModuleBase_ISelection* theSelection);
 
+ protected:
+  /// Return a widget value point by the selection and the viewer position
+  /// \param thePrs the presentation
+  /// \param theViewer a viewer to have the viewer the eye position
+  /// \param theX the horizontal coordinate
+  /// \param theY the vertical coordinate
+  /// \return true if the point exits in the selection
+  virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs,
+                                   ModuleBase_IViewer* theViewer,
+                                   double& theX, double& theY);
 
  protected:
   CompositeFeaturePtr mySketch;  ///< the sketch of the feature
index 49c8b24901b0e158c54736471d5ccfcb4bf1e294..eed4d1ea4781f696a19c0e342dc777137d883fed 100644 (file)
 #include <XGUI_Constants.h>
 
 #include <V3d_View.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS.hxx>
-#include <BRep_Tool.hxx>
-#include <TopoDS.hxx>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -119,26 +115,20 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Module
     PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
   } else {
     ModuleBase_ViewerPrs aPrs = aSelected.first();
+    if (getViewerPoint(aPrs, theViewer, aX, anY)) {
+      ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+      PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
+      isClosedContour = true;
+    }
     const TopoDS_Shape& aShape = aPrs.shape();
-    if (!aShape.IsNull()) {
-      if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
-        const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
-        if (!aVertex.IsNull()) {
-          aPoint = BRep_Tool::Pnt(aVertex);
-          PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
-          ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
-          PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
-          isClosedContour = true;
-        }
-      } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
-        ObjectPtr aObject = aPrs.object();
-        if (sketch()->isSub(aObject))
-          PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
-        else {
-          // we have to create the selected edge for the current sketch
-          ResultPtr aRes = PartSet_Tools::createFixedObjectByEdge(aPrs, sketch());
-          aSelected.first().setFeature(aRes);
-        }
+    if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
+      ObjectPtr aObject = aPrs.object();
+      if (sketch()->isSub(aObject))
+        PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
+      else {
+        // we have to create the selected edge for the current sketch
+        ResultPtr aRes = PartSet_Tools::createFixedObjectByEdge(aPrs, sketch());
+        aSelected.first().setFeature(aRes);
       }
     }
   }
index 6c6c19682ac89478cd53609f1916fff114a0c810..a49e63dc7149ce030c9f51ffdf73a700cd07038f 100644 (file)
@@ -28,9 +28,6 @@
 #include <SketchPlugin_Line.h>
 
 #include <V3d_View.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS.hxx>
-#include <BRep_Tool.hxx>
 #include <AIS_DimensionOwner.hxx>
 #include <AIS_DimensionSelectionMode.hxx>
 
@@ -89,14 +86,10 @@ void PartSet_OperationFeatureEdit::fillFeature2Attribute(
   // 1. find all features with skipping features with selected vertex shapes
   theFeature2Attribute.clear();
   // firstly, collect the features without local selection
+  double aX, anY;
   foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
-    const TopoDS_Shape& aShape = aPrs.shape();
-    if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
-      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
-      if (!aVertex.IsNull()) {
-        continue;
-      }
-    }
+    if (getViewerPoint(aPrs, theViewer, aX, anY))
+      continue;
     else {
       ObjectPtr aObject = aPrs.object();
       if (!aObject)
@@ -113,13 +106,8 @@ void PartSet_OperationFeatureEdit::fillFeature2Attribute(
   // if the list already has this feature, the local selection is skipped
   // that means that if the selection contains a feature and a feature with local selected point,
   // the edit is performed for a full feature
-  Handle(V3d_View) aView = theViewer->activeView();
   foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
-    const TopoDS_Shape& aShape = aPrs.shape();
-    if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
-      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
-      if (aVertex.IsNull())
-        continue;
+    if (getViewerPoint(aPrs, theViewer, aX, anY)) {
       ObjectPtr aObject = aPrs.object();
       if (!aObject)
         continue;
@@ -128,11 +116,8 @@ void PartSet_OperationFeatureEdit::fillFeature2Attribute(
         continue;
 
       // append the attribute of the vertex if it is found on the current feature
-      gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
-      double aVX, aVY;
-      PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aVX, aVY);
       boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D = PartSet_Tools::getFeaturePoint(
-                                                                    aFeature, aVX, aVY);
+                                                                    aFeature, aX, anY);
       std::string anAttribute = aFeature->data()->id(aPoint2D);
       std::list<std::string> aList;
       if (theFeature2Attribute.find(aFeature) != theFeature2Attribute.end())
index b5407f6f78a49a442fa64411b5d11eedcd93b7bc..d1369536111582223c3d8a32afcfb399a680a85d 100644 (file)
@@ -46,6 +46,7 @@
 #include <BRep_Tool.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
+#include <TopoDS_Vertex.hxx>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -486,4 +487,24 @@ ResultPtr PartSet_Tools::findExternalEdge(CompositeFeaturePtr theSketch, boost::
     }
   }
   return ResultPtr();
-}
\ No newline at end of file
+}
+
+bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
+                                   Handle_V3d_View theView, double& theX, double& theY)
+{
+  bool aHasVertex = false;
+
+  const TopoDS_Shape& aShape = thePrs.shape();
+  if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX)
+  {
+    const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
+    if (!aVertex.IsNull())
+    {
+      gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+      PartSet_Tools::convertTo2D(aPoint, theSketch, theView, theX, theY);
+      aHasVertex = true;
+    }
+  }
+
+  return aHasVertex;
+}
index a436f7b0bf372a79a904eabddfa839c11d8bc6cd..912db7307b5b9de3be76a4e3ca7b53b629193fb4 100644 (file)
@@ -151,6 +151,15 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theEdge - the edge
   /// \return result object with external edge if it is found
   static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, boost::shared_ptr<GeomAPI_Edge> theEdge);
+
+  /// Returns whether the selected presentation has a shape with the vertex type
+  /// \param thePrs a selected presentation
+  /// \param theSketch the sketch feature
+  /// \param theView a 3D view
+  /// \param theX the output horizontal coordinate of the point
+  /// \param theY the output vertical coordinate of the point
+  static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
+                             Handle_V3d_View theView, double& theX, double& theY);
 };
 
 #endif