]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Fri, 6 Jun 2014 12:13:41 +0000 (16:13 +0400)
committernds <natalia.donis@opencascade.com>
Fri, 6 Jun 2014 12:13:41 +0000 (16:13 +0400)
Circle final creation.

src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h
src/PartSet/PartSet_FeatureCirclePrs.cpp
src/PartSet/PartSet_FeatureCirclePrs.h
src/PartSet/PartSet_FeaturePointPrs.cpp
src/PartSet/PartSet_FeaturePointPrs.h
src/PartSet/PartSet_FeaturePrs.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Point.cpp

index 2cc821e39fc26a8d52a3103a0fa3adf923b379ed..57afd7a6956fb9ae7c033c9997e72a4441a67529 100644 (file)
@@ -10,6 +10,9 @@
 #include <BRep_Tool.hxx>
 #include <Geom_Plane.hxx>
 
+#include <gp_Ax2.hxx>
+#include <gp_Circ.hxx>
+
 boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::line(
   boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd)
 {
@@ -26,3 +29,19 @@ boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::line(
   aRes->setImpl(new TopoDS_Shape(anEdge));
   return aRes;
 }
+
+boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::lineCircle(
+    boost::shared_ptr<GeomAPI_Pnt> theCenter,
+    boost::shared_ptr<GeomAPI_Dir> theNormal, double theRadius)
+{
+  const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
+  const gp_Dir& aDir = theNormal->impl<gp_Dir>();
+
+  gp_Circ aCircle(gp_Ax2(aCenter, aDir), theRadius);
+
+  BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle);
+  boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+  TopoDS_Edge anEdge = anEdgeBuilder.Edge();
+  aRes->setImpl(new TopoDS_Shape(anEdge));
+  return aRes;
+}
index cd505a8614d57f110f42a634098663eac38e577c..b7f527230c9cd6e5458e74c4889a054d8674b117 100644 (file)
@@ -8,6 +8,7 @@
 #include <GeomAlgoAPI.h>
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_Dir.h>
 #include <boost/shared_ptr.hpp>
 
 /**\class GeomAlgoAPI_EdgeBuilder
@@ -21,6 +22,11 @@ public:
   /// Creates linear edge by two points
   static boost::shared_ptr<GeomAPI_Shape> line(
     boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd);
+
+  /// Creates linear edge in a form of a circle by a point and a circle radius
+  static boost::shared_ptr<GeomAPI_Shape> lineCircle(
+    boost::shared_ptr<GeomAPI_Pnt> theCenter,
+    boost::shared_ptr<GeomAPI_Dir> theNormal, double theRadius);
 };
 
 #endif
index 48342d9a60821e8183802c25d97d868ef6450d1f..d825fdd583a5d4d5baf6e07ff9ab5fda031f1fe9 100644 (file)
@@ -7,11 +7,10 @@
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_Line.h>
-#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_Circle.h>
 
 #include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pnt2d.h>
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
@@ -27,38 +26,25 @@ PartSet_FeatureCirclePrs::PartSet_FeatureCirclePrs(FeaturePtr theSketch)
 {
 }
 
-void PartSet_FeatureCirclePrs::initFeature(FeaturePtr theFeature)
-{
-  if (feature() && theFeature)
-  {
-    // use the last point of the previous feature as the first of the new one
-    boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-    boost::shared_ptr<GeomDataAPI_Point2D> anInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
-                                                                  (aData->attribute(LINE_ATTR_END));
-    PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_START);
-    PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_END);
-
-    aData = feature()->data();
-    boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
-                                                                 (aData->attribute(LINE_ATTR_START));
-    PartSet_Tools::createConstraint(sketch(), anInitPoint, aPoint);
-  }
-}
-
 PartSet_SelectionMode PartSet_FeatureCirclePrs::setPoint(double theX, double theY,
-                                                       const PartSet_SelectionMode& theMode)
+                                                         const PartSet_SelectionMode& theMode)
 {
   PartSet_SelectionMode aMode = theMode;
   switch (theMode)
   {
     case SM_FirstPoint: {
-      PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_START);
-      PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END);
+      PartSet_Tools::setFeaturePoint(feature(), theX, theY, CIRCLE_ATTR_CENTER);
       aMode = SM_SecondPoint;
     }
     break;
     case SM_SecondPoint: {
-      PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END);
+      boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+      boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                                  (aData->attribute(CIRCLE_ATTR_CENTER));
+      boost::shared_ptr<GeomAPI_Pnt2d> aCoordPoint(new GeomAPI_Pnt2d(theX, theY));
+      double aRadius = aCoordPoint->distance(aPoint->pnt());
+      PartSet_Tools::setFeatureValue(feature(), aRadius, CIRCLE_ATTR_RADIUS);
+
       aMode = SM_DonePoint;
    }
     break;
@@ -74,10 +60,10 @@ std::string PartSet_FeatureCirclePrs::getAttribute(const PartSet_SelectionMode&
   switch (theMode)
   {
     case SM_FirstPoint:
-      aAttribute = LINE_ATTR_START;
+      aAttribute = CIRCLE_ATTR_CENTER;
     break;
     case SM_SecondPoint:
-      aAttribute = LINE_ATTR_END;
+      aAttribute = CIRCLE_ATTR_RADIUS;
     break;
     default:
     break;
@@ -89,9 +75,9 @@ PartSet_SelectionMode PartSet_FeatureCirclePrs::getNextMode(const std::string& t
 {
   PartSet_SelectionMode aMode;
 
-  if (theAttribute == LINE_ATTR_START)
+  if (theAttribute == CIRCLE_ATTR_CENTER)
     aMode = SM_SecondPoint;
-  else if (theAttribute == LINE_ATTR_END)
+  else if (theAttribute == CIRCLE_ATTR_RADIUS)
     aMode = SM_DonePoint;
   return aMode;
 }
@@ -103,10 +89,7 @@ boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::featurePoint
   switch (theMode)
   {
     case SM_FirstPoint:
-      aPointArg = LINE_ATTR_START;
-      break;
-    case SM_SecondPoint:
-      aPointArg = LINE_ATTR_END;
+      aPointArg = CIRCLE_ATTR_CENTER;
       break;
     default:
       break;
index 1e4e680001c8220059b79ff699b6e77d40c38964..ef4b8497dc2012b5edb514bc372b9761506c503b 100644 (file)
@@ -45,10 +45,6 @@ public:
   virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
 
 protected:
-  /// Initializes current feature by the given
-  /// \param theSourceFeature the feature, which attributes are used to initialize the current feature
-  virtual void initFeature(FeaturePtr theSourceFeature);
-
   /// Returns the feature point in the selection mode position.
   /// \param theMode the current operation selection mode. The feature attribute depends on the mode
   virtual boost::shared_ptr<GeomDataAPI_Point2D> featurePoint(const PartSet_SelectionMode& theMode);
index ac695dada8c7abc016474c7ffd50cc8376a1530d..ee6bc8140a9c072ffc62fae196636ca8c58ed5a5 100644 (file)
@@ -25,10 +25,6 @@ PartSet_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theSketch)
 {
 }
 
-void PartSet_FeaturePointPrs::initFeature(FeaturePtr theFeature)
-{
-}
-
 PartSet_SelectionMode PartSet_FeaturePointPrs::setPoint(double theX, double theY,
                                                        const PartSet_SelectionMode& theMode)
 {
index d06b3c7345a71dd8db687b7359ac2c5b4f927908..fa9f73debc765a8b11021f40a68836a914ba40ac 100644 (file)
@@ -45,10 +45,6 @@ public:
   virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
 
 protected:
-  /// Initializes current feature by the given
-  /// \param theSourceFeature the feature, which attributes are used to initialize the current feature
-  virtual void initFeature(FeaturePtr theSourceFeature);
-
   /// Returns the feature point in the selection mode position.
   /// \param theMode the current operation selection mode. The feature attribute depends on the mode
   virtual boost::shared_ptr<GeomDataAPI_Point2D> featurePoint(const PartSet_SelectionMode& theMode);
index 4a602d2248ed627919abb6c4efe300aed9362bbb..bf965ed8de53ba80e95366344c412808707ad884 100644 (file)
@@ -66,7 +66,7 @@ protected:
 
   /// Initializes current feature by the given
   /// \param theSourceFeature the feature, which attributes are used to initialize the current feature
-  virtual void initFeature(FeaturePtr theSourceFeature) = 0;
+  virtual void initFeature(FeaturePtr theSourceFeature) {};
 
   /// Returns the feature point in the selection mode position.
   /// \param theMode the current operation selection mode. The feature attribute depends on the mode
index 3e8c921b237c1a9724e86387e0b51b846a6495d2..36dd3fd0c3b009f43ccf80c2b9ed92a2d622aae1 100644 (file)
@@ -239,6 +239,18 @@ void PartSet_Tools::setFeaturePoint(FeaturePtr theFeature, double theX, double t
     aPoint->setValue(theX, theY);
 }
 
+void PartSet_Tools::setFeatureValue(FeaturePtr theFeature, double theValue,
+                                    const std::string& theAttribute)
+{
+  if (!theFeature)
+    return;
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeDouble> anAttribute =
+        boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(theAttribute));
+  if (anAttribute)
+    anAttribute->setValue(theValue);
+}
+
 void PartSet_Tools::createConstraint(FeaturePtr theSketch,
                                      boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
                                      boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
@@ -305,5 +317,6 @@ boost::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findPoint(FeaturePtr theFe
     if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
       aPoint2D = aPoint;
   }
+
   return aPoint2D;
 }
index ac55abbb26ed35b40af1ed95694ac2ba922f3fc8..5cb8e9c7fc01df7292867079e5773b176e7ce518 100644 (file)
@@ -91,9 +91,16 @@ public:
   /// \param theX the horizontal coordinate
   /// \param theY the vertical coordinate
   /// \param theAttribute the feature attribute
-  static void setFeaturePoint(FeaturePtr, double theX, double theY, const std::string& theAttribute);
+  static void setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
+                              const std::string& theAttribute);
 
-    /// Creates a constraint on two points
+  /// \brief Save the double to the feature. If the attribute is double, it is filled.
+  /// \param theFeature the feature
+  /// \param theValue the horizontal coordinate
+  /// \param theAttribute the feature attribute
+  static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
+
+  /// Creates a constraint on two points
   /// \param thePoint1 the first point
   /// \param thePoint1 the second point
   static void createConstraint(FeaturePtr theSketch,
index a083b1845aee55d10233a1b5b78c997b8d8d2749..af26e92308ee7b48c6a9aa077989ae37dbff1acd 100644 (file)
@@ -6,6 +6,11 @@
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
 #include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomDataAPI_Dir.h>
+
 #include <ModelAPI_AttributeDouble.h>
 
 SketchPlugin_Circle::SketchPlugin_Circle()
@@ -25,6 +30,38 @@ void SketchPlugin_Circle::execute()
 
 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Circle::preview()
 {
+  SketchPlugin_Sketch* aSketch = sketch();
+  if (aSketch) {
+    // compute a circle point in 3D view
+    boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = 
+      boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CIRCLE_ATTR_CENTER));
+    boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+
+    // compute the circle radius
+    boost::shared_ptr<ModelAPI_AttributeDouble> aRadiusAttr = 
+      boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CIRCLE_ATTR_RADIUS));
+    double aRadius = aRadiusAttr->value();
+
+    std::list<boost::shared_ptr<GeomAPI_Shape> > aShapes;
+    // make a visible point
+    boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+    aShapes.push_back(aCenterPointShape);
+
+    // make a visible circle
+    boost::shared_ptr<GeomDataAPI_Dir> aNDir = 
+      boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->data()->attribute(SKETCH_ATTR_NORM));
+    bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
+    if (aHasPlane) {
+      boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
+
+      boost::shared_ptr<GeomAPI_Shape> aCircleShape = 
+                              GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aRadius);
+      aShapes.push_back(aCircleShape);
+
+      boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+      setPreview(aCompound);
+    }
+  }
   /// \todo Implement preview for the circle
   return getPreview();
 }
index 63cf747a21c43b0a05195795a76a424e386396b6..6df2b536bad40f21b91a6bdf4fbfd97c9cb65b8a 100644 (file)
@@ -26,13 +26,14 @@ void SketchPlugin_Point::execute()
 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Point::preview()
 {
   SketchPlugin_Sketch* aSketch = sketch();
-  // compute a point in 3D view
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(POINT_ATTR_COORD));
-  boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
-  // make a visible point
-  boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
-  setPreview(aPointShape);
-
+  if (aSketch) {
+    // compute a point in 3D view
+    boost::shared_ptr<GeomDataAPI_Point2D> aPoint = 
+      boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(POINT_ATTR_COORD));
+    boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
+    // make a visible point
+    boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
+    setPreview(aPointShape);
+  }
   return getPreview();
 }