]> 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>
Sat, 21 Jun 2014 08:25:20 +0000 (12:25 +0400)
committernds <natalia.donis@opencascade.com>
Sat, 21 Jun 2014 08:25:20 +0000 (12:25 +0400)
1. SetCustomValue for a dimension to show the model value, not a real one
2. Dir2d to add new costructor in Curc2d
3. Visualize Radius dimension
4. projectPointOnFeature for arc and circle (was projectPointOnArc)

20 files changed:
src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_Circ2d.cpp
src/GeomAPI/GeomAPI_Circ2d.h
src/GeomAPI/GeomAPI_Dir2d.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Dir2d.h [new file with mode: 0644]
src/GeomAPI/GeomAPI_Pnt2d.cpp
src/GeomAPI/GeomAPI_Pnt2d.h
src/PartSet/PartSet_ConstraintDistancePrs.cpp
src/PartSet/PartSet_ConstraintLengthPrs.cpp
src/PartSet/PartSet_ConstraintRadiusPrs.cpp
src/PartSet/PartSet_ConstraintRadiusPrs.h
src/PartSet/PartSet_FeatureArcPrs.cpp
src/PartSet/PartSet_FeatureArcPrs.h
src/PartSet/PartSet_FeatureCirclePrs.cpp
src/PartSet/PartSet_FeatureCirclePrs.h
src/PartSet/PartSet_OperationCreateConstraint.cpp
src/PartSet/PartSet_OperationCreateFeature.cpp
src/PartSet/PartSet_OperationEditConstraint.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h

index e14d63fe3d7559daea10803987490dd6194efb7e..b268a83b652ec1083ad1d095d0f4beba812851ed 100644 (file)
@@ -14,6 +14,7 @@ SET(PROJECT_HEADERS
     GeomAPI_Lin.h
     GeomAPI_Lin2d.h
     GeomAPI_Dir.h
+    GeomAPI_Dir2d.h
     GeomAPI_Pln.h
     GeomAPI_Shape.h
 )
@@ -28,6 +29,7 @@ SET(PROJECT_SOURCES
     GeomAPI_Lin.cpp
     GeomAPI_Lin2d.cpp
     GeomAPI_Dir.cpp
+    GeomAPI_Dir2d.cpp
     GeomAPI_Pln.cpp
     GeomAPI_Shape.cpp
 )
index 4985ae3f4d9ddb629a1eb16271965cda6f923aab..27854d2a943194acfa1dc3536051feb6b42ce235 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <GeomAPI_Circ2d.h>
 #include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Dir2d.h>
 
 #include <gp_Dir2d.hxx>
 #include <gp_Circ2d.hxx>
 
 #define MY_CIRC2D static_cast<gp_Circ2d*>(myImpl)
 
+static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
+                            const gp_Dir2d theDir, const double theRadius)
+{
+  gp_Pnt2d aCenter(theCenterX, theCenterY);
+  return new gp_Circ2d(gp_Ax2d(aCenter, theDir), theRadius);
+}
+
 static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
                             const double thePointX,   const double thePointY)
 {
@@ -29,16 +37,25 @@ static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
       return NULL;
 
   gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY);
-  return new gp_Circ2d(gp_Ax2d(aCenter, aDir), aRadius);
+  
+  return newCirc2d(theCenterX, theCenterY, aDir, aRadius);
 }
 
-
 GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
                                const boost::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint)
   : GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(),
                                 theCirclePoint->x(),   theCirclePoint->y()))
 {}
 
+GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                               const boost::shared_ptr<GeomAPI_Dir2d>& theDir,
+                               double theRadius)
+ : GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(),
+                               theDir->impl<gp_Dir2d>(), theRadius))
+{
+
+}
+
 const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
 {
   boost::shared_ptr<GeomAPI_Pnt2d> aResult;
index 8b91d8332f3adeb2614646ac9dae3351e4b7dcff..1870cbba80e160350ed0e6b7e1beae04af5b52b6 100644 (file)
@@ -9,6 +9,7 @@
 #include <boost/shared_ptr.hpp>
 
 class GeomAPI_Pnt2d;
+class GeomAPI_Dir2d;
 
 /**\class GeomAPI_Circ2d
  * \ingroup DataModel
@@ -22,6 +23,11 @@ public:
   GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
                  const boost::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint);
 
+  /// Creation of circle defined by center point, direction and circle radius
+  GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                 const boost::shared_ptr<GeomAPI_Dir2d>& theDir,
+                 double theRadius);
+
   /// Project point on line
   const boost::shared_ptr<GeomAPI_Pnt2d> project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
 };
diff --git a/src/GeomAPI/GeomAPI_Dir2d.cpp b/src/GeomAPI/GeomAPI_Dir2d.cpp
new file mode 100644 (file)
index 0000000..fd795ab
--- /dev/null
@@ -0,0 +1,44 @@
+// File:        GeomAPI_Dir2d.cpp
+// Created:     23 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#include <GeomAPI_Dir2d.h>
+#include <GeomAPI_XY.h>
+
+#include <gp_Dir2d.hxx>
+
+#define MY_DIR static_cast<gp_Dir2d*>(myImpl)
+
+GeomAPI_Dir2d::GeomAPI_Dir2d(const double theX, const double theY)
+  : GeomAPI_Interface(new gp_Dir2d(theX, theY))
+{}
+
+GeomAPI_Dir2d::GeomAPI_Dir2d(const boost::shared_ptr<GeomAPI_XY>& theCoords)
+  : GeomAPI_Interface(new gp_Dir2d(theCoords->x(), theCoords->y()))
+{}
+
+double GeomAPI_Dir2d::x() const
+{
+  return MY_DIR->X();
+}
+
+double GeomAPI_Dir2d::y() const
+{
+  return MY_DIR->Y();
+}
+
+const boost::shared_ptr<GeomAPI_XY> GeomAPI_Dir2d::xy() 
+{
+  return boost::shared_ptr<GeomAPI_XY>(new GeomAPI_XY(MY_DIR->X(), MY_DIR->Y()));
+}
+
+double GeomAPI_Dir2d::dot(const boost::shared_ptr<GeomAPI_Dir2d>& theArg) const
+{
+  return MY_DIR->Dot(theArg->impl<gp_Dir2d>());
+}
+
+double GeomAPI_Dir2d::cross(const boost::shared_ptr<GeomAPI_Dir2d>& theArg) const
+{
+  return MY_DIR->XY().Crossed(theArg->impl<gp_Dir2d>().XY());
+}
+
diff --git a/src/GeomAPI/GeomAPI_Dir2d.h b/src/GeomAPI/GeomAPI_Dir2d.h
new file mode 100644 (file)
index 0000000..4c9e6fc
--- /dev/null
@@ -0,0 +1,41 @@
+// File:        GeomAPI_Dir2d.hxx
+// Created:     23 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef GeomAPI_Dir2d_HeaderFile
+#define GeomAPI_Dir2d_HeaderFile
+
+#include <GeomAPI_Interface.h>
+#include <boost/shared_ptr.hpp>
+
+class GeomAPI_XY;
+
+/**\class GeomAPI_Dir2d
+ * \ingroup DataModel
+ * \brief 2D direction defined by three normalized coordinates
+ */
+
+class GEOMAPI_EXPORT GeomAPI_Dir2d: public GeomAPI_Interface
+{
+public:
+  /// Creation of direction by coordinates
+  GeomAPI_Dir2d(const double theX, const double theY);
+  /// Creation of direction by coordinates
+  GeomAPI_Dir2d(const boost::shared_ptr<GeomAPI_XY>& theCoords);
+
+  /// returns X coordinate
+  double x() const;
+  /// returns Y coordinate
+  double y() const;
+
+  /// returns coordinates of the direction
+  const boost::shared_ptr<GeomAPI_XY> xy();
+
+  /// result is a scalar product of directions
+  double dot(const boost::shared_ptr<GeomAPI_Dir2d>& theArg) const;
+  /// result is a cross product of two directions
+  double cross(const boost::shared_ptr<GeomAPI_Dir2d>& theArg) const;
+};
+
+#endif
+
index 1b4ee554bfb82bde1c9bdc1338b246635bbe2489..e1cdf3d283e53b2627bee83afb0681b542f28b1a 100644 (file)
@@ -4,6 +4,9 @@
 
 #include<GeomAPI_Pnt2d.h>
 #include<GeomAPI_XY.h>
+#include<GeomAPI_XYZ.h>
+#include<GeomAPI_Pnt.h>
+#include<GeomAPI_Dir.h>
 
 #include<gp_Pnt2d.hxx>
 
@@ -37,6 +40,16 @@ void GeomAPI_Pnt2d::setY(const double theY)
   return MY_PNT2D->SetY(theY);
 }
 
+boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Pnt2d::to3D(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+                                                   const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+                                                   const boost::shared_ptr<GeomAPI_Dir>& theDirY)
+{
+  boost::shared_ptr<GeomAPI_XYZ> aSum = theOrigin->xyz()->added(
+    theDirX->xyz()->multiplied(x()))->added(theDirY->xyz()->multiplied(y()));
+
+  return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
+}
+
 const boost::shared_ptr<GeomAPI_XY> GeomAPI_Pnt2d::xy()
 {
   return boost::shared_ptr<GeomAPI_XY>(new GeomAPI_XY(MY_PNT2D->X(), MY_PNT2D->Y()));
index a1faf626c561b1e5df015cb502575af70cbab1c4..91aec7eee0b22864d460c5b2a3fc972ddab6b7f3 100644 (file)
@@ -9,6 +9,8 @@
 #include <boost/shared_ptr.hpp>
 
 class GeomAPI_XY;
+class GeomAPI_Pnt;
+class GeomAPI_Dir;
 
 /**\class GeomAPI_Pnt2d
  * \ingroup DataModel
@@ -33,6 +35,11 @@ public:
   /// sets Y coordinate
   void setY(const double theY);
 
+  /// Returns the 3D point
+  boost::shared_ptr<GeomAPI_Pnt> to3D(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+                                      const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+                                      const boost::shared_ptr<GeomAPI_Dir>& theDirY);
+
   /// returns coordinates of the point
   const boost::shared_ptr<GeomAPI_XY> xy();
 
index 29a0d19c27f4508a707f9a9a8e689c38c7869445..d63e98c26f90ad2df3ba9fd6638b45792e243f4f 100644 (file)
@@ -112,14 +112,10 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintDistancePrs::createPresentation(
   if (!theFeature || !theSketch)
     return anAIS;
   /*
-  boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
-  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
-  boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
-  gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0);
-
-  aData = theFeature->data();
+  boost::shared_ptr<GeomAPI_Pln> aGPlane = PartSet_Tools::sketchPlane(theSketch);
+  gp_Pln aPlane = aGPlane->impl<gp_Pln>();
+
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
   if (!anAttr)
index 716b435ebabc3fb8e332c9953d3a00a17a14b17c..67df7c4c729ac62de750244ed0c061e9d5e288fe 100644 (file)
@@ -18,6 +18,7 @@
 #include <GeomDataAPI_Dir.h>
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pln.h>
 
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_LengthDimension.hxx>
@@ -119,14 +120,10 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintLengthPrs::createPresentation(Fe
   if (!theFeature || !theSketch)
     return thePreviuos;
 
-  boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
-  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
-  boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
-  gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0/*D*/);
+  boost::shared_ptr<GeomAPI_Pln> aGPlane = PartSet_Tools::sketchPlane(theSketch);
+  gp_Pln aPlane = aGPlane->impl<gp_Pln>();
 
-  aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
   if (!anAttr)
@@ -139,6 +136,10 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintLengthPrs::createPresentation(Fe
           boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
   double aFlyout = aFlyoutAttr->value();
 
+  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
+          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+  double aValue = aValueAttr->value();
+
   aData = aFeature->data();
   if (!aData->isValid())
     return thePreviuos;
@@ -164,6 +165,7 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintLengthPrs::createPresentation(Fe
   if (anAIS.IsNull())
   {
     Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane);
+    aDimAIS->SetCustomValue(aValue);
 
     Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
     anAspect->MakeArrows3d (Standard_False);
@@ -186,6 +188,7 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintLengthPrs::createPresentation(Fe
     Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
     if (!aDimAIS.IsNull()) {
       aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane);
+      aDimAIS->SetCustomValue(aValue);
       aDimAIS->SetFlyout(aFlyout);
 
       aDimAIS->Redisplay(Standard_True);
index bee75f1c38c60c29e0e3d804185266c8611e9466..216f800febf07fc9be6633a57ae35613e1620a3e 100644 (file)
@@ -5,7 +5,8 @@
 #include <PartSet_ConstraintRadiusPrs.h>
 #include <PartSet_Tools.h>
 
-#include <PartSet_FeatureLinePrs.h>
+#include <PartSet_FeatureCirclePrs.h>
+#include <PartSet_FeatureArcPrs.h>
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_ConstraintRadius.h>
 
+#include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Dir.h>
+
+#include <GeomAlgoAPI_EdgeBuilder.h>
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeDouble.h>
 
 #include <AIS_InteractiveObject.hxx>
+#include <AIS_RadiusDimension.hxx>
 #include <Precision.hxx>
+#include <gp_Circ.hxx>
+#include <V3d_View.hxx>
 
 using namespace std;
 
@@ -42,26 +52,31 @@ std::string PartSet_ConstraintRadiusPrs::getKind()
 bool PartSet_ConstraintRadiusPrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode)
 {
   bool aResult = false;
-  if (feature() && theMode == SM_FirstPoint &&
-      (theFeature && theFeature->getKind() == SKETCH_CIRCLE_KIND ||
-       theFeature && theFeature->getKind() == SKETCH_ARC_KIND)) {
+  if (!feature() || theMode != SM_FirstPoint || !theFeature) {
+    return aResult;
+  }
+  std::string aKind = theFeature->getKind();
+  if (aKind == SKETCH_CIRCLE_KIND || aKind == SKETCH_ARC_KIND) {
     // set length feature
     boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
     boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
     aRef->setFeature(theFeature);
 
-    // set length value
-    /*aData = theFeature->data();
-    boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
-          boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
-    boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
-          boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-
-    double aLenght = aPoint1->pnt()->distance(aPoint2->pnt());
-    */
-    double aLenght = 50;
-    PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE);
+    double aLength = 50;
+    bool isValid;
+    if (aKind == SKETCH_CIRCLE_KIND) {
+      aLength = PartSet_Tools::featureValue(theFeature, CIRCLE_ATTR_RADIUS, isValid);
+    }
+    else if (aKind == SKETCH_ARC_KIND) {
+      boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = 
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute(ARC_ATTR_CENTER));
+      boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute(ARC_ATTR_START));
+      aLength = aCenterAttr->pnt()->distance(aStartAttr->pnt());
+    }
+
+    PartSet_Tools::setFeatureValue(feature(), aLength, CONSTRAINT_ATTR_VALUE);
     aResult = true;
   }
   return aResult;
@@ -75,31 +90,16 @@ PartSet_SelectionMode PartSet_ConstraintRadiusPrs::setPoint(double theX, double
   {
     case SM_SecondPoint: {
       boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-      /*boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
-              boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
-      FeaturePtr aFeature;
-      if (anAttr) {
-        aFeature = anAttr->feature();
-        if (aFeature->getKind() != SKETCH_LINE_KIND) {
-          aFeature = FeaturePtr();
-        }
-      }
+
       boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>
                                                              (new GeomAPI_Pnt2d(theX, theY));
-      boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = PartSet_FeatureLinePrs::createLin2d(aFeature);
-      boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aPoint);
-      double aDistance = aPoint->distance(aResult);
 
-      double aStartX, aStartY;
-      PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY);
+      PartSet_Tools::setFeaturePoint(feature(), theX, theY, SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT);
 
-      if (!aFeatureLin->isRight(aPoint))
-        aDistance = -aDistance;
-        */
-      double aDistance = 40;
-      AttributeDoublePtr aFlyoutAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
-      aFlyoutAttr->setValue(aDistance);
+      //double aDistance = 40;
+      //AttributeDoublePtr aFlyoutAttr = 
+      //    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+      //aFlyoutAttr->setValue(aDistance);
 
       aMode = SM_DonePoint;
     }
@@ -117,52 +117,61 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintRadiusPrs::createPresentation(Fe
   Handle(AIS_InteractiveObject) anAIS = thePreviuos;
   if (!theFeature || !theSketch)
     return anAIS;
-  /*
-  boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
-  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
-  boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
-  gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0);
-
-  aData = theFeature->data();
+
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
   if (!anAttr)
-    return thePreviuos;
+    return anAIS;
   FeaturePtr aFeature = anAttr->feature();
-  if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND)
-    return thePreviuos;
-
-  boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
-  double aFlyout = aFlyoutAttr->value();
-
-  aData = aFeature->data();
-  if (!aData->isValid())
-    return thePreviuos;
-
-  boost::shared_ptr<GeomDataAPI_Point2D> aPointStart =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
-  boost::shared_ptr<GeomDataAPI_Point2D> aPointEnd =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-
-  gp_Pnt aPoint1, aPoint2;
-  PartSet_Tools::convertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1);
-  PartSet_Tools::convertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2);
-
-  //Build dimension here
-  gp_Pnt aP1 = aPoint1;
-  gp_Pnt aP2 = aPoint2;
-  if (aFlyout < 0) {
-    aP1 = aPoint2;
-    aP2 = aPoint1;
-  }
+  if (!aFeature || aFeature->getKind() != SKETCH_CIRCLE_KIND)
+    return anAIS;
 
-  Handle(AIS_InteractiveObject) anAIS = thePreviuos;
+
+  //boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr = 
+  //        boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+  //double aFlyout = aFlyoutAttr->value();
+  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
+          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+  double aValue = aValueAttr->value();
+
+  gp_Circ aCircle;
+  gp_Pnt anAnchorPoint;
+  double aRadius;
+  //boost::shared_ptr<GeomAPI_Shape> aShape;
+  if (aFeature->getKind() == SKETCH_CIRCLE_KIND) {
+    boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+    // a circle
+    boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = 
+      boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
+    boost::shared_ptr<GeomAPI_Pnt2d> aCenter2D = aCenterAttr->pnt();
+    
+    boost::shared_ptr<GeomAPI_Pnt> aCenter = PartSet_Tools::point3D(aCenter2D, theSketch);
+
+    boost::shared_ptr<GeomDataAPI_Dir> aNDir = 
+      boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theSketch->data()->attribute(SKETCH_ATTR_NORM));
+    boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
+    const gp_Dir& aDir = aNormal->impl<gp_Dir>();
+    bool isValid;
+    aRadius = PartSet_Tools::featureValue(aFeature, CIRCLE_ATTR_RADIUS, isValid);
+    aCircle = gp_Circ(gp_Ax2(aCenter->impl<gp_Pnt>(), aDir), aRadius);
+
+    // an anchor point
+    boost::shared_ptr<GeomDataAPI_Point2D> aAnchorAttr = 
+      boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute
+                                                         (SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT));
+    boost::shared_ptr<GeomAPI_Pnt2d> anAnchor2D = aAnchorAttr->pnt();
+    boost::shared_ptr<GeomAPI_Pnt> anAnchor = PartSet_Tools::point3D(anAnchor2D, theSketch);
+    anAnchorPoint = anAnchor->impl<gp_Pnt>();
+
+    //aShape = GeomAlgoAPI_EdgeBuilder::line(aCenter, anAnchor);
+      //boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd)
+  }
   if (anAIS.IsNull())
   {
-    Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane);
+    Handle(AIS_RadiusDimension) aDimAIS = new AIS_RadiusDimension(aCircle, anAnchorPoint);
+    aDimAIS->SetCustomValue(aValue);
+    //Handle(AIS_RadiusDimension) aDimAIS = new AIS_RadiusDimension(aShape->impl<TopoDS_Shape>());
 
     Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
     anAspect->MakeArrows3d (Standard_False);
@@ -170,30 +179,60 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintRadiusPrs::createPresentation(Fe
     anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
     anAspect->MakeTextShaded(false);
     aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
-    //if (isUnitsDisplayed)
-    //{
-    //  aDimAIS->SetDisplayUnits (aDimDlg->GetUnits ());
-    //}
     aDimAIS->SetDimensionAspect (anAspect);
-    aDimAIS->SetFlyout(aFlyout);
+    //aDimAIS->SetFlyout(aFlyout);
     aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
 
     anAIS = aDimAIS;
   }
   else {
     // update presentation
-    Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
+    Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS);
     if (!aDimAIS.IsNull()) {
-      aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane);
-      aDimAIS->SetFlyout(aFlyout);
+      gp_Pnt anAPoint(anAnchorPoint.X(),anAnchorPoint.Y(),anAnchorPoint.Z());
 
+      aDimAIS->SetMeasuredGeometry(aCircle, anAnchorPoint);
+      aDimAIS->SetCustomValue(aValue);
+      //aDimAIS->SetMeasuredGeometry(aShape->impl<TopoDS_Shape>());
+      //aDimAIS->SetFlyout(aFlyout);
       aDimAIS->Redisplay(Standard_True);
     }
   }
-*/
   return anAIS;
 }
 
+void PartSet_ConstraintRadiusPrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch,
+                                                        gp_Pnt& thePoint, Handle(V3d_View) theView,
+                                                        double& theX, double& theY)
+{
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
+          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+  if (!anAttr)
+    return;
+  FeaturePtr aFeature = anAttr->feature();
+  if (!aFeature)
+    return;
+
+  gp_Circ aCircle;
+  gp_Pnt anAnchorPoint;
+  if (aFeature->getKind() == SKETCH_CIRCLE_KIND) {
+    PartSet_FeatureCirclePrs::projectPointOnFeature(aFeature, theSketch, thePoint, theView, theX, theY);
+  }
+  else if (aFeature->getKind() == SKETCH_ARC_KIND) {
+    PartSet_FeatureArcPrs::projectPointOnFeature(aFeature, theSketch, thePoint, theView, theX, theY);
+  }
+  // TODO: a bug in AIS_RadiusDimension:
+  // The anchor point can't be myCirc.Location() - an exception is raised.
+  // But we need exactly this case...
+  // We want to show a radius dimension starting from the circle centre and 
+  // ending at the user-defined point.
+  // Also, if anchor point coincides with myP2, the radius dimension is not displayed at all.
+  double aDelta = 1/1000.0;
+  theX += aDelta;
+  theY += aDelta;
+}
+
 std::string PartSet_ConstraintRadiusPrs::getAttribute(const PartSet_SelectionMode& theMode) const
 {
   return "";
index c71ac902b5eaa33fa9f7d4ef6ee8a9af8d512e0b..754f2dadf0fe49a3b7fcc9c142b6da1e40a2247a 100644 (file)
 #include "PartSet_FeaturePrs.h"
 #include "PartSet_Constants.h"
 
+#include <gp_Pnt.hxx>
+
 class GeomDataAPI_Point2D;
 class Handle_AIS_InteractiveObject;
+class Handle_V3d_View;
 
 /*!
  \class PartSet_ConstraintRadiusPrs
@@ -81,6 +84,16 @@ public:
   /// \param theY the vertical point coordinate
   virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
                                                            double theY);
+  /// Project the view point on the feature. The output coordinates belong to the feature
+  /// \param theFeature a feature
+  /// \param theSketch the sketch feature
+  /// \param thePoint a viewer point
+  /// \param theView the OCC view
+  /// \theX the output horizontal coordinate of a projected point
+  /// \theY the output vertical coordinate of a projected point
+  static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint,
+                                    Handle_V3d_View theView, double& theX, double& theY);
+
 protected:
   /// Returns the feature point in the selection mode position.
   /// \param theMode the current operation selection mode. The feature attribute depends on the mode
index 0e76f6e8b899d7ea9364dd7fe93d6f4af5ebc444..29d65a9cf60bf07a00c596a9bce1889338c396ec 100644 (file)
@@ -168,16 +168,17 @@ boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureArcPrs::findPoint(FeatureP
   return aPoint2D;
 }
 
-void PartSet_FeatureArcPrs::projectPointOnArc(gp_Pnt& thePoint, Handle(V3d_View) theView,
-                                              double& theX, double& theY)
+void PartSet_FeatureArcPrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch,
+                                                  gp_Pnt& thePoint, Handle(V3d_View) theView,
+                                                  double& theX, double& theY)
 {
-  FeaturePtr aSketch = sketch();
+  FeaturePtr aSketch = theSketch;
   if (aSketch) {
     double aX, anY;
     PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY);
 
     // circle origin point and radius
-    boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+    boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
     boost::shared_ptr<GeomDataAPI_Point2D> aCenter = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
                                                               (aData->attribute(ARC_ATTR_CENTER));
     boost::shared_ptr<GeomDataAPI_Point2D> aStart = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
index 80d07e014d1c1c2a3d3b6df87ff771c2ace62bb6..b06e0882bb080e0c232b2280f537d90f6719dfab 100644 (file)
@@ -51,8 +51,15 @@ public:
   /// \return next attribute selection mode
   virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
 
-  void projectPointOnArc(gp_Pnt& thePoint, Handle_V3d_View theView,
-                         double& theX, double& theY);
+  /// Project the view point on the feature. The output coordinates belong to the feature
+  /// \param theFeature a feature
+  /// \param theSketch the sketch feature
+  /// \param thePoint a viewer point
+  /// \param theView the OCC view
+  /// \theX the output horizontal coordinate of a projected point
+  /// \theY the output vertical coordinate of a projected point
+  static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint,
+                                    Handle_V3d_View theView, double& theX, double& theY);
 
   /// \brief Move the full feature.
   /// \param theDeltaX the delta for X coordinate is moved
index 71bd9721cd1249925c4b50cd036a7ac311b2f194..70f957134c2d08e7cb86ec8260c9c2615fa7eb1b 100644 (file)
 #include <SketchPlugin_Circle.h>
 
 #include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
 #include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Circ2d.h>
+#include <GeomAPI_Dir2d.h>
+#include <GeomAPI_Dir.h>
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefList.h>
 
+#include <V3d_View.hxx>
 #include <Precision.hxx>
 
 using namespace std;
@@ -129,6 +134,33 @@ boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::findPoint(Featu
   return aPoint2D;
 }
 
+void PartSet_FeatureCirclePrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch,
+                                                     gp_Pnt& thePoint, Handle(V3d_View) theView,
+                                                     double& theX, double& theY)
+{
+  FeaturePtr aSketch = theSketch;
+  if (aSketch) {
+    double aX, anY;
+    PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY);
+
+    // circle origin point and radius
+    boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+    boost::shared_ptr<GeomDataAPI_Point2D> aCenter = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                              (aData->attribute(CIRCLE_ATTR_CENTER));
+    bool isValid;
+    double aRadius = PartSet_Tools::featureValue(theFeature, CIRCLE_ATTR_RADIUS, isValid);
+
+    boost::shared_ptr<GeomAPI_Dir2d> aNormal(new GeomAPI_Dir2d(aX, anY));
+    boost::shared_ptr<GeomAPI_Circ2d> aCirc(new GeomAPI_Circ2d(aCenter->pnt(), aNormal, aRadius));
+    boost::shared_ptr<GeomAPI_Pnt2d> aGeomPoint2d(new GeomAPI_Pnt2d(aX, anY));
+    boost::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aCirc->project(aGeomPoint2d);
+    if (aPnt2d) {
+      theX = aPnt2d->x();
+      theY = aPnt2d->y();
+    }
+  }
+}
+
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::featurePoint
                                                      (const PartSet_SelectionMode& theMode)
 {
index 72a3d48553c3870a1b191053b54d39e3c0b493c6..c3ec1c6673609c0ec5c858cab79586ad73706f12 100644 (file)
 #include "PartSet_FeaturePrs.h"
 #include "PartSet_Constants.h"
 
+#include <gp_Pnt.hxx>
+
 class GeomDataAPI_Point2D;
+class Handle_V3d_View;
 
 /*!
  \class PartSet_FeatureCirclePrs
@@ -65,6 +68,16 @@ public:
   /// \param theY the vertical point coordinate
   virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
                                                            double theY);
+  /// Project the view point on the feature. The output coordinates belong to the feature
+  /// \param theFeature a feature
+  /// \param theSketch the sketch feature
+  /// \param thePoint a viewer point
+  /// \param theView the OCC view
+  /// \theX the output horizontal coordinate of a projected point
+  /// \theY the output vertical coordinate of a projected point
+  static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint,
+                                    Handle_V3d_View theView, double& theX, double& theY);
+
 protected:
   /// Returns the feature point in the selection mode position.
   /// \param theMode the current operation selection mode. The feature attribute depends on the mode
index 20558f3cbe03b04723886a727847857efdae9964..576cf40098248ca91c21d8918177375d54d62600 100644 (file)
@@ -127,8 +127,9 @@ void PartSet_OperationCreateConstraint::mouseReleased(QMouseEvent* theEvent, Han
 
       PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
       // show value edit dialog
-      double aValue;
-      if (PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, aValue)) {
+      bool isValid;
+      double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid);
+      if (isValid) {
         showEditor(theEvent, aValue);
         setPointSelectionMode(SM_ThirdPoint/*aMode*/);
       }
@@ -151,15 +152,13 @@ void PartSet_OperationCreateConstraint::mouseMoved(QMouseEvent* theEvent, Handle
       double aX, anY;
       gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
       PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
-      /*if (myPointSelectionMode == SM_ThirdPoint) {
-        if (feature()->getKind() == SKETCH_ARC_KIND) {
-          boost::shared_ptr<PartSet_FeatureArcPrs> anArcPrs =
-                                 boost::dynamic_pointer_cast<PartSet_FeatureArcPrs>(myFeaturePrs);
-          if (anArcPrs) {
-            anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
-          }
+      if (feature()->getKind() == PartSet_ConstraintRadiusPrs::getKind()) {
+        boost::shared_ptr<PartSet_ConstraintRadiusPrs> anArcPrs =
+                                boost::dynamic_pointer_cast<PartSet_ConstraintRadiusPrs>(myFeaturePrs);
+        if (anArcPrs) {
+          anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY);
         }
-      }*/
+      }
       myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
 
       flushUpdated();
index 23c746219a6e55dde46c4ff17f800575fff0c728..da80e62b294c763fa2187736701925d05d5ea390 100644 (file)
@@ -145,7 +145,7 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
         boost::shared_ptr<PartSet_FeatureArcPrs> anArcPrs =
                                  boost::dynamic_pointer_cast<PartSet_FeatureArcPrs>(myFeaturePrs);
         if (anArcPrs) {
-          anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
+          anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY);
         }
       }
       PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
@@ -174,7 +174,7 @@ void PartSet_OperationCreateFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3
           boost::shared_ptr<PartSet_FeatureArcPrs> anArcPrs =
                                  boost::dynamic_pointer_cast<PartSet_FeatureArcPrs>(myFeaturePrs);
           if (anArcPrs) {
-            anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
+            anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY);
           }
         }
       }
index 97057d76406fdb9d836a62fd4c9150ca776c5cfe..0fb85e9866328e813e99686279eb2d29ef7e03ba 100644 (file)
@@ -188,9 +188,9 @@ void PartSet_OperationEditConstraint::mouseDoubleClick(QMouseEvent* theEvent, Ha
 {
   // changed
   if (!theSelected.empty()) {
-
-    double aValue;
-    if(PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, aValue)) {
+    bool isValid;
+    double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid);
+    if (isValid) {
       QPoint aPos = theEvent->globalPos();
       myEditor->start(aPos, aValue);
     }
index 30bdc0b131d3eaa76565709bbf04c106a6bff545..45b994e524126691a086cd1816b4c9d6b57ac00f 100644 (file)
@@ -11,6 +11,9 @@
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Dir.h>
 #include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Pnt.h>
 
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_XYZ.h>
@@ -252,20 +255,21 @@ void PartSet_Tools::setFeatureValue(FeaturePtr theFeature, double theValue,
     anAttribute->setValue(theValue);
 }
 
-bool PartSet_Tools::featureValue(FeaturePtr theFeature, const std::string& theAttribute,
-                                 double& theValue)
+double PartSet_Tools::featureValue(FeaturePtr theFeature, const std::string& theAttribute,
+                                   bool& isValid)
 {
-  bool aResult = false;
-  if (!theFeature)
-    return aResult;
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  AttributeDoublePtr anAttribute =
-        boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(theAttribute));
-  if (anAttribute) {
-    theValue = anAttribute->value();
-    aResult = true;
+  isValid = false;
+  double aValue;
+  if (theFeature) {
+    boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+    AttributeDoublePtr anAttribute =
+          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(theAttribute));
+    if (anAttribute) {
+      aValue = anAttribute->value();
+      isValid = true;
+    }
   }
-  return aResult;
+  return aValue;
 }
 
 void PartSet_Tools::createConstraint(FeaturePtr theSketch,
@@ -307,3 +311,40 @@ boost::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findPoint(FeaturePtr theFe
 
   return aPoint2D;
 }
+
+boost::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(FeaturePtr theSketch)
+{
+  boost::shared_ptr<GeomAPI_Pln> aPlane;
+  double aA, aB, aC, aD;
+
+  boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+  boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+  aA = aNormal->x();
+  aB = aNormal->y();
+  aC = aNormal->z();
+  aD = 0;
+
+  aPlane = boost::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+  return aPlane;
+}
+
+boost::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(
+                                                boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
+                                                FeaturePtr theSketch)
+{
+  boost::shared_ptr<GeomAPI_Pnt> aPoint;
+  if (!theSketch || !thePoint2D)
+    return aPoint;
+
+  boost::shared_ptr<GeomDataAPI_Point> aC = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point>(theSketch->data()->attribute(SKETCH_ATTR_ORIGIN));
+  boost::shared_ptr<GeomDataAPI_Dir> aX = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theSketch->data()->attribute(SKETCH_ATTR_DIRX));
+  boost::shared_ptr<GeomDataAPI_Dir> aY = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theSketch->data()->attribute(SKETCH_ATTR_DIRY));
+
+  return thePoint2D->to3D(aC->pnt(), aX->dir(), aY->dir());
+}
index 0ddb45e7f7e339d4a917c3da406d193b82eef5c6..d43feb7bfc329a18620783226076a6bc78336fcd 100644 (file)
@@ -20,6 +20,9 @@
 class Handle_V3d_View;
 class XGUI_ViewerPrs;
 class GeomDataAPI_Point2D;
+class GeomAPI_Pln;
+class GeomAPI_Pnt2d;
+class GeomAPI_Pnt;
 class PartSet_FeaturePrs;
 
 /*!
@@ -92,10 +95,10 @@ public:
   /// \brief Returns the feature double value if it is.
   /// \param theFeature the feature
   /// \param theAttribute the feature attribute
-  /// \param theValue the horizontal coordinate
-  /// \returns the state whether the value is correct
-  static bool featureValue(FeaturePtr theFeature, const std::string& theAttribute,
-                           double& theValue);
+  /// \param isValid an output parameter whether the value is valid
+  /// \returns the feature value
+  static double featureValue(FeaturePtr theFeature, const std::string& theAttribute,
+                             bool& isValid);
 
   /// Creates a constraint on two points
   /// \param thePoint1 the first point
@@ -111,6 +114,17 @@ public:
   static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
                                                           double theY);
 
+  /// Create a sketch plane instance
+  /// \param theSketch a sketch feature
+  /// \return API object of geom plane
+  static boost::shared_ptr<GeomAPI_Pln> sketchPlane(FeaturePtr theSketch);
+
+  /// Create a point 3D on a basis of point 2D and sketch feature
+  /// \param thePoint2D a point on a sketch
+  /// \param theSketch a sketch feature
+  /// \return API object of point 3D
+  static boost::shared_ptr<GeomAPI_Pnt> point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
+                                                FeaturePtr theSketch);
 private:
   /// Return the distance between the feature and the point
   /// \param theFeature feature object