]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Provide sub-shapes selection in sketcher
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 27 Nov 2014 15:45:28 +0000 (18:45 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 27 Nov 2014 15:45:28 +0000 (18:45 +0300)
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetShapeSelector.cpp [new file with mode: 0644]
src/PartSet/PartSet_WidgetShapeSelector.h [new file with mode: 0644]
src/SketchPlugin/plugin-Sketch.xml

index e7899b5d27e93ccccf75a9ebbf688ac750a1f908..211363d1661920c52520516f3498ec36407b4075 100644 (file)
@@ -133,9 +133,9 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const
     ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(mySelectedObject);
     if (aBody) {
       AttributePtr aAttr = aData->attribute(attributeID());
-      std::shared_ptr<ModelAPI_AttributeSelection> aSelectAttr = 
-        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aAttr);
 
+      AttributeSelectionPtr aSelectAttr = 
+        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aAttr);
       if (aSelectAttr)
         aSelectAttr->setValue(aBody, myShape);
       updateObject(myFeature);
@@ -171,7 +171,7 @@ bool ModuleBase_WidgetShapeSelector::restoreValue()
   DataPtr aData = myFeature->data();
   bool isBlocked = this->blockSignals(true);
   if (myUseSubShapes) {
-    std::shared_ptr<ModelAPI_AttributeSelection> aSelect = aData->selection(attributeID());
+    AttributeSelectionPtr aSelect = aData->selection(attributeID());
     if (aSelect) {
       mySelectedObject = aSelect->context();
       myShape = aSelect->value();
index d0b04a6c63def6480f810b8aa412860eddc6d109..4cf0a4d2ed6ea6c70fe65c49a879befdf77e78cf 100644 (file)
@@ -35,7 +35,6 @@ Q_OBJECT
   virtual ~ModuleBase_WidgetShapeSelector();
 
   /// Saves the internal parameters to the given feature
-  /// \param theObject a model feature to be changed
   virtual bool storeValue() const;
 
   virtual bool restoreValue();
@@ -98,7 +97,7 @@ Q_OBJECT
   void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
 
   //----------- Class members -------------
- private:
+ protected:
   QWidget* myContainer;
   QLabel* myLabel;
   QLineEdit* myTextLine;
index bdfcb5360a22edb668cc15777328d77659ec8ad7..a6c9c34e800b17fd35ffab39650ed045e2e8dfc2 100644 (file)
@@ -6,36 +6,24 @@ SET(PROJECT_HEADERS
        PartSet.h
        PartSet_Constants.h
        PartSet_EditLine.h
-#      PartSet_Listener.h
        PartSet_Module.h
-#      PartSet_OperationFeatureCreate.h
-#      PartSet_OperationFeatureEdit.h
-#      PartSet_OperationSketchBase.h
-#      PartSet_OperationSketch.h
-#      PartSet_OperationFeatureBase.h
        PartSet_Tools.h
        PartSet_WidgetSketchLabel.h
        PartSet_Validators.h
        PartSet_WidgetPoint2d.h
        PartSet_WidgetPoint2dDistance.h
-#      PartSet_Operation.h
+       PartSet_WidgetShapeSelector.h
 )
 
 SET(PROJECT_SOURCES
        PartSet_EditLine.cpp
-#      PartSet_Listener.cpp
        PartSet_Module.cpp
-#      PartSet_OperationFeatureCreate.cpp
-#      PartSet_OperationFeatureEdit.cpp
-#      PartSet_OperationSketchBase.cpp
-#      PartSet_OperationSketch.cpp
-#      PartSet_OperationFeatureBase.cpp
        PartSet_Tools.cpp
        PartSet_WidgetSketchLabel.cpp
        PartSet_Validators.cpp
        PartSet_WidgetPoint2d.cpp
        PartSet_WidgetPoint2dDistance.cpp
-#      PartSet_Operation.cpp
+       PartSet_WidgetShapeSelector.cpp
 )
 
 SET(PROJECT_RESOURCES 
index 7204c0e12b084f9d82b6f6b804bebe99a4c0b861..e115736c35b88993ef33b63eb81f03514f86b102 100644 (file)
@@ -9,7 +9,7 @@
 #include "PartSet_Tools.h"
 #include "PartSet_WidgetPoint2D.h"
 #include "PartSet_WidgetPoint2dDistance.h"
-//#include "PartSet_Operation.h"
+#include "PartSet_WidgetShapeSelector.h"
 
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_IViewer.h>
 #include <SketchPlugin_Point.h>
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Circle.h>
+#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintParallel.h>
+#include <SketchPlugin_ConstraintPerpendicular.h>
+#include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_ConstraintRigid.h>
 
 //#include <Config_PointerMessage.h>
 //#include <Config_ModuleReader.h>
@@ -399,11 +405,16 @@ void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* t
 QStringList PartSet_Module::sketchOperationIdList() const
 {
   QStringList aIds;
-  aIds << SketchPlugin_Sketch::ID().c_str();
   aIds << SketchPlugin_Line::ID().c_str();
   aIds << SketchPlugin_Point::ID().c_str();
   aIds << SketchPlugin_Arc::ID().c_str();
   aIds << SketchPlugin_Circle::ID().c_str();
+  aIds << SketchPlugin_ConstraintLength::ID().c_str();
+  aIds << SketchPlugin_ConstraintDistance::ID().c_str();
+  aIds << SketchPlugin_ConstraintRigid::ID().c_str();
+  aIds << SketchPlugin_ConstraintRadius::ID().c_str();
+  aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
+  aIds << SketchPlugin_ConstraintParallel::ID().c_str();
   return aIds;
 }
 
@@ -858,6 +869,7 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
     aWgt->setWorkshop(aWorkshop);
     theModelWidgets.append(aWgt);
     return aWgt->getControl();
+
   } else if (theType == "sketch-2dpoint_selector") {
     PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
     aWgt->setWorkshop(aWorkshop);
@@ -868,6 +880,7 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
 
     theModelWidgets.append(aWgt);
     return aWgt->getControl();
+
   } if (theType == "point2ddistance") {
     PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
     aWgt->setWorkshop(aWorkshop);
@@ -875,6 +888,15 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
 
     theModelWidgets.append(aWgt);
     return aWgt->getControl();
+
+  } if (theType == "sketch_shape_selector") {
+    PartSet_WidgetShapeSelector* aWgt = 
+      new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
+    aWgt->setSketcher(myCurrentSketch);
+
+    theModelWidgets.append(aWgt);
+    return aWgt->getControl();
+
   }else
     return 0;
 }
index dbb12d393902a87b589d170ecafbc5554a86ccf3..fdc4e25c8ffe186fec15a8e89b8f67eab9f1df53 100644 (file)
@@ -126,12 +126,8 @@ Handle(V3d_View) theView,
   theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
 }
 
-void PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
-                                gp_Pnt& thePoint)
+std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr theSketch)
 {
-  if (!theSketch)
-    return;
-
   std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
 
   std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
@@ -141,11 +137,10 @@ void PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr
   std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
 
-  std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
-      ->added(aY->dir()->xyz()->multiplied(theY));
+  std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = 
+    std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
 
-  std::shared_ptr<GeomAPI_Pnt> aPoint = std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
-  thePoint = gp_Pnt(aPoint->x(), aPoint->y(), aPoint->z());
+  return aPnt2d->to3D(aC->pnt(), aX->dir(), aY->dir());
 }
 
 ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
@@ -535,3 +530,39 @@ bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePt
 
   return aHasVertex;
 }
+
+AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj, 
+                                                   const TopoDS_Shape theShape, 
+                                                   FeaturePtr theSketch)
+{
+
+  AttributePtr anAttribute;
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theObj);
+  if (aFeature) {
+    if (theShape.ShapeType() == TopAbs_VERTEX) {
+      const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape);
+      if (!aVertex.IsNull())  {
+        gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+        std::shared_ptr<GeomAPI_Pnt> aValue = std::shared_ptr<GeomAPI_Pnt>(
+            new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
+
+        // find the given point in the feature attributes
+        std::list<AttributePtr> anAttiributes = 
+          aFeature->data()->attributes(GeomDataAPI_Point2D::type());
+        std::list<AttributePtr>::const_iterator anIt = anAttiributes.begin(), 
+                                                aLast = anAttiributes.end();
+        for (; anIt != aLast && !anAttribute; anIt++) {
+          std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+
+          std::shared_ptr<GeomAPI_Pnt> aPnt = convertTo3D(aCurPoint->x(), aCurPoint->y(), theSketch);
+          if (aPnt && (aPnt->distance(aValue) < Precision::Confusion())) {
+            anAttribute = aCurPoint;
+            break;
+          }
+        }
+      }
+    }
+  }
+  return anAttribute;
+}
index 53c98a47b33b5b0d9d7dedf2f6b4affa7e7355c1..522f0363d1a1a268522bf07aa1794f67c0adefa3 100644 (file)
 #include <QList>
 
 #include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_Attribute.h>
+
+#include <TopoDS_Shape.hxx>
 
 #include <memory>
 
@@ -52,8 +56,7 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theY the Y coordinate
   /// \param theSketch the sketch feature
   /// \param thePoint the 3D point in the viewer
-  static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
-                          gp_Pnt& thePoint);
+  static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
 
   /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
   /// if it exists, the first object is returned. Secondly, there is an iteration on
@@ -161,6 +164,16 @@ class PARTSET_EXPORT PartSet_Tools
   /// \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);
+
+
+  /**
+  * Find attribute of object which corresponds to the given shape
+  * \param theObj - an object
+  * \param theShape - a Shape
+  * \param theSketch - a Sketch to get a plane of converting to 2d
+  */
+  static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch);
+
 protected:
   /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
   /// if it exists, the first object is returned. Secondly, there is an iteration on
diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp
new file mode 100644 (file)
index 0000000..6036af1
--- /dev/null
@@ -0,0 +1,38 @@
+// File:        PartSet_WidgetShapeSelector.cpp
+// Created:     27 Nov 2014
+// Author:      Vitaly Smetannikov
+
+#include "PartSet_WidgetShapeSelector.h"
+
+#include <ModelAPI_AttributeRefAttr.h>
+#include <PartSet_Tools.h>
+
+
+bool PartSet_WidgetShapeSelector::storeValue() const
+{
+  if (!mySelectedObject)
+    return false;
+
+  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
+  if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
+    return false;
+
+  DataPtr aData = myFeature->data();
+  if (myUseSubShapes && myShape) {
+    AttributePtr aAttr = aData->attribute(attributeID());
+    AttributeRefAttrPtr aRefAttr = 
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
+    if (aRefAttr) {
+      TopoDS_Shape aShape = myShape->impl<TopoDS_Shape>();
+      AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch);
+      if (mySelectedObject)
+        aRefAttr->setObject(mySelectedObject);
+      if (aPntAttr)
+        aRefAttr->setAttr(aPntAttr);
+
+      updateObject(myFeature);
+      return true;
+    }
+  }
+  return ModuleBase_WidgetShapeSelector::storeValue();
+}
diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h
new file mode 100644 (file)
index 0000000..a216830
--- /dev/null
@@ -0,0 +1,35 @@
+// File:        PartSet_WidgetShapeSelector.h
+// Created:     27 Nov 2014
+// Author:      Vitaly Smetannikov
+
+
+#ifndef PartSet_WidgetShapeSelector_H
+#define PartSet_WidgetShapeSelector_H
+
+#include "PartSet.h"
+
+#include <ModuleBase_WidgetShapeSelector.h>
+
+#include <ModelAPI_CompositeFeature.h>
+
+class PARTSET_EXPORT PartSet_WidgetShapeSelector: public ModuleBase_WidgetShapeSelector
+{
+Q_OBJECT
+ public:
+  PartSet_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+    const Config_WidgetAPI* theData, const std::string& theParentId)
+    : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {}
+
+  virtual ~PartSet_WidgetShapeSelector() {}
+
+  /// Saves the internal parameters to the given feature
+  virtual bool storeValue() const;
+
+  void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
+  CompositeFeaturePtr sketch() const { return mySketch; }
+
+private:
+  CompositeFeaturePtr mySketch;
+};
+
+#endif
\ No newline at end of file
index d0881383bd2f24eb336e4d83936fc12b9e60821a..4395e92fcba66b05d159391b902c6dd1cfecd954 100644 (file)
 
       <feature id="SketchConstraintDistance" title="Distance" tooltip="Create constraint for the distance from a point to an object" icon=":icons/distance.png">
         <label title="Select objects for distance definition. Following objects can be accepted: point, line or arc end point, center of circle or arc."/>
-               <shape_selector id="ConstraintEntityA" label="First object" tooltip="Select point, line end point, line, center of circle or arc." 
-                       shape_types="edge vertex"/>
-               <shape_selector id="ConstraintEntityB" label="Last object" tooltip="Select point, line end point, line, center of circle or arc." 
-                       shape_types="edge vertex"/>
+               <sketch_shape_selector id="ConstraintEntityA" label="First object" tooltip="Select point, line end point, line, center of circle or arc." 
+                       shape_types="edge vertex"  use_subshapes="true"/>
+               <sketch_shape_selector id="ConstraintEntityB" label="Last object" tooltip="Select point, line end point, line, center of circle or arc." 
+                       shape_types="edge vertex"  use_subshapes="true"/>
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
         <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed" min="0">
           <validator id="GeomValidators_Positive"/>