]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Select external objects for sketcher
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 29 Oct 2014 13:48:32 +0000 (16:48 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 29 Oct 2014 13:48:32 +0000 (16:48 +0300)
src/PartSet/PartSet_OperationFeatureBase.h
src/PartSet/PartSet_OperationFeatureCreate.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h

index cde5fb6756674e736437cfc49e2bb817d5ccc6db..bb74a4431642c6c76b314c2a0e6103840d7bd7bf 100644 (file)
@@ -46,14 +46,6 @@ Q_OBJECT
                              ModuleBase_ISelection* theSelection);
 
 
- protected:
-  /// Set value to the active widget
-  /// \param theFeature the feature
-  /// \param theX the horizontal coordinate
-  /// \param theY the vertical coordinate
-  /// \return true if the point is set
-  //bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
-
  protected:
   CompositeFeaturePtr mySketch;  ///< the sketch of the feature
 };
index c2780006535a3cc6645a7c75db092c66c516f3a2..49c8b24901b0e158c54736471d5ccfcb4bf1e294 100644 (file)
@@ -36,6 +36,7 @@
 #include <TopoDS_Vertex.hxx>
 #include <TopoDS.hxx>
 #include <BRep_Tool.hxx>
+#include <TopoDS.hxx>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -130,7 +131,14 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Module
           isClosedContour = true;
         }
       } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
-        PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
+        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 dc4feb845df6099a441ecbec50a169b55709155c..14971c0975386fea22d68686f79d34cc538c1b56 100644 (file)
 #include <SketchPlugin_ConstraintRadius.h>
 #include <SketchPlugin_ConstraintRigid.h>
 #include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Line.h>
 
 #include <ModuleBase_ViewerPrs.h>
 
 #include <V3d_View.hxx>
 #include <gp_Pln.hxx>
+#include <gp_Circ.hxx>
 #include <ProjLib.hxx>
 #include <ElSLib.hxx>
 #include <Geom_Line.hxx>
 #include <GeomAPI_ProjectPointOnCurve.hxx>
+#include <BRep_Tool.hxx>
+#include <TopoDS.hxx>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -178,8 +184,8 @@ void PartSet_Tools::setFeaturePoint(FeaturePtr theFeature, double theX, double t
   if (!theFeature)
     return;
   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-      aData->attribute(theAttribute));
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
   if (aPoint)
     aPoint->setValue(theX, theY);
 }
@@ -341,3 +347,66 @@ bool PartSet_Tools::isConstraintFeature(const std::string& theKind)
       || theKind == SketchPlugin_ConstraintRadius::ID()
       || theKind == SketchPlugin_ConstraintRigid::ID();
 }
+
+ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch)
+{
+  TopoDS_Shape aShape = thePrs.shape();
+  if (aShape.ShapeType() != TopAbs_EDGE)
+    return ResultPtr();
+
+  Standard_Real aStart, aEnd;
+  Handle(V3d_View) aNullView;
+  FeaturePtr myFeature;
+
+  Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aStart, aEnd);
+  GeomAdaptor_Curve aAdaptor(aCurve);
+  if (aAdaptor.GetType() == GeomAbs_Line) {
+    // Create line
+    myFeature = theSketch->addFeature(SketchPlugin_Line::ID());
+
+    //DataPtr aData = myFeature->data();
+    //boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = 
+    //  boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
+
+    //double aX, aY;
+    //gp_Pnt Pnt1 = aAdaptor.Value(aStart);
+    //convertTo2D(Pnt1, theSketch, aNullView, aX, aY);
+    //setFeaturePoint(myFeature, aX, aY, SketchPlugin_Line::START_ID());
+
+    //gp_Pnt Pnt2 = aAdaptor.Value(aEnd);
+    //convertTo2D(Pnt2, theSketch, aNullView, aX, aY);
+    //setFeaturePoint(myFeature, aX, aY, SketchPlugin_Line::END_ID());
+  } else if (aAdaptor.GetType() == GeomAbs_Circle) {
+    if (aAdaptor.IsClosed()) {
+      // Create circle
+      myFeature = theSketch->addFeature(SketchPlugin_Circle::ID());
+      //gp_Circ aCirc = aAdaptor.Circle();
+      //gp_Pnt aCenter = aCirc.Location();
+
+      //double aX, aY;
+      //convertTo2D(aCenter, theSketch, aNullView, aX, aY);
+      //setFeaturePoint(myFeature, aX, aY, SketchPlugin_Circle::CENTER_ID());
+      //setFeatureValue(myFeature, aCirc.Radius(), SketchPlugin_Circle::RADIUS_ID());
+    } else {
+      // Create arc
+      myFeature = theSketch->addFeature(SketchPlugin_Arc::ID());
+    }
+  }
+  if (myFeature) {
+    DataPtr aData = myFeature->data();
+    AttributeSelectionPtr anAttr = 
+      boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+      (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+
+    ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(thePrs.object());
+    if (anAttr && aRes) {
+      boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
+      anEdge->setImpl(new TopoDS_Shape(aShape));
+
+      anAttr->setValue(aRes, anEdge);
+      myFeature->execute();
+      return myFeature->firstResult();
+    }
+  }
+  return ResultPtr();
+}
\ No newline at end of file
index 872102d8b6d9022e9beea3a9cada4c2105cf5de3..16c79788d5f43310a07b06ae87ec567717b96972 100644 (file)
@@ -7,12 +7,14 @@
 
 #include "PartSet.h"
 
+#include <ModuleBase_ViewerPrs.h>
 #include <gp_Pnt.hxx>
 
 #include <QPoint>
 #include <QList>
 
 #include <ModelAPI_CompositeFeature.h>
+#include <TopoDS_Edge.hxx>
 
 #include <boost/shared_ptr.hpp>
 
@@ -125,6 +127,12 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theKind a feature kind
   /// \return the boolean value
   static bool isConstraintFeature(const std::string& theKind);
+
+  /// Creates a line (arc or circle) by given edge
+  /// Created line will have fixed constraint
+  /// \param theEdge - an edge
+  /// \return - result of created feature
+  static ResultPtr createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch);
 };
 
 #endif