From f05a54dabb8f9aff6b52df72a88160a9be792aee Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 25 Apr 2014 15:18:07 +0400 Subject: [PATCH] Sub-features of sketcher support --- src/GeomAPI/GeomAPI_Dir.h | 1 + src/GeomData/CMakeLists.txt | 3 ++- src/GeomData/GeomData_Dir.cpp | 8 ++++++++ src/GeomData/GeomData_Dir.h | 5 +++++ src/SketchPlugin/SketchPlugin_Feature.h | 12 ++++++++++++ src/SketchPlugin/SketchPlugin_Line.cpp | 2 +- src/SketchPlugin/SketchPlugin_Sketch.cpp | 9 ++------- src/SketchPlugin/SketchPlugin_Sketch.h | 11 ++++------- 8 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/GeomAPI/GeomAPI_Dir.h b/src/GeomAPI/GeomAPI_Dir.h index a003d3826..7993a3d77 100644 --- a/src/GeomAPI/GeomAPI_Dir.h +++ b/src/GeomAPI/GeomAPI_Dir.h @@ -24,6 +24,7 @@ public: double y() const; /// returns Z coordinate double z() const; + }; #endif diff --git a/src/GeomData/CMakeLists.txt b/src/GeomData/CMakeLists.txt index 39f76ff15..de9142621 100644 --- a/src/GeomData/CMakeLists.txt +++ b/src/GeomData/CMakeLists.txt @@ -16,11 +16,12 @@ SET(PROJECT_SOURCES 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) +TARGET_LINK_LIBRARIES(GeomData ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI GeomAPI) INCLUDE_DIRECTORIES( ../ModelAPI ../GeomDataAPI + ../GeomAPI ../Events ../Config ${CAS_INCLUDE_DIRS} diff --git a/src/GeomData/GeomData_Dir.cpp b/src/GeomData/GeomData_Dir.cpp index dc2ca123d..22dac3fe4 100644 --- a/src/GeomData/GeomData_Dir.cpp +++ b/src/GeomData/GeomData_Dir.cpp @@ -3,6 +3,8 @@ // Author: Mikhail PONIKAROV #include "GeomData_Dir.h" +#include "GeomAPI_Dir.h" +#include using namespace std; @@ -28,6 +30,12 @@ double GeomData_Dir::z() const return myCoords->Value(2); } +boost::shared_ptr GeomData_Dir::dir() +{ + return boost::shared_ptr(new GeomAPI_Dir( + myCoords->Value(0), myCoords->Value(1), myCoords->Value(2))); +} + GeomData_Dir::GeomData_Dir(TDF_Label& theLabel) { // check the attribute could be already presented in this doc (after load document) diff --git a/src/GeomData/GeomData_Dir.h b/src/GeomData/GeomData_Dir.h index 554fd04c4..56a8b9d2a 100644 --- a/src/GeomData/GeomData_Dir.h +++ b/src/GeomData/GeomData_Dir.h @@ -9,6 +9,9 @@ #include "GeomDataAPI_Dir.h" #include #include +#include + +class GeomAPI_Dir; /**\class GeomData_Dir * \ingroup DataModel @@ -27,6 +30,8 @@ public: GEOMDATA_EXPORT virtual double y() const; /// Returns the Z double value GEOMDATA_EXPORT virtual double z() const; + /// Returns the direction of this attribute + GEOMDATA_EXPORT boost::shared_ptr dir(); protected: /// Initializes attributes diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 26efd6e05..0419550a8 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -24,6 +24,11 @@ public: /// \return the built preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview() = 0; + /// Adds sub-feature of the higher level feature (sub-element of the sketch) + /// \param theFeature sub-feature + SKETCHPLUGIN_EXPORT virtual const void addSub( + const boost::shared_ptr& theFeature) = 0; + protected: /// Set the shape to the internal preview field /// \param theShape a preview shape @@ -31,9 +36,16 @@ protected: /// Return the shape from the internal preview field /// \return theShape a preview shape const boost::shared_ptr& getPreview() const; + /// Sets the higher-level feature for the sub-feature (sketch for line) + void setSketch(SketchPlugin_Sketch* theSketch) {mySketch = theSketch;} + /// Returns the sketch of this feature + SketchPlugin_Sketch* sketch() {return mySketch;} + + friend class SketchPlugin_Sketch; private: boost::shared_ptr myPreview; ///< the preview shape + SketchPlugin_Sketch* mySketch; /// sketch that contains this feature }; #endif diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 5b5cf5108..8462d99bd 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -30,7 +30,7 @@ void SketchPlugin_Line::execute() const boost::shared_ptr& SketchPlugin_Line::preview() { - boost::shared_ptr aSketch = SketchPlugin_Sketch::active(); + SketchPlugin_Sketch* aSketch = sketch(); // compute a start point in 3D view boost::shared_ptr aStartAttr = boost::dynamic_pointer_cast(data()->attribute(LINE_ATTR_START)); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 83480d9a8..6acb48d74 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -46,14 +46,9 @@ const boost::shared_ptr& SketchPlugin_Sketch::preview() return getPreview(); } -void SketchPlugin_Sketch::setActive(boost::shared_ptr theSketch) +const void SketchPlugin_Sketch::addSub(const boost::shared_ptr& theFeature) { - MY_ACITVE_SKETCH = theSketch; -} - -boost::shared_ptr SketchPlugin_Sketch::active() -{ - return MY_ACITVE_SKETCH; + boost::dynamic_pointer_cast(theFeature)->setSketch(this); } void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ, diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 3c6181200..0fc24fb11 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -43,13 +43,10 @@ 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(); + /// Adds sub-feature of the higher level feature (sub-element of the sketch) + /// \param theFeature sub-feature + SKETCHPLUGIN_EXPORT virtual const void addSub( + const boost::shared_ptr& theFeature); /// Converts a 2D sketch space point into point in 3D space SKETCHPLUGIN_EXPORT boost::shared_ptr to3D( -- 2.30.2