From: azv Date: Wed, 14 May 2014 05:56:57 +0000 (+0400) Subject: Implemented methods to transform entities and parameters from SketchPlugin to SolveSp... X-Git-Tag: V_0.2~64^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b2e18d7720b9ad1381975d83d83597517f938d10;p=modules%2Fshaper.git Implemented methods to transform entities and parameters from SketchPlugin to SolveSpace format --- diff --git a/src/SketchSolver/CMakeLists.txt b/src/SketchSolver/CMakeLists.txt index 974e46481..70b9fecbb 100644 --- a/src/SketchSolver/CMakeLists.txt +++ b/src/SketchSolver/CMakeLists.txt @@ -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 ) diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index 3251a2af3..a95f3c17f 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -5,6 +5,9 @@ #include "SketchSolver_ConstraintManager.h" #include +#include +#include +#include #include #include #include @@ -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 theEntity) { - /// \todo Should be implemented + // Look over supported types of entities + + // Point in 3D + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(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 aPoint2D = + boost::dynamic_pointer_cast(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 theDirX, + boost::shared_ptr theDirY) +{ + boost::shared_ptr aDirX = boost::dynamic_pointer_cast(theDirX); + boost::shared_ptr aDirY = boost::dynamic_pointer_cast(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 theParams) + boost::shared_ptr theSketch) { - /// \todo Should be implemented - return false; + if (myWorkplane.h) + return false; // the workplane already exists + + // Get parameters of workplane + boost::shared_ptr aDirX = theSketch->data()->attribute(SKETCH_ATTR_DIRX); + boost::shared_ptr aDirY = theSketch->data()->attribute(SKETCH_ATTR_DIRY); + boost::shared_ptr 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( diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.h b/src/SketchSolver/SketchSolver_ConstraintManager.h index 07699e723..80843c6b8 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.h +++ b/src/SketchSolver/SketchSolver_ConstraintManager.h @@ -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 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 theDirX, + boost::shared_ptr 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