GeomAlgoAPI.h
GeomAlgoAPI_CompoundBuilder.h
GeomAlgoAPI_FaceBuilder.h
+ GeomAlgoAPI_EdgeBuilder.h
)
SET(PROJECT_SOURCES
GeomAlgoAPI_CompoundBuilder.cpp
GeomAlgoAPI_FaceBuilder.cpp
+ GeomAlgoAPI_EdgeBuilder.cpp
)
ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
--- /dev/null
+// File: GeomAlgoAPI_EdgeBuilder.cpp
+// Created: 23 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <gp_Pln.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+#include <Geom_Plane.hxx>
+
+boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::line(
+ boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd)
+{
+ const gp_Pnt& aStart = theStart->impl<gp_Pnt>();
+ const gp_Pnt& anEnd = theEnd->impl<gp_Pnt>();
+
+ BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
+ boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+ TopoDS_Edge anEdge = anEdgeBuilder.Edge();
+ aRes->setImpl(new TopoDS_Shape(anEdge));
+ return aRes;
+}
--- /dev/null
+// File: GeomAlgoAPI_EdgeBuilder.h
+// Created: 23 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomAlgoAPI_EdgeBuilder_HeaderFile
+#define GeomAlgoAPI_EdgeBuilder_HeaderFile
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_Pnt.h>
+#include <boost/shared_ptr.hpp>
+
+/**\class GeomAlgoAPI_EdgeBuilder
+ * \ingroup DataAlgo
+ * \brief Allows to create face-shapes by different parameters
+ */
+
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder
+{
+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);
+};
+
+#endif
SET(PROJECT_HEADERS
GeomData.h
GeomData_Point.h
+ GeomData_Dir.h
+ GeomData_Point2D.h
)
SET(PROJECT_SOURCES
GeomData_Point.cpp
+ GeomData_Dir.cpp
+ GeomData_Point2D.cpp
)
ADD_DEFINITIONS(-DGEOMDATA_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
ADD_LIBRARY(GeomData SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-TARGET_LINK_LIBRARIES(GeomData ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Events Config)
+TARGET_LINK_LIBRARIES(GeomData ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI)
INCLUDE_DIRECTORIES(
../ModelAPI
--- /dev/null
+// File: GeomData_Dir.cxx
+// Created: 2 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#include "GeomData_Dir.h"
+
+using namespace std;
+
+void GeomData_Dir::setValue(const double theX, const double theY, const double theZ)
+{
+ myCoords->SetValue(0, theX);
+ myCoords->SetValue(1, theY);
+ myCoords->SetValue(2, theZ);
+}
+
+double GeomData_Dir::x() const
+{
+ return myCoords->Value(0);
+}
+
+double GeomData_Dir::y() const
+{
+ return myCoords->Value(1);
+}
+
+double GeomData_Dir::z() const
+{
+ return myCoords->Value(2);
+}
+
+GeomData_Dir::GeomData_Dir(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
+ // create attribute: not initialized by value yet, just zero
+ myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
+ }
+}
--- /dev/null
+// File: GeomData_Dir.h
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomData_Dir_HeaderFile
+#define GeomData_Dir_HeaderFile
+
+#include "GeomData.h"
+#include "GeomDataAPI_Dir.h"
+#include <TDataStd_RealArray.hxx>
+#include <TDF_Label.hxx>
+
+/**\class GeomData_Dir
+ * \ingroup DataModel
+ * \brief Attribute that contains direction.
+ */
+class GeomData_Dir : public GeomDataAPI_Dir
+{
+ Handle_TDataStd_RealArray myCoords; ///< X, Y and Z doubles as real array attribute [0; 2]
+public:
+ /// Defines the double value
+ GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY, const double theZ);
+
+ /// Returns the X double value
+ GEOMDATA_EXPORT virtual double x() const;
+ /// Returns the Y double value
+ GEOMDATA_EXPORT virtual double y() const;
+ /// Returns the Z double value
+ GEOMDATA_EXPORT virtual double z() const;
+
+protected:
+ /// Initializes attributes
+ GEOMDATA_EXPORT GeomData_Dir(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
-// File: ModelAPI_AttributeDouble.cxx
-// Created: 2 Apr 2014
+// File: GeomData_Point.cxx
+// Created: 24 Apr 2014
// Author: Mikhail PONIKAROV
#include "GeomData_Point.h"
/**\class GeomData_Point
* \ingroup DataModel
- * \brief Attribute that contains real value with double precision.
+ * \brief Attribute that contains 3D point.
*/
-class GeomData_Point : public ModelAPI_Attribute
+class GeomData_Point : public GeomDataAPI_Point
{
Handle_TDataStd_RealArray myCoords; ///< X, Y and Z doubles as real array attribute [0; 2]
public:
/// Defines the double value
- virtual void setValue(const double theX, const double theY, const double theZ);
+ GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY, const double theZ);
/// Returns the X double value
- virtual double x() const;
+ GEOMDATA_EXPORT virtual double x() const;
/// Returns the Y double value
- virtual double y() const;
+ GEOMDATA_EXPORT virtual double y() const;
/// Returns the Z double value
- virtual double z() const;
+ GEOMDATA_EXPORT virtual double z() const;
protected:
/// Initializes attributes
- GeomData_Point(TDF_Label& theLabel);
+ GEOMDATA_EXPORT GeomData_Point(TDF_Label& theLabel);
+
+ friend class Model_Data;
};
#endif
--- /dev/null
+// File: GeomData_Point2D.cxx
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#include "GeomData_Point2D.h"
+
+using namespace std;
+
+void GeomData_Point2D::setValue(const double theX, const double theY)
+{
+ myCoords->SetValue(0, theX);
+ myCoords->SetValue(1, theY);
+}
+
+double GeomData_Point2D::x() const
+{
+ return myCoords->Value(0);
+}
+
+double GeomData_Point2D::y() const
+{
+ return myCoords->Value(1);
+}
+
+GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
+ // create attribute: not initialized by value yet, just zero
+ myCoords = TDataStd_RealArray::Set(theLabel, 0, 1);
+ }
+}
--- /dev/null
+// File: GeomData_Point2D.h
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomData_Point2D_HeaderFile
+#define GeomData_Point2D_HeaderFile
+
+#include "GeomData.h"
+#include "GeomDataAPI_Point2D.h"
+#include <TDataStd_RealArray.hxx>
+#include <TDF_Label.hxx>
+
+/**\class GeomData_Point2D
+ * \ingroup DataModel
+ * \brief Attribute that contains 2D point.
+ */
+
+class GeomData_Point2D : public GeomDataAPI_Point2D
+{
+ Handle_TDataStd_RealArray myCoords; ///< X and Y doubles as real array attribute [0; 1]
+public:
+ /// Defines the double value
+ GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY);
+
+ /// Returns the X double value
+ GEOMDATA_EXPORT virtual double x() const;
+ /// Returns the Y double value
+ GEOMDATA_EXPORT virtual double y() const;
+
+protected:
+ /// Initializes attributes
+ GEOMDATA_EXPORT GeomData_Point2D(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
SET(PROJECT_HEADERS
GeomDataAPI.h
GeomDataAPI_Point.h
+ GeomDataAPI_Dir.h
+ GeomDataAPI_Point2D.h
)
SET(CMAKE_SWIG_FLAGS "")
%{
#include "GeomDataAPI.h"
#include "GeomDataAPI_Point.h"
+ #include "GeomDataAPI_Dir.h"
+ #include "GeomDataAPI_Point2D.h"
#include <boost/shared_ptr.hpp>
%}
// boost pointers
%include <boost_shared_ptr.i>
%shared_ptr(GeomDataAPI_Point)
+%shared_ptr(GeomDataAPI_Dir)
+%shared_ptr(GeomDataAPI_Point2D)
// all supported interfaces
%include "GeomDataAPI_Point.h"
+%include "GeomDataAPI_Dir.h"
+%include "GeomDataAPI_Point2D.h"
--- /dev/null
+// File: GeomDataAPI_Dir.h
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomDataAPI_Dir_HeaderFile
+#define GeomDataAPI_Dir_HeaderFile
+
+#include "GeomDataAPI.h"
+#include <ModelAPI_Attribute.h>
+
+/**\class GeomDataAPI_Dir
+ * \ingroup DataModel
+ * \brief Attribute that contains 3D direction coordinates.
+ */
+
+class GeomDataAPI_Dir : public ModelAPI_Attribute
+{
+public:
+ /// Defines the double value
+ virtual void setValue(const double theX, const double theY, const double theZ) = 0;
+
+ /// Returns the X double value
+ virtual double x() const = 0;
+ /// Returns the Y double value
+ virtual double y() const = 0;
+ /// Returns the Z double value
+ virtual double z() const = 0;
+
+ /// Returns the type of this class of attributes
+ static inline std::string type() {return std::string("Point");}
+
+ /// Returns the type of this class of attributes, not static method
+ virtual std::string attributeType() {return type();}
+
+protected:
+ /// Objects are created for features automatically
+ GeomDataAPI_Dir()
+ {}
+};
+
+#endif
-// File: GeomData_AttributeDouble.h
-// Created: 2 Apr 2014
+// File: GeomDataAPI_Point.h
+// Created: 24 Apr 2014
// Author: Mikhail PONIKAROV
-#ifndef GeomData_AttributeDouble_HeaderFile
-#define GeomData_AttributeDouble_HeaderFile
+#ifndef GeomDataAPI_Point_HeaderFile
+#define GeomDataAPI_Point_HeaderFile
#include "GeomDataAPI.h"
#include <ModelAPI_Attribute.h>
-/**\class GeomData_AttributeDouble
+/**\class GeomDataAPI_Point
* \ingroup DataModel
- * \brief Attribute that contains real value with double precision.
+ * \brief Attribute that contains 3D point coordinates.
*/
class GeomDataAPI_Point : public ModelAPI_Attribute
virtual void setValue(const double theX, const double theY, const double theZ) = 0;
/// Returns the X double value
- virtual double x() = 0;
+ virtual double x() const = 0;
/// Returns the Y double value
- virtual double y() = 0;
+ virtual double y() const = 0;
/// Returns the Z double value
- virtual double z() = 0;
+ virtual double z() const = 0;
/// Returns the type of this class of attributes
static inline std::string type() {return std::string("Point");}
--- /dev/null
+// File: GeomDataAPI_Point2D.h
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomDataAPI_Point2D_HeaderFile
+#define GeomDataAPI_Point2D_HeaderFile
+
+#include "GeomDataAPI.h"
+#include <ModelAPI_Attribute.h>
+
+/**\class GeomDataAPI_Point2D
+ * \ingroup DataModel
+ * \brief Attribute that contains 2D point coordinates.
+ */
+
+class GeomDataAPI_Point2D : public ModelAPI_Attribute
+{
+public:
+ /// Defines the double value
+ virtual void setValue(const double theX, const double theY) = 0;
+
+ /// Returns the X double value
+ virtual double x() const = 0;
+ /// Returns the Y double value
+ virtual double y() const = 0;
+
+ /// Returns the type of this class of attributes
+ static inline std::string type() {return std::string("Point2D");}
+
+ /// Returns the type of this class of attributes, not static method
+ virtual std::string attributeType() {return type();}
+
+protected:
+ /// Objects are created for features automatically
+ GeomDataAPI_Point2D()
+ {}
+};
+
+#endif
ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Events Config)
+TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Events Config GeomData)
INCLUDE_DIRECTORIES(
../ModelAPI
../Events
../Config
+ ../GeomData
+ ../GeomDataAPI
${CAS_INCLUDE_DIRS}
)
#include <Model_Data.h>
#include <Model_AttributeDocRef.h>
#include <Model_AttributeDouble.h>
+#include <GeomData_Point.h>
+#include <GeomData_Point2D.h>
#include <TDataStd_Name.hxx>
using namespace std;
anAttr = new Model_AttributeDocRef(anAttrLab);
else if (theAttrType == ModelAPI_AttributeDouble::type())
anAttr = new Model_AttributeDouble(anAttrLab);
+ else if (theAttrType == GeomData_Point::type())
+ anAttr = new GeomData_Point(anAttrLab);
+ else if (theAttrType == GeomData_Point2D::type())
+ anAttr = new GeomData_Point2D(anAttrLab);
if (anAttr)
myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
}
return aRes;
}
+
+boost::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string theID)
+{
+ boost::shared_ptr<ModelAPI_Attribute> aResult;
+ if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
+ return aResult;
+ return myAttrs[theID];
+}
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string theID);
/// Returns the attribute that contains real value with double precision
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string theID);
+ /// Returns the generic attribute by identifier
+ /// \param theID identifier of the attribute
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID);
/// Initializes object by the attributes: must be called just after the object is created
/// for each attribute of the object
* \ingroup DataModel
* \brief Generic attribute of the Object.
*/
-
class MODELAPI_EXPORT ModelAPI_Attribute
{
public:
class ModelAPI_AttributeDocRef;
class ModelAPI_AttributeDouble;
class ModelAPI_Document;
+class ModelAPI_Attribute;
/**\class ModelAPI_Data
* \ingroup DataModel
/// Returns the attribute that contains real value with double precision
virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string theID) = 0;
+ /// Returns the generic attribute by identifier
+ /// \param theID identifier of the attribute
+ virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID) = 0;
+
/// Initializes object by the attributes: must be called just after the object is created
/// for each attribute of the object
/// \param theID identifier of the attribute that can be referenced by this ID later
${CMAKE_SOURCE_DIR}/src/Events
${CMAKE_SOURCE_DIR}/src/ModuleBase
${CMAKE_SOURCE_DIR}/src/ModelAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomDataAPI
${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
${CMAKE_SOURCE_DIR}/src/SketchPlugin
${CMAKE_SOURCE_DIR}/src/GeomAPI
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDouble.h>
#include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
#include <AIS_Shape.hxx>
#include <AIS_ListOfInteractive.hxx>
aPlane->coefficients(anA, aB, aC, aD);
boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
-
+ /*
aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
+ */
+ // temporary solution for main planes only
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ anOrigin->setValue(0, 0, 0);
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ aNormal->setValue(anA, aB, aC);
+ boost::shared_ptr<GeomDataAPI_Dir> aDirX =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+ aDirX->setValue(aB, aC, anA);
+ boost::shared_ptr<GeomDataAPI_Dir> aDirY =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+ aDirY->setValue(aC, anA, aB);
boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
emit viewerProjectionChange(aDir->x(), aDir->y(), aDir->z());
SketchPlugin_Feature.h
SketchPlugin_Plugin.h
SketchPlugin_Sketch.h
+ SketchPlugin_Line.h
)
SET(PROJECT_SOURCES
SketchPlugin_Feature.cpp
SketchPlugin_Plugin.cpp
SketchPlugin_Sketch.cpp
+ SketchPlugin_Line.cpp
)
SET(PROJECT_LIBRARIES
../ModelAPI
../GeomAPI
../GeomAlgoAPI
+ ../GeomDataAPI
)
SET(XML_RESOURCES
#include "SketchPlugin.h"
#include <ModelAPI_Feature.h>
-
#include <GeomAPI_Shape.h>
+class SketchPlugin_Sketch;
+
/**\class SketchPlugin_Feature
* \ingroup DataModel
* \brief Feature for creation of the new feature in PartSet. This is an abstract class to give
{
public:
/// Returns the sketch preview
+ /// \param theSketch the owner of this feature
/// \return the built preview
SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview() = 0;
--- /dev/null
+// File: SketchPlugin_Line.cxx
+// Created: 27 Mar 2014
+// Author: Mikhail PONIKAROV
+
+#include "SketchPlugin_Line.h"
+#include "SketchPlugin_Sketch.h"
+#include <ModelAPI_Data.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomDataAPI_Point2D.h>
+
+using namespace std;
+
+// face of the square-face displayed for selection of general plane
+const double PLANE_SIZE = 200;
+
+SketchPlugin_Line::SketchPlugin_Line()
+{
+}
+
+void SketchPlugin_Line::initAttributes()
+{
+ data()->addAttribute(LINE_ATTR_START, GeomDataAPI_Point2D::type());
+ data()->addAttribute(LINE_ATTR_END, GeomDataAPI_Point2D::type());
+}
+
+void SketchPlugin_Line::execute()
+{
+}
+
+const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Line::preview()
+{
+ boost::shared_ptr<SketchPlugin_Sketch> aSketch = SketchPlugin_Sketch::active();
+ // compute a start point in 3D view
+ boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_START));
+ boost::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+ // compute an end point in 3D view
+ boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_END));
+ boost::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
+ // make linear edge
+ boost::shared_ptr<GeomAPI_Shape> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+ setPreview(anEdge);
+
+ return getPreview();
+}
--- /dev/null
+// File: SketchPlugin_Line.h
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef SketchPlugin_Line_HeaderFile
+#define SketchPlugin_Line_HeaderFile
+
+#include "SketchPlugin.h"
+#include <SketchPlugin_Feature.h>
+#include <list>
+
+/// Start 2D point of the line
+const std::string LINE_ATTR_START("StartPoint");
+/// End 2D point of the line
+const std::string LINE_ATTR_END("EndPoint");
+
+/**\class SketchPlugin_Line
+ * \ingroup DataModel
+ * \brief Feature for creation of the new part in PartSet.
+ */
+class SketchPlugin_Line: public SketchPlugin_Feature
+{
+public:
+ /// Returns the kind of a feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+ {static std::string MY_KIND = "SketchLine"; return MY_KIND;}
+
+ /// Returns to which group in the document must be added feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
+ {static std::string MY_GROUP = "Sketch"; return MY_GROUP;}
+
+ /// Creates a new part document if needed
+ SKETCHPLUGIN_EXPORT virtual void execute();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Returns the sketch preview
+ SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+
+ /// Use plugin manager for features creation
+ SketchPlugin_Line();
+};
+
+#endif
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeDouble.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
using namespace std;
+/// the active sketch
+boost::shared_ptr<SketchPlugin_Sketch> MY_ACITVE_SKETCH;
+
// face of the square-face displayed for selection of general plane
const double PLANE_SIZE = 200;
void SketchPlugin_Sketch::initAttributes()
{
- data()->addAttribute(SKETCH_ATTR_PLANE_A, ModelAPI_AttributeDouble::type());
- data()->addAttribute(SKETCH_ATTR_PLANE_B, ModelAPI_AttributeDouble::type());
- data()->addAttribute(SKETCH_ATTR_PLANE_C, ModelAPI_AttributeDouble::type());
- data()->addAttribute(SKETCH_ATTR_PLANE_D, ModelAPI_AttributeDouble::type());
+ data()->addAttribute(SKETCH_ATTR_ORIGIN, GeomDataAPI_Point::type());
+ data()->addAttribute(SKETCH_ATTR_DIRX, GeomDataAPI_Dir::type());
+ data()->addAttribute(SKETCH_ATTR_DIRY, GeomDataAPI_Dir::type());
+ data()->addAttribute(SKETCH_ATTR_NORM, GeomDataAPI_Dir::type());
}
void SketchPlugin_Sketch::execute()
return getPreview();
}
+void SketchPlugin_Sketch::setActive(boost::shared_ptr<SketchPlugin_Sketch> theSketch)
+{
+ MY_ACITVE_SKETCH = theSketch;
+}
+
+boost::shared_ptr<SketchPlugin_Sketch> SketchPlugin_Sketch::active()
+{
+ return MY_ACITVE_SKETCH;
+}
+
void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ,
std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const
{
GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
theShapes.push_back(aFace);
}
+
+boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
+{
+ boost::shared_ptr<GeomDataAPI_Point> aC =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SKETCH_ATTR_ORIGIN));
+ boost::shared_ptr<GeomDataAPI_Dir> aX =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_DIRX));
+ boost::shared_ptr<GeomDataAPI_Dir> aY =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_DIRY));
+
+ return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(
+ aC->x() + aX->x() * theX + aY->x() * theY,
+ aC->y() + aX->y() * theX + aY->y() * theY,
+ aC->z() + aX->z() * theX + aY->z() * theY));
+}
#include "SketchPlugin.h"
#include <SketchPlugin_Feature.h>
+#include <GeomAPI_Pnt.h>
#include <list>
-/// Coefficient A of the sketch plane (Ax+By+Cz+D=0)
-const std::string SKETCH_ATTR_PLANE_A("PlaneA");
-/// Coefficient B of the sketch plane
-const std::string SKETCH_ATTR_PLANE_B("PlaneB");
-/// Coefficient C of the sketch plane
-const std::string SKETCH_ATTR_PLANE_C("PlaneC");
-/// Coefficient D of the sketch plane
-const std::string SKETCH_ATTR_PLANE_D("PlaneD");
+/// Origin point of the sketcher in 3D space
+const std::string SKETCH_ATTR_ORIGIN("Origin");
+/// Vector X inside of the sketch plane
+const std::string SKETCH_ATTR_DIRX("DirX");
+/// Vector Y inside of the sketch plane
+const std::string SKETCH_ATTR_DIRY("DirY");
+/// Vector Z, normal to the sketch plane
+const std::string SKETCH_ATTR_NORM("Norm");
/**\class SketchPlugin_Sketch
* \ingroup DataModel
/// Returns the sketch preview
SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+ /// Sets the sketch as active. All features and features previews
+ /// will be connected to this sketch.
+ SKETCHPLUGIN_EXPORT static void setActive(boost::shared_ptr<SketchPlugin_Sketch> theSketch);
+
+ /// Returns the currently active sketch. All features and features previews
+ /// will be connected to this sketch.
+ SKETCHPLUGIN_EXPORT static boost::shared_ptr<SketchPlugin_Sketch> active();
+
+ /// Converts a 2D sketch space point into point in 3D space
+ SKETCHPLUGIN_EXPORT boost::shared_ptr<GeomAPI_Pnt> to3D(
+ const double theX, const double theY);
+
/// Use plugin manager for features creation
SketchPlugin_Sketch();
protected: