]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into SketchSolver
authorazv <azv@opencascade.com>
Mon, 9 Jun 2014 07:22:01 +0000 (11:22 +0400)
committerazv <azv@opencascade.com>
Mon, 9 Jun 2014 07:22:01 +0000 (11:22 +0400)
15 files changed:
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Constants.h
src/PartSet/PartSet_FeatureArcPrs.cpp [new file with mode: 0644]
src/PartSet/PartSet_FeatureArcPrs.h [new file with mode: 0644]
src/PartSet/PartSet_FeatureCirclePrs.h
src/PartSet/PartSet_FeatureLinePrs.cpp
src/PartSet/PartSet_FeatureLinePrs.h
src/PartSet/PartSet_FeaturePointPrs.h
src/PartSet/PartSet_OperationCreateFeature.cpp
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/plugin-Sketch.xml

index 57afd7a6956fb9ae7c033c9997e72a4441a67529..51437474968900e6d73b8c1a04aec5dc1ec61472 100644 (file)
@@ -45,3 +45,22 @@ boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::lineCircle(
   aRes->setImpl(new TopoDS_Shape(anEdge));
   return aRes;
 }
+
+boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::lineCircleArc(
+    boost::shared_ptr<GeomAPI_Pnt> theCenter,
+    boost::shared_ptr<GeomAPI_Pnt> theStartPoint,
+    boost::shared_ptr<GeomAPI_Pnt> theEndPoint,
+    boost::shared_ptr<GeomAPI_Dir> theNormal)
+{
+  const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
+  const gp_Dir& aDir = theNormal->impl<gp_Dir>();
+
+  double aRadius = theCenter->distance(theStartPoint);
+  gp_Circ aCircle(gp_Ax2(aCenter, aDir), aRadius);
+
+  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 b7f527230c9cd6e5458e74c4889a054d8674b117..de532ea563fa18fce180685c69441865107cdb53 100644 (file)
@@ -27,6 +27,13 @@ public:
   static boost::shared_ptr<GeomAPI_Shape> lineCircle(
     boost::shared_ptr<GeomAPI_Pnt> theCenter,
     boost::shared_ptr<GeomAPI_Dir> theNormal, double theRadius);
+
+  /// Creates linear edge in a form of a circle arc by a three points
+  static boost::shared_ptr<GeomAPI_Shape> lineCircleArc(
+    boost::shared_ptr<GeomAPI_Pnt> theCenter,
+    boost::shared_ptr<GeomAPI_Pnt> theStartPoint,
+    boost::shared_ptr<GeomAPI_Pnt> theEndPoint,
+    boost::shared_ptr<GeomAPI_Dir> theNormal);
 };
 
 #endif
