Salome HOME
Fix for registering of parameters in command line.
[modules/shaper.git] / src / PartSet / PartSet_Tools.cpp
index 53c1dc13fb77177cb87957788ac0ccc43d9e9bf1..e7e2458f560fe68c7a118d50c7ec2e6990d1c3b1 100755 (executable)
@@ -353,30 +353,11 @@ std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findFirstEqualPoint(
   return aFPoint;
 }
 
-void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
-                                   const std::string& theAttribute, double theClickedX,
-                                   double theClickedY)
+std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findFirstEqualPointInSketch(
+                                    const CompositeFeaturePtr& theSketch,
+                                    const std::shared_ptr<GeomDataAPI_Point2D>& theFeaturePoint,
+                                    const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
 {
-  if (!theFeature.get())
-    return;
-
-  std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
-      new GeomAPI_Pnt2d(theClickedX, theClickedY));
-
-  // find a feature point by the selection mode
-  std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint;
-  if (theFeature->isMacro()) {
-    // the macro feature will be removed after the operation is stopped, so we need to build
-    // coicidence to possible sub-features
-    aFeaturePoint = PartSet_Tools::findFirstEqualPointInArgumentFeatures(theFeature, aClickedPoint);
-  }
-  else {
-    aFeaturePoint = std::dynamic_pointer_cast<
-        GeomDataAPI_Point2D>(theFeature->data()->attribute(theAttribute));
-  }
-  if (!aFeaturePoint)
-    return;
-
   // get all sketch features. If the point with the given coordinates belong to any sketch feature,
   // the constraint is created between the feature point and the found sketch point
   std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
@@ -386,15 +367,18 @@ void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr the
   std::list<ObjectPtr> aFeatures = aRefList->list();
   std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
   std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
+
+  FeaturePtr aFeatureOfPoint = ModelAPI_Feature::feature(theFeaturePoint->owner());
+  std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
   for (; anIt != aLast; anIt++) {
     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
-    if (!aFeature.get() || (theFeature == aFeature) || (aFeaturePoint->owner() == aFeature))
+    if (!aFeature.get() || aFeatureOfPoint == aFeature)
       continue;
-    std::shared_ptr<GeomDataAPI_Point2D> aFPoint = PartSet_Tools::findFirstEqualPoint(aFeature,
-                                                                                aClickedPoint);
-    if (aFPoint)
-      PartSet_Tools::createConstraint(theSketch, aFPoint, aFeaturePoint);
+    aFPoint = PartSet_Tools::findFirstEqualPoint(aFeature, thePoint);
+    if (aFPoint.get())
+      break;
   }
+  return aFPoint;
 }
 
 std::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
@@ -542,12 +526,12 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap
         //if (!theTemporary) {
           aMyFeature->execute();
 
-          // fix this edge
-          FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
-          aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
-            setObject(aMyFeature->lastResult());
-          // we need to flush created signal in order to fixed constraint is processed by solver
-          Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+        //  // fix this edge
+        //  FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
+        //  aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
+        //    setObject(aMyFeature->lastResult());
+        //  // we need to flush created signal in order to fixed constraint is processed by solver
+        //  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
         //}
         return aMyFeature->lastResult();
       }
@@ -563,16 +547,6 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap
         (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
 
       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-      /// check external line created on Trihedron Axis
-      /// selection of a point on external edge referenced to AIS_Trihedron axis
-      /// should be prohibited or point should be replaced to "Origin". The second
-      /// case is implemented because of not correct AIS_Trihedron origin point highlight
-      /// When AIS is corrected(exactly priority of origin and stayed vertex by highlight)
-      /// the next check should be moved to Partset 2d point widget in isValidSelectionCustom
-      bool isAxis = isAxisSelected(theObject);
-      if (isAxis)
-        aRes = ResultPtr(); // to rely on code below that found the Origin result
-
       // if there is no object,
       // it means that this is the origin point: search it in the module document
       if (!aRes.get()) {
@@ -614,12 +588,12 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap
         //if (theTemporary) {
           aMyFeature->execute();
 
-          // fix this edge
-          FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
-          aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
-            setObject(aMyFeature->lastResult());
-          // we need to flush created signal in order to fixed constraint is processed by solver
-          Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+        //  // fix this edge
+        //  FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
+        //  aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
+        //    setObject(aMyFeature->lastResult());
+        //  // we need to flush created signal in order to fixed constraint is processed by solver
+        //  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
         //}
         return aMyFeature->lastResult();
       }
@@ -628,29 +602,6 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap
   return ResultPtr();
 }
 
-bool PartSet_Tools::isAxisSelected(const ObjectPtr& theObject)
-{
-  bool isAxis = false;
-  ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-  if (aRes.get()) {
-    // check if result belongs to external feature
-    // in this case we should use as a result reference of external feature
-    FeaturePtr aResFeature = ModelAPI_Feature::feature(aRes);
-    std::shared_ptr<SketchPlugin_Feature> aSPFeature =
-                  std::dynamic_pointer_cast<SketchPlugin_Feature>(aResFeature);
-    if (aSPFeature.get() && aSPFeature->isExternal()) {
-      AttributeSelectionPtr aAttr = aResFeature->selection(
-                                    SketchPlugin_SketchEntity::EXTERNAL_ID());
-      if (aAttr) { /// check if the result is Axis
-        ResultPtr anExternalRes = std::dynamic_pointer_cast<ModelAPI_Result>(aAttr->context());
-        FeaturePtr aResFeature = ModelAPI_Feature::feature(anExternalRes);
-        isAxis = aResFeature->getKind() == "Axis"; //ConstructionPlugin_Axis::ID()
-      }
-    }
-  }
-  return isAxis;
-}
-
 bool PartSet_Tools::isContainPresentation(const QList<ModuleBase_ViewerPrsPtr>& theSelected,
                                           const ModuleBase_ViewerPrsPtr& thePrs)
 {
@@ -721,7 +672,7 @@ ResultPtr PartSet_Tools::findExternalVertex(CompositeFeaturePtr theSketch,
 
 
 bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrsPtr& thePrs, FeaturePtr theSketch,
-                                   Handle_V3d_View theView, double& theX, double& theY)
+                                   Handle(V3d_View) theView, double& theX, double& theY)
 {
   bool aHasVertex = false;