]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implemented methods to transform entities and parameters from SketchPlugin to SolveSp...
authorazv <azv@opencascade.com>
Wed, 14 May 2014 05:56:57 +0000 (09:56 +0400)
committerazv <azv@opencascade.com>
Wed, 14 May 2014 05:56:57 +0000 (09:56 +0400)
src/SketchSolver/CMakeLists.txt
src/SketchSolver/SketchSolver_ConstraintManager.cpp
src/SketchSolver/SketchSolver_ConstraintManager.h

index 974e464819a2126a323b0db13ade27b83774edc7..70b9fecbbc4b97fcc43737dfc9d4febd20c76781 100644 (file)
@@ -23,6 +23,7 @@ INCLUDE_DIRECTORIES(
     ${PROJECT_SOURCE_DIR}/src/ModelAPI
     ${PROJECT_SOURCE_DIR}/src/Model
     ${PROJECT_SOURCE_DIR}/src/GeomAPI
+    ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
     ${PROJECT_SOURCE_DIR}/src/Events
 )
 
index 3251a2af311ddcf76701a7c2f3d774691323220f..a95f3c17fafe75c3c74474b7ab2060815fcb6a52 100644 (file)
@@ -5,6 +5,9 @@
 #include "SketchSolver_ConstraintManager.h"
 
 #include <Events_Loop.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Point2D.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
 #include <Model_Events.h>
@@ -152,7 +155,7 @@ SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::
   myConstrSet.failed = 0;
 
   // Initialize workplane
-  mySketch = theWorkplane;
+  myWorkplane.h = 0;
   addWorkplane(theWorkplane);
 }
 
@@ -237,15 +240,93 @@ bool SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::addConstraint
 Slvs_hEntity SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::addEntity(
                 boost::shared_ptr<ModelAPI_Attribute> theEntity)
 {
-  /// \todo Should be implemented
+  // Look over supported types of entities
+
+  // Point in 3D
+  boost::shared_ptr<GeomDataAPI_Point> aPoint = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point>(theEntity);
+  if (aPoint)
+  {
+    Slvs_hParam aX = addParameter(aPoint->x());
+    Slvs_hParam aY = addParameter(aPoint->y());
+    Slvs_hParam aZ = addParameter(aPoint->z());
+    Slvs_Entity aPtEntity = Slvs_MakePoint3d(++myEntityMaxID, myID, aX, aY, aZ);
+    myEntities.push_back(aPtEntity);
+    return aPtEntity.h;
+  }
+
+  // Point in 2D
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theEntity);
+  if (aPoint2D)
+  {
+    // The 2D points are created on workplane. So, if there is no workplane yet, then error
+    if (myWorkplane.h == 0)
+      return 0;
+    Slvs_hParam aU = addParameter(aPoint2D->x());
+    Slvs_hParam aV = addParameter(aPoint2D->y());
+    Slvs_Entity aPt2DEntity = Slvs_MakePoint2d(++myEntityMaxID, myID, myWorkplane.h, aU, aV);
+    myEntities.push_back(aPt2DEntity);
+    return aPt2DEntity.h;
+  }
+
+  /// \todo Other types of entities
+  
+  // Unsupported or wrong entity type
   return 0;
 }
 
+Slvs_hEntity SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::addNormal(
+                boost::shared_ptr<ModelAPI_Attribute> theDirX, 
+                boost::shared_ptr<ModelAPI_Attribute> theDirY)
+{
+  boost::shared_ptr<GeomDataAPI_Dir> aDirX = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theDirX);
+  boost::shared_ptr<GeomDataAPI_Dir> aDirY = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theDirY);
+  if (!aDirX || !aDirY)
+    return 0;
+
+  // quaternion parameters of normal vector
+  double qw, qx, qy, qz;
+  Slvs_MakeQuaternion(aDirX->x(), aDirX->y(), aDirX->z(), 
+                      aDirY->x(), aDirY->y(), aDirY->z(), 
+                      &qw, &qx, &qy, &qz);
+
+  // Create a normal
+  Slvs_Entity aNormal = Slvs_MakeNormal3d(++myEntityMaxID, myID, 
+                      addParameter(qw), addParameter(qx), addParameter(qy), addParameter(qz));
+  myEntities.push_back(aNormal);
+  return aNormal.h;
+}
+
+
 bool SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::addWorkplane(
-                boost::shared_ptr<SketchPlugin_Sketch> theParams)
+                boost::shared_ptr<SketchPlugin_Sketch> theSketch)
 {
-  /// \todo Should be implemented
-  return false;
+  if (myWorkplane.h)
+    return false; // the workplane already exists
+
+  // Get parameters of workplane
+  boost::shared_ptr<ModelAPI_Attribute> aDirX    = theSketch->data()->attribute(SKETCH_ATTR_DIRX);
+  boost::shared_ptr<ModelAPI_Attribute> aDirY    = theSketch->data()->attribute(SKETCH_ATTR_DIRY);
+  boost::shared_ptr<ModelAPI_Attribute> anOrigin = theSketch->data()->attribute(SKETCH_ATTR_ORIGIN);
+  // Transform them into SolveSpace format
+  Slvs_hEntity aNormalWP = addNormal(aDirX, aDirY);
+  if (!aNormalWP) return false;
+  Slvs_hEntity anOriginWP = addEntity(anOrigin);
+  if (!anOriginWP) return false;
+  // Create workplane
+  myWorkplane = Slvs_MakeWorkplane(++myEntityMaxID, myID, anOriginWP, aNormalWP);
+  mySketch = theSketch;
+  // Workplane should be added to the list of entities
+  myEntities.push_back(myWorkplane);
+  return true;
+}
+
+Slvs_hParam SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::addParameter(double theParam)
+{
+  Slvs_Param aParam = Slvs_MakeParam(++myParamMaxID, myID, theParam);
+  myParams.push_back(aParam);
+  return aParam.h;
 }
 
 int SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::getConstraintType(
index 07699e72313d28a91f0921a88b8ca3e044d10108..80843c6b814002bb3eaee3f9a8d965f99f70a8ec 100644 (file)
@@ -154,11 +154,30 @@ public:
 
 protected:
   /** \brief Adds an entity into the group
+   *
+   *  The parameters of entity will be parsed and added to the list of SolveSpace parameters.
+   *  Parameters of certain entity will be placed sequentially in the list.
+   *
    *  \param[in] theEntity the object of constraint
    *  \return identifier of created entity or 0 if entity was not added
    */
   Slvs_hEntity addEntity(boost::shared_ptr<ModelAPI_Attribute> theEntity);
 
+  /** \brief Adds a normal into the group
+   *
+   *  Normal is a special entity in SolveSpace, which defines a direction in 3D and 
+   *  a rotation about this direction. So, SolveSpace represents normals as unit quaternions.
+   *
+   *  To define a normal there should be specified two coordinate axis 
+   *  on the plane transversed to created normal.
+   *
+   *  \param[in] theDirX first coordinate axis of the plane
+   *  \param[in] theDirY second coordinate axis of the plane
+   *  \return identifier of created normal
+   */
+  Slvs_hEntity addNormal(boost::shared_ptr<ModelAPI_Attribute> theDirX, 
+                         boost::shared_ptr<ModelAPI_Attribute> theDirY);
+
   /** \brief Adds a parameter into the group
    *  \param[in] theParam parameter to be added
    *  \return identifier of created parameter or 0 if it was not added