index a1c50ac6604f75f4e672a8053519ea02dd043504..a07a1f5990dfd8508477f558bda7376d77147efb 100644 (file)
@@ -5,6 +5,7 @@ SET(CMAKE_AUTOMOC ON)
 SET(PROJECT_HEADERS
        PartSet.h
        PartSet_Constants.h
+       PartSet_FeatureArcPrs.h
        PartSet_FeatureCirclePrs.h
        PartSet_FeaturePrs.h
        PartSet_FeatureLinePrs.h
@@ -23,6 +24,7 @@ SET(PROJECT_HEADERS
 
 SET(PROJECT_SOURCES
        PartSet_FeaturePrs.cpp
+       PartSet_FeatureArcPrs.cpp
        PartSet_FeatureCirclePrs.cpp
        PartSet_FeatureLinePrs.cpp
        PartSet_FeaturePointPrs.cpp
index 95b28bd003d80ada709fbd2d9164a328616cedc2..141e25bde2a638f290cf38444cfc64be8746c77d 100644 (file)
@@ -14,6 +14,7 @@ enum PartSet_SelectionMode
 {
   SM_FirstPoint,
   SM_SecondPoint,
+  SM_ThirdPoint,
   SM_DonePoint
 };
 
diff --git a/src/PartSet/PartSet_FeatureArcPrs.cpp b/src/PartSet/PartSet_FeatureArcPrs.cpp
new file mode 100644 (file)
index 0000000..4cc26f0
--- /dev/null
@@ -0,0 +1,110 @@
+// File:        PartSet_FeaturePrs.h
+// Created:     04 Jun 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <PartSet_FeatureArcPrs.h>
+#include <PartSet_Tools.h>
+
+#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_Arc.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+
+#include <Precision.hxx>
+
+using namespace std;
+
+PartSet_FeatureArcPrs::PartSet_FeatureArcPrs(FeaturePtr theSketch)
+: PartSet_FeaturePrs(theSketch)
+{
+}
+
+PartSet_SelectionMode PartSet_FeatureArcPrs::setPoint(double theX, double theY,
+                                                       const PartSet_SelectionMode& theMode)
+{
+  PartSet_SelectionMode aMode = theMode;
+  switch (theMode)
+  {
+    case SM_FirstPoint: {
+      PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_CENTER);
+      aMode = SM_SecondPoint;
+    }
+    break;
+    case SM_SecondPoint: {
+      PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_START);
+      aMode = SM_ThirdPoint;
+   }
+   break;
+   case SM_ThirdPoint: {
+      PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_END);
+      aMode = SM_DonePoint;
+   }
+    break;
+    default:
+      break;
+  }
+  return aMode;
+}
+
+std::string PartSet_FeatureArcPrs::getAttribute(const PartSet_SelectionMode& theMode) const
+{
+  std::string aAttribute;
+  switch (theMode)
+  {
+    case SM_FirstPoint:
+      aAttribute = ARC_ATTR_CENTER;
+    break;
+    case SM_SecondPoint:
+      aAttribute = ARC_ATTR_START;
+    break;
+    case SM_ThirdPoint:
+      aAttribute = ARC_ATTR_END;
+    break;
+    default:
+    break;
+  }
+  return aAttribute;
+}
+
+PartSet_SelectionMode PartSet_FeatureArcPrs::getNextMode(const std::string& theAttribute) const
+{
+  PartSet_SelectionMode aMode;
+
+  if (theAttribute == ARC_ATTR_CENTER)
+    aMode = SM_SecondPoint;
+  else if (theAttribute == ARC_ATTR_START)
+    aMode = SM_ThirdPoint;
+  else if (theAttribute == ARC_ATTR_END)
+    aMode = SM_DonePoint;
+  return aMode;
+}
+
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureArcPrs::featurePoint
+                                                     (const PartSet_SelectionMode& theMode)
+{
+  std::string aPointArg;
+  switch (theMode)
+  {
+    case SM_FirstPoint:
+      aPointArg = ARC_ATTR_CENTER;
+      break;
+    case SM_SecondPoint:
+      aPointArg = ARC_ATTR_START;
+      break;
+    case SM_ThirdPoint:
+      aPointArg = ARC_ATTR_END;
+      break;
+    default:
+      break;
+  }
+  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                              (aData->attribute(aPointArg));
+  return aPoint;
+}
diff --git a/src/PartSet/PartSet_FeatureArcPrs.h b/src/PartSet/PartSet_FeatureArcPrs.h
new file mode 100644 (file)
index 0000000..ea25b97
--- /dev/null
@@ -0,0 +1,53 @@
+// File:        PartSet_FeatureArcPrs.h
+// Created:     04 Jun 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef PartSet_FeatureArcPrs_H
+#define PartSet_FeatureArcPrs_H
+
+#include "PartSet.h"
+
+#include "PartSet_FeaturePrs.h"
+#include "PartSet_Constants.h"
+
+class GeomDataAPI_Point2D;
+
+/*!
+ \class PartSet_FeatureArcPrs
+ * \brief The class to define the circle arc feature manipulation. It is created for
+ * the feature create operation to move out the feature properties set and use one operation
+ * for any type of features.
+*/
+class PARTSET_EXPORT PartSet_FeatureArcPrs : public PartSet_FeaturePrs
+{
+public:
+  /// Constructor
+  /// \param theSketch the sketch feature
+  PartSet_FeatureArcPrs(FeaturePtr theSketch);
+  /// Destructor
+  virtual ~PartSet_FeatureArcPrs() {};
+
+  /// Sets the point to the feature in an attribute depending on the selection mode
+  /// \param theX the 2D point horizontal coordinate
+  /// \param theY the 2D point vertical coordinate
+  /// \param theMode the selection mode
+  /// \return the new selection mode
+  virtual PartSet_SelectionMode setPoint(double theX, double theY,
+                                         const PartSet_SelectionMode& theMode);
+
+  /// Returns the feature attribute name for the selection mode
+  /// \param theMode the current operation selection mode. The feature attribute depends on the mode
+  virtual std::string getAttribute(const PartSet_SelectionMode& theMode) const;
+
+  /// Returns the next selection mode after the attribute
+  /// \param theAttribute the feature attribute name
+  /// \return next attribute selection mode
+  virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+
+protected:
+  /// 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);
+};
+
+#endif
index ef4b8497dc2012b5edb514bc372b9761506c503b..6a75b05b87e0adf726e335acd1b6031276013e33 100644 (file)
@@ -14,7 +14,7 @@ class GeomDataAPI_Point2D;
 
 /*!
  \class PartSet_FeatureCirclePrs
- * \brief The abstract class to define the specific feature manipulation. It is created for
+ * \brief The class to define the circle feature manipulation. It is created for
  * the feature create operation to move out the feature properties set and use one operation
  * for any type of features.
 */
index 5e67aaeeef6ade656ab6f1eb7a19e28fe453d626..d6200d5766a4b0fd54ab4d9a8e9bca0706ca62f1 100644 (file)
@@ -19,6 +19,7 @@
 #include <ModelAPI_AttributeRefList.h>
 
 #include <Precision.hxx>
+#include <V3d_View.hxx>
 
 using namespace std;
 
@@ -96,6 +97,33 @@ PartSet_SelectionMode PartSet_FeatureLinePrs::getNextMode(const std::string& the
   return aMode;
 }
 
+void PartSet_FeatureLinePrs::projectPointOnLine(FeaturePtr theFeature,
+                                                const PartSet_SelectionMode& theMode,
+                                                const gp_Pnt& thePoint, Handle(V3d_View) theView,
+                                                double& theX, double& theY)
+{
+  if (theFeature) {
+    double X0, X1, X2, X3;
+    double Y0, Y1, Y2, Y3;
+    PartSet_Tools::getLinePoint(theFeature, LINE_ATTR_START, X2, Y2);
+    PartSet_Tools::getLinePoint(theFeature, LINE_ATTR_END, X3, Y3);
+    PartSet_Tools::convertTo2D(thePoint, sketch(), theView, X1, Y1);
+
+    switch (theMode) {
+      case SM_FirstPoint:
+        PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, theX, theY);
+      break;
+      case SM_SecondPoint: {
+        PartSet_Tools::getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
+        PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, theX, theY);
+      }
+      break;
+      default:
+      break;
+    }
+  }
+}
+
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLinePrs::featurePoint
                                                      (const PartSet_SelectionMode& theMode)
 {
index a2ff5bba0397c2937512fdb0a43ef7373efb5b3b..eefced5e5c910166e6fa124781e1174c75da6722 100644 (file)
 #include "PartSet_FeaturePrs.h"
 #include "PartSet_Constants.h"
 
+#include <gp_Pnt.hxx>
+
 class GeomDataAPI_Point2D;
+class Handle_V3d_View;
 
 /*!
  \class PartSet_FeatureLinePrs
- * \brief The abstract class to define the specific feature manipulation. It is created for
+ * \brief The class to define the line feature manipulation. It is created for
  * the feature create operation to move out the feature properties set and use one operation
  * for any type of features.
 */
@@ -44,6 +47,18 @@ public:
   /// \return next attribute selection mode
   virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
 
+
+  /// Project the point on a feature
+  /// \param theFeature the feature to be projected on
+  /// \param theMode the selection mode
+  /// \param thePoint the clicked point
+  /// \param theView the viewer
+  /// \param theX the output horizontal coordinate
+  /// \param theY the output vertical coordinate
+  void projectPointOnLine(FeaturePtr theFeature, const PartSet_SelectionMode& theMode,
+                          const gp_Pnt& thePoint, Handle_V3d_View theView,
+                          double& theX, double& theY);
+
 protected:
   /// Initializes current feature by the given
   /// \param theSourceFeature the feature, which attributes are used to initialize the current feature
index fa9f73debc765a8b11021f40a68836a914ba40ac..bd63137f227991d5a9da3d1a3487b6c8cf48d66b 100644 (file)
@@ -14,7 +14,7 @@ class GeomDataAPI_Point2D;
 
 /*!
  \class PartSet_FeaturePointPrs
- * \brief The abstract class to define the specific feature manipulation. It is created for
+ * \brief The class to define the point feature manipulation. It is created for
  * the feature create operation to move out the feature properties set and use one operation
  * for any type of features.
 */
index 7905f6a019ce9cf57343325fec236529db54e10e..4c117b3ebec475bb07e1572ac692f6a582a0fd17 100644 (file)
@@ -9,11 +9,13 @@
 #include <PartSet_FeaturePointPrs.h>
 #include <PartSet_FeatureLinePrs.h>
 #include <PartSet_FeatureCirclePrs.h>
+#include <PartSet_FeatureArcPrs.h>
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Point.h>
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Arc.h>
 
 #include <ModuleBase_OperationDescription.h>
 
@@ -50,6 +52,9 @@ PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& th
   else if (aKind == SKETCH_CIRCLE_KIND) {
     myFeaturePrs = new PartSet_FeatureCirclePrs(theFeature);
   }
+  else if (aKind == SKETCH_ARC_KIND) {
+    myFeaturePrs = new PartSet_FeatureArcPrs(theFeature);
+  }
 }
 
 PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature()
@@ -59,7 +64,8 @@ PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature()
 
 bool PartSet_OperationCreateFeature::canProcessKind(const std::string& theId)
 {
-  return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND || theId == SKETCH_CIRCLE_KIND;
+  return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND || theId == SKETCH_CIRCLE_KIND ||
+         theId == SKETCH_ARC_KIND;
 }
 
 bool PartSet_OperationCreateFeature::canBeCommitted() const
@@ -109,11 +115,9 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
 
   double aX, anY;
 
-  bool isFoundPoint = false;
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
   if (theSelected.empty()) {
     PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
-    isFoundPoint = true;
   }
   else {
     XGUI_ViewerPrs aPrs = theSelected.front();
@@ -125,7 +129,6 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
         if (!aVertex.IsNull()) {
           aPoint = BRep_Tool::Pnt(aVertex);
           PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
-          isFoundPoint = true;
 
           myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode);
         }
@@ -133,31 +136,14 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
       else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
       {
         PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
-        isFoundPoint = true;
-        /*
-        FeaturePtr aFeature = aPrs.feature();
-        if (aFeature) {
-          double X0, X1, X2, X3;
-          double Y0, Y1, Y2, Y3;
-          PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
-          PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
-          PartSet_Tools::convertTo2D(aPoint, sketch(), theView, X1, Y1);
-
-          switch (myPointSelectionMode) {
-            case SM_FirstPoint:
-              PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY);
-            break;
-            case SM_SecondPoint: {
-              PartSet_Tools::getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
-              PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY);
-            }
-            break;
-            default:
-            break;
+        // move to selected line
+        if (feature()->getKind() == SKETCH_LINE_KIND) {
+          PartSet_FeatureLinePrs* aLinePrs = dynamic_cast<PartSet_FeatureLinePrs*>(myFeaturePrs);
+          if (aLinePrs) {
+            FeaturePtr aFeature = aPrs.feature();
+            aLinePrs->projectPointOnLine(aFeature, myPointSelectionMode, aPoint, theView, aX, anY);
           }
-          isFoundPoint = true;
         }
-        */
       }
     }
   }
