From: mpv Date: Fri, 25 Apr 2014 09:20:16 +0000 (+0400) Subject: Sketch line feature based on points attributes X-Git-Tag: V_0.2~118^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1a6a9c1c0c466abb867f2c2815b20aa0620a444c;p=modules%2Fshaper.git Sketch line feature based on points attributes --- diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index c05fa5a25..509c7fd9e 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -8,11 +8,13 @@ SET(PROJECT_HEADERS 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}) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp new file mode 100644 index 000000000..c8419fe37 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp @@ -0,0 +1,24 @@ +// File: GeomAlgoAPI_EdgeBuilder.cpp +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#include +#include +#include +#include +#include +#include +#include + +boost::shared_ptr GeomAlgoAPI_EdgeBuilder::line( + boost::shared_ptr theStart, boost::shared_ptr theEnd) +{ + const gp_Pnt& aStart = theStart->impl(); + const gp_Pnt& anEnd = theEnd->impl(); + + BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd); + boost::shared_ptr aRes(new GeomAPI_Shape); + TopoDS_Edge anEdge = anEdgeBuilder.Edge(); + aRes->setImpl(new TopoDS_Shape(anEdge)); + return aRes; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h new file mode 100644 index 000000000..cd505a861 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h @@ -0,0 +1,26 @@ +// File: GeomAlgoAPI_EdgeBuilder.h +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAlgoAPI_EdgeBuilder_HeaderFile +#define GeomAlgoAPI_EdgeBuilder_HeaderFile + +#include +#include +#include +#include + +/**\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 line( + boost::shared_ptr theStart, boost::shared_ptr theEnd); +}; + +#endif diff --git a/src/GeomData/CMakeLists.txt b/src/GeomData/CMakeLists.txt index 05ee5eb3c..39f76ff15 100644 --- a/src/GeomData/CMakeLists.txt +++ b/src/GeomData/CMakeLists.txt @@ -4,15 +4,19 @@ INCLUDE(FindCAS) 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 diff --git a/src/GeomData/GeomData_Dir.cpp b/src/GeomData/GeomData_Dir.cpp new file mode 100644 index 000000000..dc2ca123d --- /dev/null +++ b/src/GeomData/GeomData_Dir.cpp @@ -0,0 +1,38 @@ +// 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); + } +} diff --git a/src/GeomData/GeomData_Dir.h b/src/GeomData/GeomData_Dir.h new file mode 100644 index 000000000..554fd04c4 --- /dev/null +++ b/src/GeomData/GeomData_Dir.h @@ -0,0 +1,38 @@ +// 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 +#include + +/**\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 diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp index 9fbb5f424..6f57d4157 100644 --- a/src/GeomData/GeomData_Point.cpp +++ b/src/GeomData/GeomData_Point.cpp @@ -1,5 +1,5 @@ -// File: ModelAPI_AttributeDouble.cxx -// Created: 2 Apr 2014 +// File: GeomData_Point.cxx +// Created: 24 Apr 2014 // Author: Mikhail PONIKAROV #include "GeomData_Point.h" diff --git a/src/GeomData/GeomData_Point.h b/src/GeomData/GeomData_Point.h index 06f84959a..9886333c2 100644 --- a/src/GeomData/GeomData_Point.h +++ b/src/GeomData/GeomData_Point.h @@ -12,26 +12,28 @@ /**\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 diff --git a/src/GeomData/GeomData_Point2D.cpp b/src/GeomData/GeomData_Point2D.cpp new file mode 100644 index 000000000..3e576226b --- /dev/null +++ b/src/GeomData/GeomData_Point2D.cpp @@ -0,0 +1,32 @@ +// 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); + } +} diff --git a/src/GeomData/GeomData_Point2D.h b/src/GeomData/GeomData_Point2D.h new file mode 100644 index 000000000..4b3d4671c --- /dev/null +++ b/src/GeomData/GeomData_Point2D.h @@ -0,0 +1,37 @@ +// 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 +#include + +/**\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 diff --git a/src/GeomDataAPI/CMakeLists.txt b/src/GeomDataAPI/CMakeLists.txt index 9f09481b0..389463212 100644 --- a/src/GeomDataAPI/CMakeLists.txt +++ b/src/GeomDataAPI/CMakeLists.txt @@ -5,6 +5,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) SET(PROJECT_HEADERS GeomDataAPI.h GeomDataAPI_Point.h + GeomDataAPI_Dir.h + GeomDataAPI_Point2D.h ) SET(CMAKE_SWIG_FLAGS "") diff --git a/src/GeomDataAPI/GeomDataAPI.i b/src/GeomDataAPI/GeomDataAPI.i index f759848d9..455e0122e 100644 --- a/src/GeomDataAPI/GeomDataAPI.i +++ b/src/GeomDataAPI/GeomDataAPI.i @@ -3,6 +3,8 @@ %{ #include "GeomDataAPI.h" #include "GeomDataAPI_Point.h" + #include "GeomDataAPI_Dir.h" + #include "GeomDataAPI_Point2D.h" #include %} @@ -17,6 +19,10 @@ // boost pointers %include %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" diff --git a/src/GeomDataAPI/GeomDataAPI_Dir.h b/src/GeomDataAPI/GeomDataAPI_Dir.h new file mode 100644 index 000000000..90ab61614 --- /dev/null +++ b/src/GeomDataAPI/GeomDataAPI_Dir.h @@ -0,0 +1,41 @@ +// File: GeomDataAPI_Dir.h +// Created: 24 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomDataAPI_Dir_HeaderFile +#define GeomDataAPI_Dir_HeaderFile + +#include "GeomDataAPI.h" +#include + +/**\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 diff --git a/src/GeomDataAPI/GeomDataAPI_Point.h b/src/GeomDataAPI/GeomDataAPI_Point.h index d53271fd7..68f294e60 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point.h +++ b/src/GeomDataAPI/GeomDataAPI_Point.h @@ -1,16 +1,16 @@ -// 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 -/**\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 @@ -20,11 +20,11 @@ public: 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");} diff --git a/src/GeomDataAPI/GeomDataAPI_Point2D.h b/src/GeomDataAPI/GeomDataAPI_Point2D.h new file mode 100644 index 000000000..bfc8094c2 --- /dev/null +++ b/src/GeomDataAPI/GeomDataAPI_Point2D.h @@ -0,0 +1,39 @@ +// File: GeomDataAPI_Point2D.h +// Created: 24 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomDataAPI_Point2D_HeaderFile +#define GeomDataAPI_Point2D_HeaderFile + +#include "GeomDataAPI.h" +#include + +/**\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 diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 24bee85be..7b60ee48c 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -26,12 +26,14 @@ SET(PROJECT_SOURCES 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} ) diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 87c7be867..121cd1902 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include using namespace std; @@ -39,6 +41,10 @@ void Model_Data::addAttribute(string theID, string theAttrType) 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(anAttr); @@ -75,3 +81,11 @@ boost::shared_ptr Model_Data::real(const string theID) } return aRes; } + +boost::shared_ptr Model_Data::attribute(const std::string theID) +{ + boost::shared_ptr aResult; + if (myAttrs.find(theID) == myAttrs.end()) // no such attribute + return aResult; + return myAttrs[theID]; +} diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 5c3ffdf2f..647024e6d 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -43,6 +43,9 @@ public: MODEL_EXPORT virtual boost::shared_ptr docRef(const std::string theID); /// Returns the attribute that contains real value with double precision MODEL_EXPORT virtual boost::shared_ptr real(const std::string theID); + /// Returns the generic attribute by identifier + /// \param theID identifier of the attribute + MODEL_EXPORT virtual boost::shared_ptr 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 diff --git a/src/ModelAPI/ModelAPI_Attribute.h b/src/ModelAPI/ModelAPI_Attribute.h index 1d4bf15e8..dfcdae495 100644 --- a/src/ModelAPI/ModelAPI_Attribute.h +++ b/src/ModelAPI/ModelAPI_Attribute.h @@ -12,7 +12,6 @@ * \ingroup DataModel * \brief Generic attribute of the Object. */ - class MODELAPI_EXPORT ModelAPI_Attribute { public: diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index 73fe3d7de..077e75d27 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -12,6 +12,7 @@ class ModelAPI_AttributeDocRef; class ModelAPI_AttributeDouble; class ModelAPI_Document; +class ModelAPI_Attribute; /**\class ModelAPI_Data * \ingroup DataModel @@ -34,6 +35,10 @@ public: /// Returns the attribute that contains real value with double precision virtual boost::shared_ptr real(const std::string theID) = 0; + /// Returns the generic attribute by identifier + /// \param theID identifier of the attribute + virtual boost::shared_ptr 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 diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 45abe7d5b..f8ce75a92 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -47,6 +47,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI ${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 diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 8ce3b7958..c343503e2 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include @@ -57,11 +59,25 @@ void PartSet_OperationSketch::setSelectedShapes(const NCollection_Listcoefficients(anA, aB, aC, aD); boost::shared_ptr 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 anOrigin = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + anOrigin->setValue(0, 0, 0); + boost::shared_ptr aNormal = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + aNormal->setValue(anA, aB, aC); + boost::shared_ptr aDirX = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); + aDirX->setValue(aB, aC, anA); + boost::shared_ptr aDirY = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); + aDirY->setValue(aC, anA, aB); boost::shared_ptr aDir = aPlane->direction(); emit viewerProjectionChange(aDir->x(), aDir->y(), aDir->z()); diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index c075da118..347fabe88 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -5,12 +5,14 @@ SET(PROJECT_HEADERS 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 @@ -26,6 +28,7 @@ INCLUDE_DIRECTORIES( ../ModelAPI ../GeomAPI ../GeomAlgoAPI + ../GeomDataAPI ) SET(XML_RESOURCES diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 2bb33c268..26efd6e05 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -7,9 +7,10 @@ #include "SketchPlugin.h" #include - #include +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 @@ -19,6 +20,7 @@ class SketchPlugin_Feature: public ModelAPI_Feature { public: /// Returns the sketch preview + /// \param theSketch the owner of this feature /// \return the built preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview() = 0; diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp new file mode 100644 index 000000000..5b5cf5108 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -0,0 +1,47 @@ +// File: SketchPlugin_Line.cxx +// Created: 27 Mar 2014 +// Author: Mikhail PONIKAROV + +#include "SketchPlugin_Line.h" +#include "SketchPlugin_Sketch.h" +#include +#include +#include +#include + +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& SketchPlugin_Line::preview() +{ + boost::shared_ptr aSketch = SketchPlugin_Sketch::active(); + // compute a start point in 3D view + boost::shared_ptr aStartAttr = + boost::dynamic_pointer_cast(data()->attribute(LINE_ATTR_START)); + boost::shared_ptr aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); + // compute an end point in 3D view + boost::shared_ptr anEndAttr = + boost::dynamic_pointer_cast(data()->attribute(LINE_ATTR_END)); + boost::shared_ptr anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); + // make linear edge + boost::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); + setPreview(anEdge); + + return getPreview(); +} diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h new file mode 100644 index 000000000..9d0ae5092 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -0,0 +1,45 @@ +// File: SketchPlugin_Line.h +// Created: 24 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef SketchPlugin_Line_HeaderFile +#define SketchPlugin_Line_HeaderFile + +#include "SketchPlugin.h" +#include +#include + +/// 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& preview(); + + /// Use plugin manager for features creation + SketchPlugin_Line(); +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 878670ec2..83480d9a8 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -4,12 +4,16 @@ #include "SketchPlugin_Sketch.h" #include -#include +#include +#include #include #include using namespace std; +/// the active sketch +boost::shared_ptr MY_ACITVE_SKETCH; + // face of the square-face displayed for selection of general plane const double PLANE_SIZE = 200; @@ -19,10 +23,10 @@ SketchPlugin_Sketch::SketchPlugin_Sketch() 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() @@ -42,6 +46,16 @@ const boost::shared_ptr& SketchPlugin_Sketch::preview() return getPreview(); } +void SketchPlugin_Sketch::setActive(boost::shared_ptr theSketch) +{ + MY_ACITVE_SKETCH = theSketch; +} + +boost::shared_ptr SketchPlugin_Sketch::active() +{ + return MY_ACITVE_SKETCH; +} + void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ, std::list >& theShapes) const { @@ -51,3 +65,18 @@ void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ, GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE); theShapes.push_back(aFace); } + +boost::shared_ptr SketchPlugin_Sketch::to3D(const double theX, const double theY) +{ + boost::shared_ptr aC = + boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_ORIGIN)); + boost::shared_ptr aX = + boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_DIRX)); + boost::shared_ptr aY = + boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_DIRY)); + + return boost::shared_ptr(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)); +} diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index ec81fe62e..3c6181200 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -7,16 +7,17 @@ #include "SketchPlugin.h" #include +#include #include -/// 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 @@ -42,6 +43,18 @@ public: /// Returns the sketch preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& 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 theSketch); + + /// Returns the currently active sketch. All features and features previews + /// will be connected to this sketch. + SKETCHPLUGIN_EXPORT static boost::shared_ptr active(); + + /// Converts a 2D sketch space point into point in 3D space + SKETCHPLUGIN_EXPORT boost::shared_ptr to3D( + const double theX, const double theY); + /// Use plugin manager for features creation SketchPlugin_Sketch(); protected: