]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #399: Create a rigid vertex on selection of external one
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 9 Feb 2015 13:29:33 +0000 (16:29 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 9 Feb 2015 13:29:33 +0000 (16:29 +0300)
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/SketchPlugin/SketchPlugin_Feature.h

index 0b07da7e75db47c670207a7138059a3b9048c0fe..4bab36441129bfa093884895d0e14bb5f772ce49 100644 (file)
@@ -433,7 +433,7 @@ bool PartSet_Tools::isConstraintFeature(const std::string& theKind)
       || theKind == SketchPlugin_ConstraintRigid::ID();
 }
 
-ResultPtr PartSet_Tools::createFixedObjectByEdge(const TopoDS_Shape& theShape, 
+ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, 
                                                  const ObjectPtr& theObject, 
                                                  CompositeFeaturePtr theSketch)
 {
index 31508cb9a32ca2e58a95f48b851481f81830133d..4ff7da471a6d7a3fe7965a737dd6267f060d8236 100644 (file)
@@ -155,9 +155,9 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theObject a selected result object
   /// \param theSketch a sketch feature
   /// \return result of created feature
-  static ResultPtr createFixedObjectByEdge(const TopoDS_Shape& theShape, 
-                                           const ObjectPtr& theObject, 
-                                           CompositeFeaturePtr theSketch);
+  static ResultPtr createFixedObjectByExternal(const TopoDS_Shape& theShape, 
+                                               const ObjectPtr& theObject, 
+                                               CompositeFeaturePtr theSketch);
 
   /// Checks whether the list of selected presentations contains the given one
   /// \param theSelected a list of presentations
index e8796669b9cc529bd2b625a8dc9de2e5d61aeca1..d61d8d7481c00d80c4fe25e001b140520b01debd 100644 (file)
@@ -30,6 +30,8 @@
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAPI_Pnt2d.h>
 
+#include <SketchPlugin_Feature.h>
+
 #include <QGroupBox>
 #include <QGridLayout>
 #include <QLabel>
@@ -234,45 +236,56 @@ bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView,
 void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
   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.
-  //NCollection_List<TopoDS_Shape> aShapes;
-  //std::list<ObjectPtr> aObjects;
-  //aSelection->selectedShapes(aShapes, aObjects);
-  //if (aShapes.Extent() > 0) {
-  //  TopoDS_Shape aShape = aShapes.First();
-  //  double aX, aY;
-  //  if (getPoint2d(theWnd->v3dView(), aShape, aX, aY)) {
-  //    setPoint(aX, aY);
-
-  //    PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
-  //    emit vertexSelected(aObjects.front(), aShape);
-  //    emit focusOutWidget(this);
-  //    return;
-  //  }
-  //}
+  NCollection_List<TopoDS_Shape> aShapes;
+  std::list<ObjectPtr> aObjects;
+  aSelection->selectedShapes(aShapes, aObjects);
+  // if we have selection
+  if (aShapes.Extent() > 0) {
+    TopoDS_Shape aShape = aShapes.First();
+    ObjectPtr aObject = aObjects.front();
+    FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject);
+    if (aSelectedFeature.get() != NULL) {
+      std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+              std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
+      if ((!aSPFeature) && (!aShape.IsNull()))
+        PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+    }
+    double aX, aY;
+    if (getPoint2d(aView, aShape, aX, aY)) {
+      setPoint(aX, aY);
+
+      PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
+      emit vertexSelected();
+      emit focusOutWidget(this);
+      return;
+    }
+  }
   // End of Bug dependent fragment
 
   // A case when point is taken from mouse event
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
   double aX, anY;
-  Handle(V3d_View) aView = theWnd->v3dView();
   PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
   if (!setPoint(aX, anY))
     return;
 
-  std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
-      GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
-  QList<FeaturePtr> aIgnore;
-  aIgnore.append(feature());
-
-  double aTolerance = aView->Convert(7);
-  std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt = 
-    PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
-  if (aAttrPnt.get() != NULL) {
-    aFeaturePoint->setValue(aAttrPnt->pnt());
-    PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
-    emit vertexSelected();
-  }
+  /// Start alternative code
+  //std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
+  //    GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
+  //QList<FeaturePtr> aIgnore;
+  //aIgnore.append(feature());
+
+  //double aTolerance = aView->Convert(7);
+  //std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt = 
+  //  PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
+  //if (aAttrPnt.get() != NULL) {
+  //  aFeaturePoint->setValue(aAttrPnt->pnt());
+  //  PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
+  //  emit vertexSelected();
+  //}
+  /// End alternative code
   emit focusOutWidget(this);
 }
 
index cd69a1998d2e0620624667848994846ae8003549..2f9bb3e95ee310ef5b436e456599d03fabc224e7 100644 (file)
@@ -28,8 +28,8 @@ bool PartSet_WidgetShapeSelector::storeValue() const
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
   if ((!aSPFeature) && (!myShape->isNull())) {
     // Processing of external (non-sketch) object
-    ObjectPtr aObj = PartSet_Tools::createFixedObjectByEdge(myShape->impl<TopoDS_Shape>(),
-                                                            mySelectedObject, mySketch);
+    ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl<TopoDS_Shape>(),
+                                                                mySelectedObject, mySketch);
     if (aObj) {
       PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this;
       that->mySelectedObject = aObj;
@@ -133,8 +133,8 @@ bool PartSet_WidgetConstraintShapeSelector::storeValue() const
     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
     if ((!aSPFeature) && (!myShape->isNull())) {
-      ObjectPtr aObj = PartSet_Tools::createFixedObjectByEdge(myShape->impl<TopoDS_Shape>(),
-                                                              mySelectedObject, mySketch);
+      ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl<TopoDS_Shape>(),
+                                                                  mySelectedObject, mySketch);
       if (aObj) {
         PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this;
         that->mySelectedObject = aObj;
index 66d59467b5682dfb6fc6ebcf95a0aeb1083edb73..5174eff40940cd9ccf9f7d9c1decc9e4a2333efa 100644 (file)
@@ -67,8 +67,8 @@ class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
   /// Customize presentation of the feature
   virtual void customisePresentation(AISObjectPtr thePrs)
   {
-    // if this is an edge
-    if (thePrs->getShapeType() == 6) {
+    // if this is an edge or vertex
+    if ((thePrs->getShapeType() == 6) || (thePrs->getShapeType() == 7)) {
       thePrs->setWidth(3);
       if (isExternal())
         thePrs->setColor(0,255,0);