@@ -165,7 +151,8 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
   switch (myPointSelectionMode)
   {
     case SM_FirstPoint:
-    case SM_SecondPoint: {
+    case SM_SecondPoint:
+    case SM_ThirdPoint: {
       PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
       flushUpdated();
       setPointSelectionMode(aMode);
@@ -182,6 +169,7 @@ void PartSet_OperationCreateFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3
   {
     case SM_FirstPoint:
     case SM_SecondPoint:
+    case SM_ThirdPoint:
     {
       double aX, anY;
       gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
index ed5275b0091ffc5592a7a8ee54d17aa53d262c1c..1830a00585c97c9d0fe55e7b847be5b909c331dc 100644 (file)
@@ -5,7 +5,13 @@
 #include "SketchPlugin_Arc.h"
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
+
 #include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
+
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
 
 SketchPlugin_Arc::SketchPlugin_Arc()
   : SketchPlugin_Feature()
@@ -25,6 +31,40 @@ void SketchPlugin_Arc::execute()
 
 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Arc::preview()
 {
-  /// \todo Implement preview for arc of circle
+  SketchPlugin_Sketch* aSketch = sketch();
+  if (aSketch) {
+    std::list<boost::shared_ptr<GeomAPI_Shape> > aShapes;
+
+    // compute a circle point in 3D view
+    boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = 
+      boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_CENTER));
+    boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+    // 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()));
+      // compute the arc start point
+      boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_START));
+      boost::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+
+      // compute the arc end point
+      boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = 
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_END));
+      boost::shared_ptr<GeomAPI_Pnt> aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
+
+      boost::shared_ptr<GeomAPI_Shape> aCircleShape = 
+                 GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStartPoint, aEndPoint, aNormal);
+      aShapes.push_back(aCircleShape);
+    }
+    boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+    setPreview(aCompound);
+  }
   return getPreview();
 }
index af26e92308ee7b48c6a9aa077989ae37dbff1acd..d58a58dd76f1de3b5617291bfc921f62f19e753c 100644 (file)
@@ -5,11 +5,13 @@
 #include "SketchPlugin_Circle.h"
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
+
 #include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
+
 #include <GeomAlgoAPI_PointBuilder.h>
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
-#include <GeomDataAPI_Dir.h>
 
 #include <ModelAPI_AttributeDouble.h>
 
@@ -32,17 +34,12 @@ const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Circle::preview()
 {
   SketchPlugin_Sketch* aSketch = sketch();
   if (aSketch) {
+    std::list<boost::shared_ptr<GeomAPI_Shape> > aShapes;
+
     // 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);
@@ -53,15 +50,17 @@ const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Circle::preview()
     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()));
+      // 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();
 
       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);
     }
+    boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+    setPreview(aCompound);
   }
-  /// \todo Implement preview for the circle
   return getPreview();
 }
index 14e61b2362c7806c27657e8017b92cb77c2f95c8..d494a63790a8cc9558e97ca2cda6a995d2b97514 100644 (file)
@@ -38,6 +38,9 @@ FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID)
   else if (theFeatureID == SKETCH_CIRCLE_KIND) {
     return FeaturePtr(new SketchPlugin_Circle);
   }
+  else if (theFeatureID == SKETCH_ARC_KIND) {
+    return FeaturePtr(new SketchPlugin_Arc);
+  }
   else if (theFeatureID == SKETCH_CONSTRAINT_COINCIDENCE_KIND) {
     return FeaturePtr(new SketchPlugin_ConstraintCoincidence);
   }
index f5d7507d3fb82a5b5fa0cfc820c44ebeb808b46e..e39aa518cf6fe8c2f589d2b237529cbd5d6fdbe2 100644 (file)
@@ -1,7 +1,7 @@
 <plugin>
   <workbench id="Sketch">
     <group id="Basic">
-      <feature id="Sketch" nested="SketchPoint SketchLine SketchCircle SketchConstraintLength" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+      <feature id="Sketch" nested="SketchPoint SketchLine SketchCircle SketchArc SketchConstraintLength" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
         <label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/> 
       <!--icon=":pictures/x_point.png"-->
       </feature>
@@ -16,7 +16,7 @@
         <point_selector id="CircleCenter" title="Center" tooltip="Center of the circle"/>
         <doublevalue id="CircleRadius" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set Radius"/>
       </feature>
-      <feature id="SketchArc" title="Arc" tooltip="Create a new arc of a circle" icon="" internal="1">
+      <feature id="SketchArc" title="Arc" tooltip="Create a new arc of a circle" icon="">
         <point_selector id="ArcCenter" title="Center" tooltip="Center of the arc"/>
         <point_selector id="ArcStartPoint" title="Start point" tooltip="Start point of the arc"/>
         <point_selector id="ArcEndPoint" title="End point" tooltip="End point of the arc"/>