From: azv Date: Thu, 5 Jun 2014 11:09:28 +0000 (+0400) Subject: Merge remote-tracking branch 'remotes/origin/master' into SketchSolver X-Git-Tag: V_0.4.4~303^2^2^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ae347a8a8014a15245199a3bb603413628e3f7d4;hp=b035864efaaa03ffcf5a3aa32d20f84f5d6ddc58;p=modules%2Fshaper.git Merge remote-tracking branch 'remotes/origin/master' into SketchSolver Conflicts: src/GeomAlgoAPI/CMakeLists.txt --- diff --git a/CMakeLists.txt b/CMakeLists.txt index bef4cdee8..4f70d821c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ INCLUDE(FindBoost) INCLUDE(FindPython) INCLUDE(FindSalome) INCLUDE(FindSolveSpace) +INCLUDE(FindCAS) IF(UNIX) IF(CMAKE_COMPILER_IS_GNUCC) diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index 2e954c8a8..ebb5efb69 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -4,7 +4,7 @@ INCLUDE(XMLProcessing) INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Events) SET(PROJECT_HEADERS - Config.h + Config_def.h Config_FeatureMessage.h Config_XMLReader.h Config_ModuleReader.h diff --git a/src/Config/Config.h b/src/Config/Config.h deleted file mode 100644 index 587ac534d..000000000 --- a/src/Config/Config.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -#if defined CONFIG_EXPORTS -#if defined WIN32 -#define CONFIG_EXPORT __declspec( dllexport ) -#else -#define CONFIG_EXPORT -#endif -#else -#if defined WIN32 -#define CONFIG_EXPORT __declspec( dllimport ) -#else -#define CONFIG_EXPORT -#endif -#endif - -#endif //CONFIG_H diff --git a/src/Config/Config_Common.h b/src/Config/Config_Common.h index 40051dc2a..2a579b91e 100644 --- a/src/Config/Config_Common.h +++ b/src/Config/Config_Common.h @@ -8,7 +8,7 @@ #ifndef Config_Common_H_ #define Config_Common_H_ -#include "Config.h" +#include "Config_def.h" #include #include diff --git a/src/Config/Config_FeatureMessage.h b/src/Config/Config_FeatureMessage.h index 9328e0690..2613c9926 100644 --- a/src/Config/Config_FeatureMessage.h +++ b/src/Config/Config_FeatureMessage.h @@ -1,7 +1,7 @@ #ifndef CONFIG_MESSAGE_H #define CONFIG_MESSAGE_H -#include +#include #include #include diff --git a/src/Config/Config_FeatureReader.h b/src/Config/Config_FeatureReader.h index 1add8438d..468cb9911 100644 --- a/src/Config/Config_FeatureReader.h +++ b/src/Config/Config_FeatureReader.h @@ -8,7 +8,7 @@ #ifndef CONFIG_FEATUREREADER_H_ #define CONFIG_FEATUREREADER_H_ -#include +#include #include #include diff --git a/src/Config/Config_ModuleReader.h b/src/Config/Config_ModuleReader.h index a4afba3c2..3bd5d39f3 100644 --- a/src/Config/Config_ModuleReader.h +++ b/src/Config/Config_ModuleReader.h @@ -8,7 +8,7 @@ #ifndef CONFIG_MODULEREADER_H_ #define CONFIG_MODULEREADER_H_ -#include +#include #include #include diff --git a/src/Config/Config_PointerMessage.h b/src/Config/Config_PointerMessage.h index f108d3ede..0e3c726ca 100644 --- a/src/Config/Config_PointerMessage.h +++ b/src/Config/Config_PointerMessage.h @@ -8,7 +8,7 @@ #ifndef PARTSET_MESSAGE_H_ #define PARTSET_MESSAGE_H_ -#include +#include #include /* diff --git a/src/Config/Config_WidgetAPI.cpp b/src/Config/Config_WidgetAPI.cpp index 9a77d778a..2fdad6735 100644 --- a/src/Config/Config_WidgetAPI.cpp +++ b/src/Config/Config_WidgetAPI.cpp @@ -61,7 +61,7 @@ bool Config_WidgetAPI::toParentWidget() return myCurrentNode != NULL; } -std::string Config_WidgetAPI::widgetType() +std::string Config_WidgetAPI::widgetType() const { std::string result = ""; if(myCurrentNode) { @@ -70,19 +70,19 @@ std::string Config_WidgetAPI::widgetType() return result; } -bool Config_WidgetAPI::isContainerWidget() +bool Config_WidgetAPI::isContainerWidget() const { return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP, NULL); } -bool Config_WidgetAPI::isPagedWidget() +bool Config_WidgetAPI::isPagedWidget() const { return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH, NULL); } -std::string Config_WidgetAPI::getProperty(const char* thePropName) +std::string Config_WidgetAPI::getProperty(const char* thePropName) const { std::string result = ""; char* aPropChars = (char*) xmlGetProp(myCurrentNode, BAD_CAST thePropName); @@ -92,22 +92,22 @@ std::string Config_WidgetAPI::getProperty(const char* thePropName) return result; } -std::string Config_WidgetAPI::widgetId() +std::string Config_WidgetAPI::widgetId() const { return getProperty("id"); } -std::string Config_WidgetAPI::widgetTooltip() +std::string Config_WidgetAPI::widgetTooltip() const { return getProperty("tooltip"); } -std::string Config_WidgetAPI::widgetIcon() +std::string Config_WidgetAPI::widgetIcon() const { return getProperty("icon"); } -std::string Config_WidgetAPI::widgetLabel() +std::string Config_WidgetAPI::widgetLabel() const { return getProperty("label"); } diff --git a/src/Config/Config_WidgetAPI.h b/src/Config/Config_WidgetAPI.h index 4030ff257..190ccfc7f 100644 --- a/src/Config/Config_WidgetAPI.h +++ b/src/Config/Config_WidgetAPI.h @@ -8,7 +8,7 @@ #ifndef CONFIG_WIDGETAPI_H_ #define CONFIG_WIDGETAPI_H_ -#include +#include #include #include @@ -36,16 +36,16 @@ public: bool toChildWidget(); bool toParentWidget(); - std::string widgetType(); - bool isContainerWidget(); - bool isPagedWidget(); + std::string widgetType() const; + bool isContainerWidget() const; + bool isPagedWidget() const; - std::string widgetId(); - std::string widgetIcon(); - std::string widgetLabel(); - std::string widgetTooltip(); + std::string widgetId() const; + std::string widgetIcon() const; + std::string widgetLabel() const; + std::string widgetTooltip() const; - std::string getProperty(const char* thePropName); + std::string getProperty(const char* thePropName) const; private: xmlDocPtr myDoc; diff --git a/src/Config/Config_WidgetReader.h b/src/Config/Config_WidgetReader.h index cfc1519a5..96f35ac19 100644 --- a/src/Config/Config_WidgetReader.h +++ b/src/Config/Config_WidgetReader.h @@ -8,7 +8,7 @@ #ifndef CONFIG_WIDGETREADER_H_ #define CONFIG_WIDGETREADER_H_ -#include +#include #include #include diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index bcd8ddfdf..8915147e9 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -8,7 +8,7 @@ #ifndef CONFIG_XMLREADER_H_ #define CONFIG_XMLREADER_H_ -#include +#include #include #include diff --git a/src/Config/Config_def.h b/src/Config/Config_def.h new file mode 100644 index 000000000..587ac534d --- /dev/null +++ b/src/Config/Config_def.h @@ -0,0 +1,18 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#if defined CONFIG_EXPORTS +#if defined WIN32 +#define CONFIG_EXPORT __declspec( dllexport ) +#else +#define CONFIG_EXPORT +#endif +#else +#if defined WIN32 +#define CONFIG_EXPORT __declspec( dllimport ) +#else +#define CONFIG_EXPORT +#endif +#endif + +#endif //CONFIG_H diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index ab3491914..dc32be987 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -15,10 +15,12 @@ SET(PROJECT_SOURCES ADD_DEFINITIONS(-DCONSTRUCTIONPLUGIN_EXPORTS ${BOOST_DEFINITIONS}) ADD_LIBRARY(ConstructionPlugin SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) -TARGET_LINK_LIBRARIES(ConstructionPlugin ${PROJECT_LIBRARIES} ModelAPI) +TARGET_LINK_LIBRARIES(ConstructionPlugin ${PROJECT_LIBRARIES} ModelAPI GeomAPI GeomAlgoAPI) INCLUDE_DIRECTORIES( ../ModelAPI + ../GeomAPI + ../GeomAlgoAPI ) SET(XML_RESOURCES diff --git a/src/ConstructionPlugin/ConstructionPlugin_Extrusion.h b/src/ConstructionPlugin/ConstructionPlugin_Extrusion.h index 6d557a3ab..5270d2d89 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Extrusion.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Extrusion.h @@ -8,8 +8,11 @@ #include "ConstructionPlugin.h" #include +/// Extrusion kind +const std::string CONSTRUCTION_EXTRUSION_KIND("Extrusion"); + /// attribute name of referenced face -const std::string EXTRUSION_FACE = "extrusion_select_face"; +const std::string EXTRUSION_FACE = "extrusion_face"; /// attribute name of extrusion size const std::string EXTRUSION_SIZE = "extrusion_size"; @@ -23,7 +26,7 @@ class ConstructionPlugin_Extrusion: public ModelAPI_Feature public: /// Returns the kind of a feature CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind() - { static std::string MY_KIND = "Extrusion"; return MY_KIND; } + { static std::string MY_KIND = CONSTRUCTION_EXTRUSION_KIND; return MY_KIND; } /// Returns to which group in the document must be added feature CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getGroup() diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index a825c5608..d420b2110 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -16,13 +16,13 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() ModelAPI_PluginManager::get()->registerPlugin(this); } -boost::shared_ptr ConstructionPlugin_Plugin::createFeature(string theFeatureID) +FeaturePtr ConstructionPlugin_Plugin::createFeature(string theFeatureID) { - if (theFeatureID == "Point") { - return boost::shared_ptr(new ConstructionPlugin_Point); - } else if (theFeatureID == "Extrusion") { - return boost::shared_ptr(new ConstructionPlugin_Extrusion); + if (theFeatureID == CONSTRUCTION_POINT_KIND) { + return FeaturePtr(new ConstructionPlugin_Point); + } else if (theFeatureID == CONSTRUCTION_EXTRUSION_KIND) { + return FeaturePtr(new ConstructionPlugin_Extrusion); } // feature of such kind is not found - return boost::shared_ptr(); + return FeaturePtr(); } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.h b/src/ConstructionPlugin/ConstructionPlugin_Plugin.h index 0201b40a3..1c772033b 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.h @@ -8,12 +8,13 @@ #include "ConstructionPlugin.h" #include "ModelAPI_Plugin.h" +#include "ModelAPI_Feature.h" class CONSTRUCTIONPLUGIN_EXPORT ConstructionPlugin_Plugin: public ModelAPI_Plugin { public: /// Creates the feature object of this plugin by the feature string ID - virtual boost::shared_ptr createFeature(std::string theFeatureID); + virtual FeaturePtr createFeature(std::string theFeatureID); public: /// Is needed for python wrapping by swig diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index ea613603b..aaa697dd5 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -7,6 +7,8 @@ #include "ModelAPI_Document.h" #include "ModelAPI_Data.h" #include "ModelAPI_AttributeDouble.h" +#include +#include using namespace std; @@ -21,11 +23,10 @@ void ConstructionPlugin_Point::initAttributes() data()->addAttribute(POINT_ATTR_Z, ModelAPI_AttributeDouble::type()); } -// this is for debug only -#include void ConstructionPlugin_Point::execute() { - // TODO: create a real shape for the point using OCC layer - cout<<"X="<real(POINT_ATTR_X)->value()<<" Y="<real(POINT_ATTR_Y)->value() - <<" Z="<real(POINT_ATTR_Z)->value()< aPnt(new GeomAPI_Pnt( + data()->real(POINT_ATTR_X)->value(), data()->real(POINT_ATTR_Y)->value(), data()->real(POINT_ATTR_Z)->value())); + + data()->store(GeomAlgoAPI_PointBuilder::point(aPnt)); } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index 2b71b50fe..a0dda28dd 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -8,6 +8,9 @@ #include "ConstructionPlugin.h" #include +/// Point kind +const std::string CONSTRUCTION_POINT_KIND("Point"); + /// attribute name for X coordinate const std::string POINT_ATTR_X = "x"; /// attribute name for Y coordinate @@ -24,7 +27,7 @@ class ConstructionPlugin_Point: public ModelAPI_Feature public: /// Returns the kind of a feature CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "Point"; return MY_KIND;} + {static std::string MY_KIND = CONSTRUCTION_POINT_KIND; return MY_KIND;} /// Returns to which group in the document must be added feature CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getGroup() diff --git a/src/ConstructionPlugin/extrusion_widget.xml b/src/ConstructionPlugin/extrusion_widget.xml index 52cf8622f..f368a68cd 100644 --- a/src/ConstructionPlugin/extrusion_widget.xml +++ b/src/ConstructionPlugin/extrusion_widget.xml @@ -1,8 +1,9 @@ - diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index ad741d302..2a2f3ed40 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -1,5 +1,4 @@ FIND_PACKAGE(SWIG REQUIRED) -INCLUDE(FindCAS) INCLUDE(${SWIG_USE_FILE}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index 548f7002f..5822d61fb 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -1,5 +1,4 @@ FIND_PACKAGE(SWIG REQUIRED) -INCLUDE(FindCAS) INCLUDE(${SWIG_USE_FILE}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) @@ -9,6 +8,7 @@ SET(PROJECT_HEADERS GeomAlgoAPI_CompoundBuilder.h GeomAlgoAPI_FaceBuilder.h GeomAlgoAPI_EdgeBuilder.h + GeomAlgoAPI_PointBuilder.h GeomAlgoAPI_SketchBuilder.h ) @@ -16,6 +16,7 @@ SET(PROJECT_SOURCES GeomAlgoAPI_CompoundBuilder.cpp GeomAlgoAPI_FaceBuilder.cpp GeomAlgoAPI_EdgeBuilder.cpp + GeomAlgoAPI_PointBuilder.cpp GeomAlgoAPI_SketchBuilder.cpp ) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI.i b/src/GeomAlgoAPI/GeomAlgoAPI.i index 99a815f74..c43f350dc 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI.i +++ b/src/GeomAlgoAPI/GeomAlgoAPI.i @@ -4,6 +4,8 @@ #include "memory" #include "GeomAlgoAPI.h" #include "GeomAlgoAPI_FaceBuilder.h" + #include "GeomAlgoAPI_EdgeBuilder.h" + #include "GeomAlgoAPI_PointBuilder.h" %} // to avoid error on this @@ -17,3 +19,5 @@ // all supported interfaces %include "GeomAlgoAPI_FaceBuilder.h" +%include "GeomAlgoAPI_EdgeBuilder.h" +%include "GeomAlgoAPI_PointBuilder.h" diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp new file mode 100644 index 000000000..d12bd6a86 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp @@ -0,0 +1,22 @@ +// File: GeomAlgoAPI_PointBuilder.cpp +// Created: 02 Jun 2014 +// Author: Mikhail PONIKAROV + + + +#include +#include +#include +#include +#include + +boost::shared_ptr GeomAlgoAPI_PointBuilder::point( + boost::shared_ptr thePoint) +{ + const gp_Pnt& aPnt = thePoint->impl(); + BRepBuilderAPI_MakeVertex aMaker(aPnt); + TopoDS_Vertex aVertex = aMaker.Vertex(); + boost::shared_ptr aRes(new GeomAPI_Shape); + aRes->setImpl(new TopoDS_Shape(aVertex)); + return aRes; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h new file mode 100644 index 000000000..2715062bb --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h @@ -0,0 +1,27 @@ +// File: GeomAlgoAPI_PointBuilder.h +// Created: 02 Jun 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAlgoAPI_PointBuilder_HeaderFile +#define GeomAlgoAPI_PointBuilder_HeaderFile + +#include +#include + +class GeomAPI_Shape; +class GeomAPI_Pnt; + +/**\class GeomAlgoAPI_PointBuilder + * \ingroup DataAlgo + * \brief Allows to create face-shapes by different parameters + */ + +class GEOMALGOAPI_EXPORT GeomAlgoAPI_PointBuilder +{ +public: + /// Creates linear edge by two points + static boost::shared_ptr point( + boost::shared_ptr thePoint); +}; + +#endif diff --git a/src/GeomData/CMakeLists.txt b/src/GeomData/CMakeLists.txt index b69c280d0..a1e450c6e 100644 --- a/src/GeomData/CMakeLists.txt +++ b/src/GeomData/CMakeLists.txt @@ -1,5 +1,4 @@ INCLUDE(Common) -INCLUDE(FindCAS) SET(PROJECT_HEADERS GeomData.h diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 9da38b914..bb12daaad 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -1,5 +1,4 @@ INCLUDE(Common) -INCLUDE(FindCAS) SET(PROJECT_HEADERS Model.h @@ -36,7 +35,9 @@ SET(PROJECT_LIBRARIES Events Config GeomData + GeomAPI ${CAS_OCAF} + ${CAS_TKCAF} ) @@ -51,6 +52,7 @@ INCLUDE_DIRECTORIES( ../Config ../GeomData ../GeomDataAPI + ../GeomAPI ${CAS_INCLUDE_DIRS} ) diff --git a/src/Model/Model_AttributeBoolean.cpp b/src/Model/Model_AttributeBoolean.cpp index d3c0d6bc5..5472dadf2 100644 --- a/src/Model/Model_AttributeBoolean.cpp +++ b/src/Model/Model_AttributeBoolean.cpp @@ -10,8 +10,9 @@ using namespace std; void Model_AttributeBoolean::setValue(bool theValue) { - if (myBool->Get() != theValue) { - myBool->Set(theValue? 1 : 0); + Standard_Boolean aValue = theValue ? Standard_True : Standard_False; + if (myBool->Get() != aValue) { + myBool->Set(aValue); static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); Model_FeatureUpdatedMessage aMsg(owner(), anEvent); Events_Loop::loop()->send(aMsg); @@ -20,7 +21,7 @@ void Model_AttributeBoolean::setValue(bool theValue) bool Model_AttributeBoolean::value() { - return (myBool->Get() == 1)? true : false; + return myBool->Get() == Standard_True; } Model_AttributeBoolean::Model_AttributeBoolean(TDF_Label& theLabel) diff --git a/src/Model/Model_AttributeRefAttr.cpp b/src/Model/Model_AttributeRefAttr.cpp index 16a86b194..397977226 100644 --- a/src/Model/Model_AttributeRefAttr.cpp +++ b/src/Model/Model_AttributeRefAttr.cpp @@ -34,7 +34,7 @@ void Model_AttributeRefAttr::setAttr(boost::shared_ptr theAt boost::shared_ptr Model_AttributeRefAttr::attr() { - boost::shared_ptr aFeature = feature(); + FeaturePtr aFeature = feature(); if (aFeature) { boost::shared_ptr aData = boost::dynamic_pointer_cast(aFeature->data()); @@ -44,7 +44,7 @@ boost::shared_ptr Model_AttributeRefAttr::attr() return boost::shared_ptr(); } -void Model_AttributeRefAttr::setFeature(boost::shared_ptr theFeature) +void Model_AttributeRefAttr::setFeature(FeaturePtr theFeature) { if (myID->Get().Length() != 0 || feature() != theFeature) { boost::shared_ptr aData = @@ -58,7 +58,7 @@ void Model_AttributeRefAttr::setFeature(boost::shared_ptr theF } } -boost::shared_ptr Model_AttributeRefAttr::feature() +FeaturePtr Model_AttributeRefAttr::feature() { if (myRef->Get() != myRef->Label()) { // initialized boost::shared_ptr aDoc = @@ -70,7 +70,7 @@ boost::shared_ptr Model_AttributeRefAttr::feature() } } // not initialized - return boost::shared_ptr(); + return FeaturePtr(); } Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel) diff --git a/src/Model/Model_AttributeRefAttr.h b/src/Model/Model_AttributeRefAttr.h index f9d2bc42e..69fda0163 100644 --- a/src/Model/Model_AttributeRefAttr.h +++ b/src/Model/Model_AttributeRefAttr.h @@ -33,10 +33,10 @@ public: MODEL_EXPORT virtual boost::shared_ptr attr(); /// Defines the reference to the feature - MODEL_EXPORT virtual void setFeature(boost::shared_ptr theFeature); + MODEL_EXPORT virtual void setFeature(FeaturePtr theFeature); /// Returns feature referenced from this attribute - MODEL_EXPORT virtual boost::shared_ptr feature(); + MODEL_EXPORT virtual FeaturePtr feature(); protected: /// Objects are created for features automatically diff --git a/src/Model/Model_AttributeRefList.cpp b/src/Model/Model_AttributeRefList.cpp index f6520fce8..af4cbd3ea 100644 --- a/src/Model/Model_AttributeRefList.cpp +++ b/src/Model/Model_AttributeRefList.cpp @@ -12,7 +12,7 @@ using namespace std; -void Model_AttributeRefList::append(boost::shared_ptr theFeature) +void Model_AttributeRefList::append(FeaturePtr theFeature) { boost::shared_ptr aData = boost::dynamic_pointer_cast(theFeature->data()); @@ -23,7 +23,7 @@ void Model_AttributeRefList::append(boost::shared_ptr theFeatu Events_Loop::loop()->send(aMsg); } -void Model_AttributeRefList::remove(boost::shared_ptr theFeature) +void Model_AttributeRefList::remove(FeaturePtr theFeature) { boost::shared_ptr aData = boost::dynamic_pointer_cast(theFeature->data()); @@ -36,9 +36,9 @@ int Model_AttributeRefList::size() return myRef->Extent(); } -list > Model_AttributeRefList::list() +list Model_AttributeRefList::list() { - std::list< boost::shared_ptr > aResult; + std::list< FeaturePtr > aResult; boost::shared_ptr aDoc = boost::dynamic_pointer_cast(owner()->document()); if (aDoc) { diff --git a/src/Model/Model_AttributeRefList.h b/src/Model/Model_AttributeRefList.h index bf6290c07..340f5cdf0 100644 --- a/src/Model/Model_AttributeRefList.h +++ b/src/Model/Model_AttributeRefList.h @@ -7,6 +7,8 @@ #include "Model.h" #include "ModelAPI_AttributeRefList.h" +#include "ModelAPI_Feature.h" + #include /**\class Model_AttributeRefList @@ -19,16 +21,16 @@ class Model_AttributeRefList : public ModelAPI_AttributeRefList Handle_TDataStd_ReferenceList myRef; ///< references to the features labels public: /// Appends the feature to the end of a list - MODEL_EXPORT virtual void append(boost::shared_ptr theFeature); + MODEL_EXPORT virtual void append(FeaturePtr theFeature); /// Erases the first meet of the feature in the list - MODEL_EXPORT virtual void remove(boost::shared_ptr theFeature); + MODEL_EXPORT virtual void remove(FeaturePtr theFeature); /// Returns number of features in the list MODEL_EXPORT virtual int size(); /// Returns the list of features - MODEL_EXPORT virtual std::list > list(); + MODEL_EXPORT virtual std::list list(); protected: /// Objects are created for features automatically diff --git a/src/Model/Model_AttributeReference.cpp b/src/Model/Model_AttributeReference.cpp index 105639b74..adcfe4ab4 100644 --- a/src/Model/Model_AttributeReference.cpp +++ b/src/Model/Model_AttributeReference.cpp @@ -11,7 +11,7 @@ using namespace std; -void Model_AttributeReference::setValue(boost::shared_ptr theFeature) +void Model_AttributeReference::setValue(FeaturePtr theFeature) { if (value() != theFeature) { boost::shared_ptr aData = @@ -19,7 +19,7 @@ void Model_AttributeReference::setValue(boost::shared_ptr theF if (myRef.IsNull()) { boost::shared_ptr aMyData = boost::dynamic_pointer_cast(owner()->data()); - TDF_Reference::Set(aMyData->label(), aData->label()); + myRef = TDF_Reference::Set(aMyData->label(), aData->label()); } else { myRef->Set(aData->label()); } @@ -30,7 +30,7 @@ void Model_AttributeReference::setValue(boost::shared_ptr theF } } -boost::shared_ptr Model_AttributeReference::value() +FeaturePtr Model_AttributeReference::value() { if (!myRef.IsNull()) { boost::shared_ptr aDoc = @@ -41,7 +41,7 @@ boost::shared_ptr Model_AttributeReference::value() } } // not initialized - return boost::shared_ptr(); + return FeaturePtr(); } Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel) diff --git a/src/Model/Model_AttributeReference.h b/src/Model/Model_AttributeReference.h index e17855e48..6406d0bfb 100644 --- a/src/Model/Model_AttributeReference.h +++ b/src/Model/Model_AttributeReference.h @@ -7,6 +7,7 @@ #include "Model.h" #include "ModelAPI_AttributeReference.h" +#include #include #include @@ -20,10 +21,10 @@ class Model_AttributeReference : public ModelAPI_AttributeReference Handle_TDF_Reference myRef; ///< references to the feature label public: /// Defines the feature referenced from this attribute - MODEL_EXPORT virtual void setValue(boost::shared_ptr theFeature); + MODEL_EXPORT virtual void setValue(FeaturePtr theFeature); /// Returns feature referenced from this attribute - MODEL_EXPORT virtual boost::shared_ptr value(); + MODEL_EXPORT virtual FeaturePtr value(); protected: /// Objects are created for features automatically diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index f794bda07..31f9f36a0 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -73,6 +74,8 @@ void Model_Data::addAttribute(string theID, string theAttrType) anAttr = new GeomData_Dir(anAttrLab); else if (theAttrType == GeomData_Point2D::type()) anAttr = new GeomData_Point2D(anAttrLab); + else if (theAttrType == Model_AttributeBoolean::type()) + anAttr = new Model_AttributeBoolean(anAttrLab); if (anAttr) { myAttrs[theID] = boost::shared_ptr(anAttr); @@ -112,6 +115,21 @@ boost::shared_ptr Model_Data::real(const string theID) return aRes; } +boost::shared_ptr Model_Data::boolean(const std::string theID) +{ + map >::iterator aFound = myAttrs.find(theID); + if (aFound == myAttrs.end()) { + // TODO: generate error on unknown attribute request and/or add mechanism for customization + return boost::shared_ptr(); + } + boost::shared_ptr aRes = + boost::dynamic_pointer_cast(aFound->second); + if (!aRes) { + // TODO: generate error on invalid attribute type request + } + return aRes; +} + boost::shared_ptr Model_Data::reference(const string theID) { map >::iterator aFound = myAttrs.find(theID); @@ -188,3 +206,34 @@ bool Model_Data::isValid() { return !myLab.IsNull() && myLab.HasAttribute(); } + +#include +#include +#include +#include + +void Model_Data::store(const boost::shared_ptr& theShape) +{ + // the simplest way is to keep this attribute here, on Data + // TODO: add naming structure in separated document for shape storage + TNaming_Builder aBuilder(myLab); + if (!theShape) return; // bad shape + TopoDS_Shape aShape = theShape->impl(); + if (aShape.IsNull()) return; // null shape inside + + aBuilder.Generated(aShape); +} + +boost::shared_ptr Model_Data::shape() +{ + Handle(TNaming_NamedShape) aName; + if (myLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) { + TopoDS_Shape aShape = aName->Get(); + if (!aShape.IsNull()) { + boost::shared_ptr aRes(new GeomAPI_Shape); + aRes->setImpl(new TopoDS_Shape(aShape)); + return aRes; + } + } + return boost::shared_ptr(); +} diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 03ff0c54e..36f5f3614 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -7,12 +7,12 @@ #include "Model.h" #include +#include #include #include class ModelAPI_Attribute; -class ModelAPI_Feature; /**\class Model_Data * \ingroup DataModel @@ -27,7 +27,7 @@ class Model_Data: public ModelAPI_Data std::map > myAttrs; /// needed here to emit signal that feature changed on change of the attribute - boost::shared_ptr myFeature; + FeaturePtr myFeature; Model_Data(); @@ -57,6 +57,9 @@ public: /// Returns the attribute that contains list of references to features MODEL_EXPORT virtual boost::shared_ptr reflist(const std::string theID); + /// Returns the attribute that contains boolean value + MODEL_EXPORT virtual boost::shared_ptr + boolean(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); @@ -68,6 +71,11 @@ public: /// Returns true if it is correctly connected t othe data model MODEL_EXPORT virtual bool isValid(); + /// Stores the shape (called by the execution method). + MODEL_EXPORT virtual void store(const boost::shared_ptr& theShape); + /// Returns the shape-result produced by this feature + MODEL_EXPORT virtual boost::shared_ptr shape(); + /// 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 @@ -78,7 +86,7 @@ public: MODEL_EXPORT void setLabel(TDF_Label& theLab); /// Sets the feature of this data - MODEL_EXPORT virtual void setFeature(boost::shared_ptr theFeature) + MODEL_EXPORT virtual void setFeature(FeaturePtr theFeature) {myFeature = theFeature;} }; diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 76b72fe0c..e17a14af5 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -319,9 +319,9 @@ void Model_Document::redo() subDocument(*aSubIter)->redo(); } -boost::shared_ptr Model_Document::addFeature(string theID) +FeaturePtr Model_Document::addFeature(string theID) { - boost::shared_ptr aFeature = + FeaturePtr aFeature = ModelAPI_PluginManager::get()->createFeature(theID); if (aFeature) { boost::dynamic_pointer_cast(aFeature->documentToAdd())->addFeature(aFeature); @@ -348,7 +348,7 @@ static void AddToRefArray(TDF_Label& theArrayLab, TDF_Label& theReferenced) { } } -void Model_Document::addFeature(const boost::shared_ptr theFeature) +void Model_Document::addFeature(const FeaturePtr theFeature) { if (theFeature->isAction()) return; // do not add action to the data model @@ -421,7 +421,7 @@ static int RemoveFromRefArray( return aResult; } -void Model_Document::removeFeature(boost::shared_ptr theFeature) +void Model_Document::removeFeature(FeaturePtr theFeature) { boost::shared_ptr aData = boost::static_pointer_cast(theFeature->data()); TDF_Label aFeatureLabel = aData->label(); @@ -430,7 +430,7 @@ void Model_Document::removeFeature(boost::shared_ptr theFeatur int aRemovedIndex = RemoveFromRefArray(aGroupLabel, aFeatureLabel); RemoveFromRefArray(aGroupLabel.FindChild(1), TDF_Label(), aRemovedIndex); // remove feature from the myFeatures list - std::vector >::iterator aFIter = myFeatures.begin(); + std::vector::iterator aFIter = myFeatures.begin(); while(aFIter != myFeatures.end()) { if (*aFIter == theFeature) { aFIter = myFeatures.erase(aFIter); @@ -448,17 +448,17 @@ void Model_Document::removeFeature(boost::shared_ptr theFeatur Events_Loop::loop()->send(aMsg); } -boost::shared_ptr Model_Document::feature(TDF_Label& theLabel) +FeaturePtr Model_Document::feature(TDF_Label& theLabel) { // iterate all features, may be optimized later by keeping labels-map - vector >::iterator aFIter = myFeatures.begin(); + vector::iterator aFIter = myFeatures.begin(); for(; aFIter != myFeatures.end(); aFIter++) { boost::shared_ptr aData = boost::dynamic_pointer_cast((*aFIter)->data()); if (aData->label().IsEqual(theLabel)) return *aFIter; } - return boost::shared_ptr(); // not found + return FeaturePtr(); // not found } boost::shared_ptr Model_Document::subDocument(string theDocID) @@ -469,7 +469,7 @@ boost::shared_ptr Model_Document::subDocument(string theDocID return Model_Application::getApplication()->getDocument(theDocID); } -boost::shared_ptr Model_Document::feature( +FeaturePtr Model_Document::feature( const string& theGroupID, const int theIndex, const bool isOperation) { TDF_Label aGroupLab = groupLabel(theGroupID); @@ -477,7 +477,7 @@ boost::shared_ptr Model_Document::feature( if (aGroupLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) { if (aRefs->Lower() <= theIndex && aRefs->Upper() >= theIndex) { TDF_Label aFeatureLab = aRefs->Value(theIndex); - boost::shared_ptr aFeature = feature(aFeatureLab); + FeaturePtr aFeature = feature(aFeatureLab); if (theGroupID == FEATURES_GROUP || isOperation) { // just returns the feature from the history return aFeature; @@ -492,7 +492,7 @@ boost::shared_ptr Model_Document::feature( } // not found - return boost::shared_ptr(); + return FeaturePtr(); } int Model_Document::size(const string& theGroupID) @@ -534,7 +534,7 @@ TDF_Label Model_Document::groupLabel(const string theGroup) return aNew; } -void Model_Document::setUniqueName(boost::shared_ptr theFeature) +void Model_Document::setUniqueName(FeaturePtr theFeature) { string aName; // result // iterate all features but also iterate group of this feature if object is not in history @@ -571,8 +571,8 @@ void Model_Document::setUniqueName(boost::shared_ptr theFeatur } //! Returns the object by the feature -boost::shared_ptr Model_Document::objectByFeature( - const boost::shared_ptr theFeature) +FeaturePtr Model_Document::objectByFeature( + const FeaturePtr theFeature) { for(int a = 0; a < size(theFeature->getGroup()); a++) { boost::shared_ptr anObj = @@ -581,14 +581,14 @@ boost::shared_ptr Model_Document::objectByFeature( return anObj; } } - return boost::shared_ptr(); // not found + return FeaturePtr(); // not found } void Model_Document::synchronizeFeatures(const bool theMarkUpdated) { boost::shared_ptr aThis = Model_Application::getApplication()->getDocument(myID); // update features - vector >::iterator aFIter = myFeatures.begin(); + vector::iterator aFIter = myFeatures.begin(); // and in parallel iterate labels of features TDF_ChildIDIterator aFLabIter(groupLabel(FEATURES_GROUP), TDataStd_Comment::GetID()); while(aFIter != myFeatures.end() || aFLabIter.More()) { @@ -614,7 +614,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated) Events_Loop::loop()->send(aMsg2); } else if (aDSTag < aFeatureTag) { // a new feature is inserted // create a feature - boost::shared_ptr aFeature = ModelAPI_PluginManager::get()->createFeature( + FeaturePtr aFeature = ModelAPI_PluginManager::get()->createFeature( TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast( aFLabIter.Value())->Get()).ToCString()); @@ -637,7 +637,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated) static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED); Model_FeatureUpdatedMessage aMsg1(aFeature, anEvent); Events_Loop::loop()->send(aMsg1); - boost::shared_ptr anObj = objectByFeature(aFeature); + FeaturePtr anObj = objectByFeature(aFeature); if (anObj) { Model_FeatureUpdatedMessage aMsg2(anObj, anEvent); Events_Loop::loop()->send(aMsg2); diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 41f7d51f6..adc4846ec 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -61,14 +62,14 @@ public: //! Adds to the document the new feature of the given feature id //! \param creates feature and puts it in the document - MODEL_EXPORT virtual boost::shared_ptr addFeature(std::string theID); + MODEL_EXPORT virtual FeaturePtr addFeature(std::string theID); //! Removes the feature from the document - MODEL_EXPORT virtual void removeFeature(boost::shared_ptr theFeature); + MODEL_EXPORT virtual void removeFeature(FeaturePtr theFeature); //! Returns the existing feature by the label //! \param theLabel base label of the feature - MODEL_EXPORT virtual boost::shared_ptr feature(TDF_Label& theLabel); + MODEL_EXPORT virtual FeaturePtr feature(TDF_Label& theLabel); //! Adds a new sub-document by the identifier, or returns existing one if it is already exist MODEL_EXPORT virtual boost::shared_ptr subDocument(std::string theDocID); @@ -80,7 +81,7 @@ public: //! \param theGroupID group that contains a feature //! \param theIndex zero-based index of feature in the group //! \param isOperation if it is true, returns feature (not Object) - MODEL_EXPORT virtual boost::shared_ptr + MODEL_EXPORT virtual FeaturePtr feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false); //! Returns the number of features in the group @@ -93,14 +94,14 @@ protected: //! Initializes feature with a unique name in this group (unique name is generated as //! feature type + "_" + index - void setUniqueName(boost::shared_ptr theFeature); + void setUniqueName(FeaturePtr theFeature); //! Adds to the document the new feature - void addFeature(const boost::shared_ptr theFeature); + void addFeature(const FeaturePtr theFeature); //! Returns the object by the feature - boost::shared_ptr objectByFeature( - const boost::shared_ptr theFeature); + FeaturePtr objectByFeature( + const FeaturePtr theFeature); //! Synchronizes myFeatures list with the updated document void synchronizeFeatures(const bool theMarkUpdated = false); @@ -124,7 +125,7 @@ private: /// number of nested transactions performed (or -1 if not nested) int myNestedNum; /// All features managed by this document (not only in history of OB) - std::vector > myFeatures; + std::vector myFeatures; ///< set of identifiers of sub-documents of this document std::set mySubs; diff --git a/src/Model/Model_Events.h b/src/Model/Model_Events.h index 0bce1c980..1fbf1980e 100644 --- a/src/Model/Model_Events.h +++ b/src/Model/Model_Events.h @@ -12,7 +12,8 @@ #include #include -class ModelAPI_Feature; +#include "ModelAPI_Feature.h" + class ModelAPI_Document; /// Event ID that feature is created (comes with Model_FeatureUpdatedMessage) @@ -26,27 +27,27 @@ static const char * EVENT_FEATURE_MOVED = "FeaturesMoved"; /// Message that feature was changed (used for Object Browser update): moved, updated and deleted class Model_FeatureUpdatedMessage : public Events_MessageGroup { - std::set > myFeatures; ///< which feature is changed + std::set myFeatures; ///< which feature is changed public: /// sender is not important, all information is located in the feature Model_FeatureUpdatedMessage( - const boost::shared_ptr& theFeature, + const FeaturePtr& theFeature, const Events_ID& theEvent) : Events_MessageGroup(theEvent, 0) {if (theFeature) myFeatures.insert(theFeature);} /// Returns the feature that has been updated - std::set > features() const {return myFeatures;} + std::set features() const {return myFeatures;} //! Creates a new empty group (to store it in the loop before flush) virtual Events_MessageGroup* newEmpty() { - boost::shared_ptr anEmptyFeature; + FeaturePtr anEmptyFeature; return new Model_FeatureUpdatedMessage(anEmptyFeature, eventID()); } //! Allows to join the given message with the current one virtual void Join(Events_MessageGroup& theJoined) { Model_FeatureUpdatedMessage* aJoined = dynamic_cast(&theJoined); - std::set >::iterator aFIter = aJoined->myFeatures.begin(); + std::set::iterator aFIter = aJoined->myFeatures.begin(); for(; aFIter != aJoined->myFeatures.end(); aFIter++) { myFeatures.insert(*aFIter); } diff --git a/src/Model/Model_Object.cpp b/src/Model/Model_Object.cpp index 269c547cf..e0c5b3028 100644 --- a/src/Model/Model_Object.cpp +++ b/src/Model/Model_Object.cpp @@ -7,7 +7,7 @@ #include "Model_Events.h" #include -boost::shared_ptr Model_Object::featureRef() +FeaturePtr Model_Object::featureRef() { return myRef; } @@ -29,7 +29,7 @@ void Model_Object::setName(std::string theName) } } -Model_Object::Model_Object(boost::shared_ptr theRef, +Model_Object::Model_Object(FeaturePtr theRef, Handle_TDataStd_Name theName) : myRef(theRef), myName(theName) { diff --git a/src/Model/Model_Object.h b/src/Model/Model_Object.h index 811edf709..73975bc28 100644 --- a/src/Model/Model_Object.h +++ b/src/Model/Model_Object.h @@ -19,11 +19,11 @@ */ class Model_Object : public ModelAPI_Object { - boost::shared_ptr myRef; ///< the referenced feature + FeaturePtr myRef; ///< the referenced feature Handle_TDataStd_Name myName; ///< the name of this object that may be changed public: /// Reference to the feature-operation that produces this object - MODEL_EXPORT virtual boost::shared_ptr featureRef(); + MODEL_EXPORT virtual FeaturePtr featureRef(); /// Returns the name of this object (by default equal to the name of feature) MODEL_EXPORT virtual std::string getName(); @@ -42,7 +42,7 @@ public: {return myRef->document();} /// Returns true if feature refers to the same model data instance - MODEL_EXPORT virtual bool isSame(const boost::shared_ptr& theFeature) + MODEL_EXPORT virtual bool isSame(const FeaturePtr& theFeature) { boost::shared_ptr anObj = boost::dynamic_pointer_cast(theFeature); return anObj && myRef == anObj->myRef; @@ -57,7 +57,7 @@ public: private: /// Constructor fully defines this object - Model_Object(boost::shared_ptr theRef, Handle_TDataStd_Name theName); + Model_Object(FeaturePtr theRef, Handle_TDataStd_Name theName); friend class Model_Document; }; diff --git a/src/Model/Model_PluginManager.cpp b/src/Model/Model_PluginManager.cpp index 1a6cef9d8..c95ab1242 100644 --- a/src/Model/Model_PluginManager.cpp +++ b/src/Model/Model_PluginManager.cpp @@ -24,7 +24,7 @@ using namespace std; static Model_PluginManager* myImpl = new Model_PluginManager(); -boost::shared_ptr Model_PluginManager::createFeature(string theFeatureID) +FeaturePtr Model_PluginManager::createFeature(string theFeatureID) { if (this != myImpl) return myImpl->createFeature(theFeatureID); @@ -36,7 +36,7 @@ boost::shared_ptr Model_PluginManager::createFeature(string th Config_ModuleReader::loadLibrary(myCurrentPluginName); } if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) { - boost::shared_ptr aCreated = + FeaturePtr aCreated = myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID); if (!aCreated) { Events_Error::send(string("Can not initialize feature '") + theFeatureID + @@ -48,7 +48,7 @@ boost::shared_ptr Model_PluginManager::createFeature(string th } } - return boost::shared_ptr(); // return nothing + return FeaturePtr(); // return nothing } boost::shared_ptr Model_PluginManager::rootDocument() diff --git a/src/Model/Model_PluginManager.h b/src/Model/Model_PluginManager.h index 4efef6a4c..bed54c08b 100644 --- a/src/Model/Model_PluginManager.h +++ b/src/Model/Model_PluginManager.h @@ -7,6 +7,8 @@ #include "Model.h" #include +#include + #include #include @@ -62,7 +64,7 @@ protected: void LoadPluginsInfo(); /// Creates the feature object using plugins functionality - virtual boost::shared_ptr createFeature(std::string theFeatureID); + virtual FeaturePtr createFeature(std::string theFeatureID); }; #endif diff --git a/src/ModelAPI/ModelAPI_AttributeRefAttr.h b/src/ModelAPI/ModelAPI_AttributeRefAttr.h index 4fd883466..a16813609 100644 --- a/src/ModelAPI/ModelAPI_AttributeRefAttr.h +++ b/src/ModelAPI/ModelAPI_AttributeRefAttr.h @@ -6,6 +6,7 @@ #define ModelAPI_AttributeRefAttr_HeaderFile #include "ModelAPI_Attribute.h" +#include "ModelAPI_Feature.h" /**\class ModelAPI_AttributeRefAttr * \ingroup DataModel @@ -26,10 +27,10 @@ public: MODELAPI_EXPORT virtual boost::shared_ptr attr() = 0; /// Defines the reference to the feature - MODELAPI_EXPORT virtual void setFeature(boost::shared_ptr theFeature) = 0; + MODELAPI_EXPORT virtual void setFeature(FeaturePtr theFeature) = 0; /// Returns feature referenced from this attribute - MODELAPI_EXPORT virtual boost::shared_ptr feature() = 0; + MODELAPI_EXPORT virtual FeaturePtr feature() = 0; /// Returns the type of this class of attributes MODELAPI_EXPORT static std::string type() {return "RefAttr";} diff --git a/src/ModelAPI/ModelAPI_AttributeRefList.h b/src/ModelAPI/ModelAPI_AttributeRefList.h index 973fbc46d..87800fb36 100644 --- a/src/ModelAPI/ModelAPI_AttributeRefList.h +++ b/src/ModelAPI/ModelAPI_AttributeRefList.h @@ -6,6 +6,7 @@ #define ModelAPI_AttributeRefList_HeaderFile #include "ModelAPI_Attribute.h" +#include "ModelAPI_Feature.h" #include /**\class ModelAPI_AttributeRefList @@ -23,16 +24,16 @@ public: MODELAPI_EXPORT virtual std::string attributeType() {return type();} /// Appends the feature to the end of a list - MODELAPI_EXPORT virtual void append(boost::shared_ptr theFeature) = 0; + MODELAPI_EXPORT virtual void append(FeaturePtr theFeature) = 0; /// Erases the first meet of the feature in the list - MODELAPI_EXPORT virtual void remove(boost::shared_ptr theFeature) = 0; + MODELAPI_EXPORT virtual void remove(FeaturePtr theFeature) = 0; /// Returns number of features in the list MODELAPI_EXPORT virtual int size() = 0; /// Returns the list of features - MODELAPI_EXPORT virtual std::list > list() = 0; + MODELAPI_EXPORT virtual std::list list() = 0; protected: /// Objects are created for features automatically diff --git a/src/ModelAPI/ModelAPI_AttributeReference.h b/src/ModelAPI/ModelAPI_AttributeReference.h index 37b22560c..0af5898ff 100644 --- a/src/ModelAPI/ModelAPI_AttributeReference.h +++ b/src/ModelAPI/ModelAPI_AttributeReference.h @@ -6,6 +6,7 @@ #define ModelAPI_AttributeReference_HeaderFile #include "ModelAPI_Attribute.h" +#include /**\class ModelAPI_AttributeReference * \ingroup DataModel @@ -16,10 +17,10 @@ class ModelAPI_AttributeReference : public ModelAPI_Attribute { public: /// Defines the feature referenced from this attribute - MODELAPI_EXPORT virtual void setValue(boost::shared_ptr theFeature) = 0; + MODELAPI_EXPORT virtual void setValue(FeaturePtr theFeature) = 0; /// Returns feature referenced from this attribute - MODELAPI_EXPORT virtual boost::shared_ptr value() = 0; + MODELAPI_EXPORT virtual FeaturePtr value() = 0; /// Returns the type of this class of attributes MODELAPI_EXPORT static std::string type() {return "Reference";} diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index f8dd22896..76967d181 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -14,8 +14,10 @@ class ModelAPI_AttributeDouble; class ModelAPI_AttributeReference; class ModelAPI_AttributeRefAttr; class ModelAPI_AttributeRefList; +class ModelAPI_AttributeBoolean; class ModelAPI_Document; class ModelAPI_Attribute; +class GeomAPI_Shape; /**\class ModelAPI_Data * \ingroup DataModel @@ -43,6 +45,8 @@ public: virtual boost::shared_ptr refattr(const std::string theID) = 0; /// Returns the attribute that contains list of references to features virtual boost::shared_ptr reflist(const std::string theID) = 0; + /// Returns the attribute that contains boolean value + virtual boost::shared_ptr boolean(const std::string theID) = 0; /// Returns the generic attribute by identifier /// \param theID identifier of the attribute @@ -55,6 +59,11 @@ public: /// Returns true if it is correctly connected t othe data model virtual bool isValid() = 0; + /// Stores the shape (called by the execution method). + virtual void store(const boost::shared_ptr& theShape) = 0; + /// Returns the shape-result produced by this feature + virtual boost::shared_ptr shape() = 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/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index bd726461f..6d7955f4b 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -58,7 +58,7 @@ public: /// Returns true if feature refers to the same model data instance MODELAPI_EXPORT virtual bool isSame(const boost::shared_ptr& theFeature) - {return true;} + {return theFeature.get() == this;} /// To virtually destroy the fields of successors virtual ~ModelAPI_Feature() {} diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index 55ee09527..581f04588 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -23,7 +23,7 @@ public: MODELAPI_EXPORT virtual bool isInHistory() {return false;} /// Reference to the feature-operation that produces this object - MODELAPI_EXPORT virtual boost::shared_ptr featureRef() = 0; + MODELAPI_EXPORT virtual FeaturePtr featureRef() = 0; /// Returns the name of this object (by default equal to the name of feature) MODELAPI_EXPORT virtual std::string getName() = 0; diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 82f7214d8..8679b5724 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -11,6 +11,9 @@ SET(PROJECT_HEADERS ModuleBase_WidgetPoint2D.h ModuleBase_WidgetSwitch.h ModuleBase_MetaWidget.h + ModuleBase_SelectorWidget.h + ModuleBase_IWorkshop.h + ModuleBase_Widgets.h ) SET(PROJECT_SOURCES @@ -21,12 +24,16 @@ SET(PROJECT_SOURCES ModuleBase_WidgetPoint2D.cpp ModuleBase_WidgetSwitch.cpp ModuleBase_MetaWidget.cpp + ModuleBase_SelectorWidget.cpp + ModuleBase_Widgets.cpp ) SET(PROJECT_LIBRARIES Config ModelAPI ${QT_LIBRARIES} + ${CAS_VIEWER} + ${CAS_KERNEL} ) SET(PROJECT_AUTOMOC @@ -40,14 +47,15 @@ SOURCE_GROUP ("Generated Files" FILES ${PROJECT_AUTOMOC} ${PROJECT_COMPILED_RESO #SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES} ${PROJECT_RESOURCES}) INCLUDE_DIRECTORIES( - ${PROJECT_SOURCE_DIR}/src/Config + ${CAS_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/src/Config ${CMAKE_SOURCE_DIR}/src/Events ${CMAKE_SOURCE_DIR}/src/Model ${CMAKE_SOURCE_DIR}/src/ModelAPI ${CMAKE_SOURCE_DIR}/src/GeomDataAPI ) -ADD_DEFINITIONS(-DMODULEBASE_EXPORTS) +ADD_DEFINITIONS(-DMODULEBASE_EXPORTS ${CAS_DEFINITIONS}) ADD_LIBRARY(ModuleBase SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) TARGET_LINK_LIBRARIES(ModuleBase ${PROJECT_LIBRARIES}) diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h new file mode 100644 index 000000000..d9dcf5405 --- /dev/null +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -0,0 +1,37 @@ +// File: ModuleBase_IWorkshop.h +// Created: 2 June 2014 +// Author: Vitaly Smetannikov + +#ifndef ModuleBase_IWorkshop_H +#define ModuleBase_IWorkshop_H + +#include "ModuleBase.h" + +#include + +#include + +#include + +/** +* Class which provides access to Workshop object serveces +*/ +class MODULEBASE_EXPORT ModuleBase_IWorkshop: public QObject +{ +Q_OBJECT +public: + ModuleBase_IWorkshop(QObject* theParent):QObject(theParent) {} + + virtual ~ModuleBase_IWorkshop() {}; + + //! Returns AIS_InteractiveContext from current OCCViewer + virtual Handle(AIS_InteractiveContext) AISContext() const = 0; + + //! Returns list of currently selected data objects + virtual QList selectedFeatures() const = 0; + +signals: + void selectionChanged(); +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_MetaWidget.cpp b/src/ModuleBase/ModuleBase_MetaWidget.cpp index a8a65232b..ba8eb260d 100644 --- a/src/ModuleBase/ModuleBase_MetaWidget.cpp +++ b/src/ModuleBase/ModuleBase_MetaWidget.cpp @@ -21,7 +21,7 @@ ModuleBase_MetaWidget::~ModuleBase_MetaWidget() } -bool ModuleBase_MetaWidget::storeValue(boost::shared_ptr theFeature) +bool ModuleBase_MetaWidget::storeValue(FeaturePtr theFeature) { #ifdef _DEBUG std::cout << "ModuleBase_MetaWidget::storeValue" @@ -30,7 +30,7 @@ bool ModuleBase_MetaWidget::storeValue(boost::shared_ptr theFe return true; } -bool ModuleBase_MetaWidget::restoreValue(boost::shared_ptr theFeature) +bool ModuleBase_MetaWidget::restoreValue(FeaturePtr theFeature) { #ifdef _DEBUG std::cout << "ModuleBase_MetaWidget::restoreValue" diff --git a/src/ModuleBase/ModuleBase_MetaWidget.h b/src/ModuleBase/ModuleBase_MetaWidget.h index 0bbc6fbcd..42504e0f0 100644 --- a/src/ModuleBase/ModuleBase_MetaWidget.h +++ b/src/ModuleBase/ModuleBase_MetaWidget.h @@ -23,9 +23,9 @@ public: MODULEBASE_EXPORT ModuleBase_MetaWidget(QWidget* theWrapped); virtual ~ModuleBase_MetaWidget(); //! Interface for saving widget's data into the data model - MODULEBASE_EXPORT virtual bool storeValue(boost::shared_ptr theFeature); + MODULEBASE_EXPORT virtual bool storeValue(FeaturePtr theFeature); //! Interface for loading widget's data from the data model - MODULEBASE_EXPORT virtual bool restoreValue(boost::shared_ptr theFeature); + MODULEBASE_EXPORT virtual bool restoreValue(FeaturePtr theFeature); /// Set focus to the current widget if it corresponds to the given attribute /// \param theAttribute name diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index afdc1f2ca..c20357942 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -7,6 +7,8 @@ #include +#include + #include #include @@ -34,16 +36,16 @@ public: /// Saves the internal parameters to the given feature /// \param theFeature a model feature to be changed - virtual bool storeValue(boost::shared_ptr theFeature) = 0; + virtual bool storeValue(FeaturePtr theFeature) const = 0; - virtual bool restoreValue(boost::shared_ptr theFeature) = 0; + virtual bool restoreValue(FeaturePtr theFeature) = 0; /// Returns whether the widget can accept focus, or if it corresponds to the given attribute /// \param theAttribute name - virtual bool canFocusTo(const std::string& theAttributeName) = 0; + virtual bool canFocusTo(const std::string& theAttributeName) const { return false; } /// Set focus to the current widget if it corresponds to the given attribute - virtual void focusTo() = 0; + virtual void focusTo() {} /// Returns list of widget controls /// \return a control list diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 8bf69185c..52b23a92c 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -24,7 +24,7 @@ #endif ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent) -: ModuleBase_IOperation(theId, theParent) +: ModuleBase_IOperation(theId, theParent), myIsEditing(false) { } @@ -37,7 +37,7 @@ QString ModuleBase_Operation::id() const return getDescription()->operationId(); } -boost::shared_ptr ModuleBase_Operation::feature() const +FeaturePtr ModuleBase_Operation::feature() const { return myFeature; } @@ -80,7 +80,8 @@ void ModuleBase_Operation::storeCustomValue() void ModuleBase_Operation::startOperation() { - setFeature(createFeature()); + if (!myIsEditing) + setFeature(createFeature()); //emit callSlot(); //commit(); } @@ -112,10 +113,10 @@ void ModuleBase_Operation::flushCreated() Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED)); } -boost::shared_ptr ModuleBase_Operation::createFeature(const bool theFlushMessage) +FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage) { boost::shared_ptr aDoc = document(); - boost::shared_ptr aFeature = aDoc->addFeature( + FeaturePtr aFeature = aDoc->addFeature( getDescription()->operationId().toStdString()); if (aFeature) // TODO: generate an error if feature was not created aFeature->execute(); @@ -125,7 +126,13 @@ boost::shared_ptr ModuleBase_Operation::createFeature(const bo return aFeature; } -void ModuleBase_Operation::setFeature(boost::shared_ptr theFeature) +void ModuleBase_Operation::setFeature(FeaturePtr theFeature) { myFeature = theFeature; } + +void ModuleBase_Operation::setEditingFeature(FeaturePtr theFeature) +{ + myFeature = theFeature; + myIsEditing = true; +} diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 833dbf57c..a526655a2 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -12,12 +12,13 @@ #include #include +#include "ModelAPI_Feature.h" + #include #include #include -class ModelAPI_Feature; class ModelAPI_Document; class QKeyEvent; @@ -54,7 +55,7 @@ public: QString id() const; /// Returns the operation feature /// \return the feature - boost::shared_ptr feature() const; + FeaturePtr feature() const; /// Returns whether the nested operations are enabled. /// The state can depend on the operation current state. @@ -70,6 +71,11 @@ public: virtual void keyReleased(std::string theName, QKeyEvent* theEvent) {}; + /// Sets the operation feature + void setEditingFeature(FeaturePtr theFeature); + + bool isEditOperation() const { return myIsEditing; } + protected: /// Virtual method called when operation started (see start() method for more description) /// Default impl calls corresponding slot and commits immediately. @@ -91,14 +97,15 @@ protected: /// Creates an operation new feature /// \param theFlushMessage the flag whether the create message should be flushed /// \returns the created feature - virtual boost::shared_ptr createFeature(const bool theFlushMessage = true); + virtual FeaturePtr createFeature(const bool theFlushMessage = true); - /// Returns the operation feature - /// \return the feature - void setFeature(boost::shared_ptr theFeature); + /// Sets the operation feature + void setFeature(FeaturePtr theFeature); private: - boost::shared_ptr myFeature; /// the operation feature to be handled + FeaturePtr myFeature; /// the operation feature to be handled + + bool myIsEditing; }; #endif diff --git a/src/ModuleBase/ModuleBase_SelectorWidget.cpp b/src/ModuleBase/ModuleBase_SelectorWidget.cpp new file mode 100644 index 000000000..f6945234c --- /dev/null +++ b/src/ModuleBase/ModuleBase_SelectorWidget.cpp @@ -0,0 +1,205 @@ +// File: ModuleBase_SelectorWidget.h +// Created: 2 June 2014 +// Author: Vitaly Smetannikov + + +#include "ModuleBase_SelectorWidget.h" +#include "ModuleBase_IWorkshop.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + + +ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData) +: ModuleBase_ModelWidget(theParent), myWorkshop(theWorkshop), myActivateOnStart(false) +{ + myFeatureAttributeID = theData->widgetId(); + + myContainer = new QWidget(theParent); + QHBoxLayout* aLayout = new QHBoxLayout(myContainer); + + aLayout->setContentsMargins(0, 0, 0, 0); + QString aLabelText = QString::fromStdString(theData->widgetLabel()); + QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); + myLabel = new QLabel(aLabelText, myContainer); + myLabel->setPixmap(QPixmap(aLabelIcon)); + + aLayout->addWidget(myLabel); + + QString aToolTip = QString::fromStdString(theData->widgetTooltip()); + myTextLine = new QLineEdit(myContainer); + myTextLine->setReadOnly(true); + myTextLine->setToolTip(aToolTip); + myTextLine->installEventFilter(this); + + aLayout->addWidget(myTextLine); + + myActivateBtn = new QToolButton(myContainer); + myActivateBtn->setIcon(QIcon(":icons/hand_point.png")); + myActivateBtn->setCheckable(true); + myActivateBtn->setToolTip(tr("Activate/Deactivate selection")); + connect(myActivateBtn, SIGNAL(toggled(bool)), this, SLOT(activateSelection(bool))); + + aLayout->addWidget(myActivateBtn); + + QString aActivateTxt = QString::fromStdString(theData->getProperty("activate")); + if (!aActivateTxt.isNull()) { + myActivateOnStart = (aActivateTxt == "true"); + } +} + +//******************************************************************** +ModuleBase_SelectorWidget::~ModuleBase_SelectorWidget() +{ +} + +//******************************************************************** +bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature) const +{ + DataPtr aData = theFeature->data(); + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); + + FeaturePtr aFeature = aRef->value(); + if (!(aFeature && aFeature->isSame(mySelectedFeature))) { + aRef->setValue(mySelectedFeature); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); + } + return true; +} + +//******************************************************************** +bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature) +{ + DataPtr aData = theFeature->data(); + boost::shared_ptr aRef = aData->reference(myFeatureAttributeID); + + bool isBlocked = this->blockSignals(true); + mySelectedFeature = aRef->value(); + updateSelectionName(); + + this->blockSignals(isBlocked); + return true; +} + +//******************************************************************** +QList ModuleBase_SelectorWidget::getControls() const +{ + QList aControls; + aControls.append(myLabel); + aControls.append(myTextLine); + aControls.append(myActivateBtn); + return aControls; +} + +//******************************************************************** +void ModuleBase_SelectorWidget::onSelectionChanged() +{ + QList aFeatures = myWorkshop->selectedFeatures(); + if (aFeatures.size() > 0) { + FeaturePtr aFeature = aFeatures.first(); + if ((!mySelectedFeature) && (!aFeature)) + return; + if (mySelectedFeature && aFeature && mySelectedFeature->isSame(aFeature)) + return; + + // TODO: Check that the selection corresponds to selection type + // TODO: Use the feature kind definition like SKETCH_KIND instead of the direct text + if (aFeature->getKind().compare("Sketch") != 0) + return; + + mySelectedFeature = aFeature; + if (mySelectedFeature) { + updateSelectionName(); + activateSelection(false); + raisePanel(); + } else { + myTextLine->setText(""); + } + emit valuesChanged(); + } +} + +//******************************************************************** +void ModuleBase_SelectorWidget::updateSelectionName() +{ + if (mySelectedFeature) { + std::string aName; + if (mySelectedFeature->data()) + aName = mySelectedFeature->data()->getName(); + else + aName = boost::dynamic_pointer_cast(mySelectedFeature)->getName(); + + myTextLine->setText(QString::fromStdString(aName)); + } else + myTextLine->setText(""); +} + +//******************************************************************** +bool ModuleBase_SelectorWidget::eventFilter(QObject* theObj, QEvent* theEvent) +{ + if (theObj == myTextLine) { + if (theEvent->type() == QEvent::Polish) { + activateSelection(myActivateOnStart); + onSelectionChanged(); + } + } + return ModuleBase_ModelWidget::eventFilter(theObj, theEvent); +} + +//******************************************************************** +void ModuleBase_SelectorWidget::enableOthersControls(bool toEnable) const +{ + QWidget* aParent = myContainer->parentWidget(); + QList aChldList = aParent->findChildren(); + foreach(QWidget* aWgt, aChldList) { + if ((aWgt != myLabel) && (aWgt != myActivateBtn) && (aWgt != myTextLine) && (aWgt != myContainer)) + aWgt->setEnabled(toEnable); + } +} + +//******************************************************************** +void ModuleBase_SelectorWidget::activateSelection(bool toActivate) +{ + enableOthersControls(!toActivate); + myTextLine->setEnabled(toActivate); + + if (toActivate) + connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + else + disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + + myActivateBtn->setDown(toActivate); +} + +//******************************************************************** +void ModuleBase_SelectorWidget::raisePanel() const +{ + QWidget* aParent = myContainer->parentWidget(); + QWidget* aLastPanel = 0; + while (!aParent->inherits("QDockWidget")) { + aLastPanel = aParent; + aParent = aParent->parentWidget(); + if (!aParent) return; + } + if (aParent->inherits("QDockWidget")) { + QDockWidget* aTabWgt = (QDockWidget*) aParent; + aTabWgt->raise(); + } +} \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_SelectorWidget.h b/src/ModuleBase/ModuleBase_SelectorWidget.h new file mode 100644 index 000000000..45ef3d64f --- /dev/null +++ b/src/ModuleBase/ModuleBase_SelectorWidget.h @@ -0,0 +1,80 @@ +// File: ModuleBase_SelectorWidget.h +// Created: 2 June 2014 +// Author: Vitaly Smetannikov + +#ifndef ModuleBase_SelectorWidget_H +#define ModuleBase_SelectorWidget_H + +#include "ModuleBase.h" +#include "ModuleBase_ModelWidget.h" + +#include + + +class Config_WidgetAPI; +class QWidget; +class QLabel; +class QLineEdit; +class QToolButton; +class ModuleBase_IWorkshop; + +class MODULEBASE_EXPORT ModuleBase_SelectorWidget: public ModuleBase_ModelWidget +{ + Q_OBJECT +public: + ModuleBase_SelectorWidget(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData); + + virtual ~ModuleBase_SelectorWidget(); + + /// Saves the internal parameters to the given feature + /// \param theFeature a model feature to be changed + virtual bool storeValue(FeaturePtr theFeature) const; + + virtual bool restoreValue(FeaturePtr theFeature); + + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + QWidget* getControl() const { return myContainer; } + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + + void setActivationOnStart(bool toActivate) { myActivateOnStart = toActivate; } + bool activateOnStart() const { return myActivateOnStart; } + + FeaturePtr selectedFeature() const { return mySelectedFeature; } + +public slots: + + /// Activate or deactivate selection + void activateSelection(bool toActivate); + +protected: + bool eventFilter(QObject* theObj, QEvent* theEvent); + +private slots: + void onSelectionChanged(); + +private: + void enableOthersControls(bool toEnable) const; + void updateSelectionName(); + void raisePanel() const; + + std::string myFeatureAttributeID; + + QWidget* myContainer; + QLabel* myLabel; + QLineEdit* myTextLine; + QToolButton* myActivateBtn; + + ModuleBase_IWorkshop* myWorkshop; + + bool myActivateOnStart; + + FeaturePtr mySelectedFeature; +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 1ef8c83d8..63646b956 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -7,11 +7,12 @@ #include -#include #include #include #include #include +#include +#include #include #include @@ -25,9 +26,6 @@ #include #include #include -#include -#include -#include #ifdef _DEBUG #include @@ -36,8 +34,8 @@ #include #include -ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(ModuleBase_Operation* theOperation) - : myOperation(theOperation) +ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(ModuleBase_Operation* theOperation, ModuleBase_IWorkshop* theWorkshop) + : myOperation(theOperation), myWorkshop(theWorkshop) { QString aXml = myOperation->getDescription()->xmlRepresentation(); myWidgetApi = new Config_WidgetAPI(aXml.toStdString()); @@ -106,7 +104,7 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType { QWidget* result = NULL; if (theType == WDG_DOUBLEVALUE) { - result = doubleSpinBoxControl(); + result = doubleSpinBoxControl(theParent); } else if (theType == WDG_INFO) { result = labelControl(theParent); @@ -149,52 +147,17 @@ QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, Q return result; } -QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl() +QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent) { - QWidget* result = new QWidget(); - QHBoxLayout* aControlLay = new QHBoxLayout(result); - aControlLay->setContentsMargins(0, 0, 0, 0); - QString aLabelText = qs(myWidgetApi->widgetLabel()); - QString aLabelIcon = qs(myWidgetApi->widgetIcon()); - QLabel* aLabel = new QLabel(aLabelText); - aLabel->setPixmap(QPixmap(aLabelIcon)); + ModuleBase_DoubleValueWidget* aDblWgt = new ModuleBase_DoubleValueWidget(theParent, myWidgetApi); + QObject::connect(aDblWgt, SIGNAL(valuesChanged()), myOperation, SLOT(storeCustomValue())); - aControlLay->addWidget(aLabel); - QDoubleSpinBox* aBox = new QDoubleSpinBox(result); - QString anObjName = QString::fromStdString(myWidgetApi->widgetId()); - aBox->setObjectName(anObjName); - bool isOk = false; - std::string aProp = myWidgetApi->getProperty(DOUBLE_WDG_MIN); - double aMinVal = qs(aProp).toDouble(&isOk); - if (isOk) { - aBox->setMinimum(aMinVal); - } else { - aBox->setMinimum(-DBL_MAX); - } - aProp = myWidgetApi->getProperty(DOUBLE_WDG_MAX); - double aMaxVal = qs(aProp).toDouble(&isOk); - if (isOk) { - aBox->setMaximum(aMaxVal); - } else { - aBox->setMaximum(DBL_MAX); - } - aProp = myWidgetApi->getProperty(DOUBLE_WDG_STEP); - double aStepVal = qs(aProp).toDouble(&isOk); - if (isOk) { - aBox->setSingleStep(aStepVal); - } - aProp = myWidgetApi->getProperty(DOUBLE_WDG_DFLT); - double aDefVal = qs(aProp).toDouble(&isOk); - if (isOk) { - aBox->setValue(aDefVal); - } - QString aTTip = qs(myWidgetApi->widgetTooltip()); - aBox->setToolTip(aTTip); - aControlLay->addWidget(aBox); - aControlLay->setStretch(1, 1); - result->setLayout(aControlLay); - connectWidget(aBox, WDG_DOUBLEVALUE); - return result; + myModelWidgets.append(aDblWgt); + + // Init default values + if (!myOperation->isEditOperation()) + aDblWgt->storeValue(myOperation->feature()); + return aDblWgt->getControl(); } QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent) @@ -229,40 +192,24 @@ QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent) { - QWidget* aRes = new QWidget(); - QHBoxLayout* aLayout = new QHBoxLayout(aRes); - - aLayout->setContentsMargins(0, 0, 0, 0); - QString aLabelText = qs(myWidgetApi->widgetLabel()); - QString aLabelIcon = qs(myWidgetApi->widgetIcon()); - QLabel* aLabel = new QLabel(aLabelText, aRes); - aLabel->setPixmap(QPixmap(aLabelIcon)); + ModuleBase_SelectorWidget* aSelector = new ModuleBase_SelectorWidget(theParent, myWorkshop, myWidgetApi); + + QObject::connect(aSelector, SIGNAL(valuesChanged()), myOperation, SLOT(storeCustomValue())); - aLayout->addWidget(aLabel); - - QLineEdit* aTextLine = new QLineEdit(aRes); - aTextLine->setReadOnly(true); - - aLayout->addWidget(aTextLine); - - QToolButton* aActivateBtn = new QToolButton(aRes); - aActivateBtn->setIcon(QIcon(":icons/hand_point.png")); - aActivateBtn->setCheckable(true); - - aLayout->addWidget(aActivateBtn); - - return aRes; + myModelWidgets.append(aSelector); + return aSelector->getControl(); } QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent) { - QString aText = qs(myWidgetApi->widgetLabel()); - QString aToolTip = qs(myWidgetApi->widgetTooltip()); - QString aDefault = qs(myWidgetApi->getProperty("default")); + ModuleBase_BoolValueWidget* aBoolWgt = new ModuleBase_BoolValueWidget(theParent, myWidgetApi); + QObject::connect(aBoolWgt, SIGNAL(valuesChanged()), myOperation, SLOT(storeCustomValue())); + + myModelWidgets.append(aBoolWgt); - QCheckBox* aRes = new QCheckBox(aText, theParent); - aRes->setToolTip(aToolTip); - aRes->setChecked(aDefault == "true"); - return aRes; + // Init default values + if (!myOperation->isEditOperation()) + aBoolWgt->storeValue(myOperation->feature()); + return aBoolWgt->getControl(); } \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index f0303cdae..e20fd2d9c 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -8,8 +8,8 @@ #ifndef ModuleBase_WidgetFactory_H_ #define ModuleBase_WidgetFactory_H_ -#include -#include +#include "ModuleBase.h" +#include "ModuleBase_ModelWidget.h" #include #include @@ -18,11 +18,12 @@ class QObject; class QWidget; class Config_WidgetAPI; class ModuleBase_Operation; +class ModuleBase_IWorkshop; class MODULEBASE_EXPORT ModuleBase_WidgetFactory { public: - ModuleBase_WidgetFactory(ModuleBase_Operation*); + ModuleBase_WidgetFactory(ModuleBase_Operation* theOperation, ModuleBase_IWorkshop* theWorkshop); virtual ~ModuleBase_WidgetFactory(); void createWidget(QWidget* theParent); @@ -36,7 +37,7 @@ protected: //Widgets QWidget* createWidgetByType(const std::string& theType, QWidget* theParent = NULL); QWidget* labelControl(QWidget* theParent); - QWidget* doubleSpinBoxControl(); + QWidget* doubleSpinBoxControl(QWidget* theParent); QWidget* pointSelectorControl(QWidget* theParent); QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL); QWidget* selectorControl(QWidget* theParent); @@ -48,6 +49,7 @@ protected: private: Config_WidgetAPI* myWidgetApi; ModuleBase_Operation* myOperation; + ModuleBase_IWorkshop* myWorkshop; QList myModelWidgets; }; diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index cbc61430a..2d8c81479 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -68,21 +68,22 @@ ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D() { } -bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr theFeature) +bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const { boost::shared_ptr aData = theFeature->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); - bool isBlocked = this->blockSignals(true); + ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this; + bool isBlocked = that->blockSignals(true); aPoint->setValue(myXSpin->value(), myYSpin->value()); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); + that->blockSignals(isBlocked); - this->blockSignals(isBlocked); return true; } -bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr theFeature) +bool ModuleBase_WidgetPoint2D::restoreValue(FeaturePtr theFeature) { boost::shared_ptr aData = theFeature->data(); boost::shared_ptr aPoint = diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h index 1a09516b0..85c4c938d 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.h @@ -34,9 +34,9 @@ public: /// Saves the internal parameters to the given feature /// \param theFeature a model feature to be changed - virtual bool storeValue(boost::shared_ptr theFeature); + virtual bool storeValue(FeaturePtr theFeature) const; - virtual bool restoreValue(boost::shared_ptr theFeature); + virtual bool restoreValue(FeaturePtr theFeature); /// Returns whether the widget can accept focus, or if it corresponds to the given attribute /// \param theAttribute name diff --git a/src/ModuleBase/ModuleBase_Widgets.cpp b/src/ModuleBase/ModuleBase_Widgets.cpp new file mode 100644 index 000000000..0d810ece1 --- /dev/null +++ b/src/ModuleBase/ModuleBase_Widgets.cpp @@ -0,0 +1,170 @@ +// File: ModuleBase_Widgets.h +// Created: 04 June 2014 +// Author: Vitaly Smetannikov + +#include "ModuleBase_Widgets.h" + +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + + +ModuleBase_DoubleValueWidget::ModuleBase_DoubleValueWidget(QWidget* theParent, const Config_WidgetAPI* theData) + : ModuleBase_ModelWidget(theParent) +{ + myContainer = new QWidget(theParent); + QHBoxLayout* aControlLay = new QHBoxLayout(myContainer); + aControlLay->setContentsMargins(0, 0, 0, 0); + + QString aLabelText = QString::fromStdString(theData->widgetLabel()); + QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); + myLabel = new QLabel(aLabelText, myContainer); + myLabel->setPixmap(QPixmap(aLabelIcon)); + aControlLay->addWidget(myLabel); + + myAttributeID = theData->widgetId(); + mySpinBox = new QDoubleSpinBox(myContainer); + QString anObjName = QString::fromStdString(myAttributeID); + mySpinBox->setObjectName(anObjName); + + bool isOk = false; + std::string aProp = theData->getProperty(DOUBLE_WDG_MIN); + double aMinVal = QString::fromStdString(aProp).toDouble(&isOk); + if (isOk) { + mySpinBox->setMinimum(aMinVal); + } else { + mySpinBox->setMinimum(-DBL_MAX); + } + + aProp = theData->getProperty(DOUBLE_WDG_MAX); + double aMaxVal = QString::fromStdString(aProp).toDouble(&isOk); + if (isOk) { + mySpinBox->setMaximum(aMaxVal); + } else { + mySpinBox->setMaximum(DBL_MAX); + } + + aProp = theData->getProperty(DOUBLE_WDG_STEP); + double aStepVal = QString::fromStdString(aProp).toDouble(&isOk); + if (isOk) { + mySpinBox->setSingleStep(aStepVal); + } + + aProp = theData->getProperty(DOUBLE_WDG_DFLT); + double aDefVal = QString::fromStdString(aProp).toDouble(&isOk); + if (isOk) { + mySpinBox->setValue(aDefVal); + } + + QString aTTip = QString::fromStdString(theData->widgetTooltip()); + mySpinBox->setToolTip(aTTip); + + aControlLay->addWidget(mySpinBox); + aControlLay->setStretch(1, 1); + + connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); +} + +ModuleBase_DoubleValueWidget::~ModuleBase_DoubleValueWidget() +{ +} + +bool ModuleBase_DoubleValueWidget::storeValue(FeaturePtr theFeature) const +{ + DataPtr aData = theFeature->data(); + boost::shared_ptr aReal = aData->real(myAttributeID); + if (aReal->value() != mySpinBox->value()) { + aReal->setValue(mySpinBox->value()); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); + } + return true; +} + +bool ModuleBase_DoubleValueWidget::restoreValue(FeaturePtr theFeature) +{ + DataPtr aData = theFeature->data(); + boost::shared_ptr aRef = aData->real(myAttributeID); + + bool isBlocked = mySpinBox->blockSignals(true); + mySpinBox->setValue(aRef->value()); + mySpinBox->blockSignals(isBlocked); + + return true; +} + +QList ModuleBase_DoubleValueWidget::getControls() const +{ + QList aList; + aList.append(myLabel); + aList.append(mySpinBox); + return aList; +} + + +////////////////////////////////////////////////////////////////////////////////// +ModuleBase_BoolValueWidget::ModuleBase_BoolValueWidget(QWidget* theParent, const Config_WidgetAPI* theData) + : ModuleBase_ModelWidget(theParent) +{ + myAttributeID = theData->widgetId(); + QString aText = QString::fromStdString(theData->widgetLabel()); + QString aToolTip = QString::fromStdString(theData->widgetTooltip()); + QString aDefault = QString::fromStdString(theData->getProperty("default")); + + myCheckBox = new QCheckBox(aText, theParent); + myCheckBox->setToolTip(aToolTip); + myCheckBox->setChecked(aDefault == "true"); + + connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged())); +} + +ModuleBase_BoolValueWidget::~ModuleBase_BoolValueWidget() +{ +} + +QWidget* ModuleBase_BoolValueWidget::getControl() const +{ + return myCheckBox; +} + +bool ModuleBase_BoolValueWidget::storeValue(FeaturePtr theFeature) const +{ + DataPtr aData = theFeature->data(); + boost::shared_ptr aBool = aData->boolean(myAttributeID); + + if (aBool->value() != myCheckBox->isChecked()) { + aBool->setValue(myCheckBox->isChecked()); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); + } + return true; +} + +bool ModuleBase_BoolValueWidget::restoreValue(FeaturePtr theFeature) +{ + DataPtr aData = theFeature->data(); + boost::shared_ptr aRef = aData->boolean(myAttributeID); + + bool isBlocked = myCheckBox->blockSignals(true); + myCheckBox->setChecked(aRef->value()); + myCheckBox->blockSignals(isBlocked); + + return true; +} + +QList ModuleBase_BoolValueWidget::getControls() const +{ + QList aList; + aList.append(myCheckBox); + return aList; +} diff --git a/src/ModuleBase/ModuleBase_Widgets.h b/src/ModuleBase/ModuleBase_Widgets.h new file mode 100644 index 000000000..d8030f9ab --- /dev/null +++ b/src/ModuleBase/ModuleBase_Widgets.h @@ -0,0 +1,78 @@ +// File: ModuleBase_Widgets.h +// Created: 04 June 2014 +// Author: Vitaly Smetannikov + +#ifndef ModuleBase_Widgets_H +#define ModuleBase_Widgets_H + +#include "ModuleBase.h" +#include "ModuleBase_ModelWidget.h" + +class Config_WidgetAPI; +class QWidget; +class QLabel; +class QDoubleSpinBox; +class QCheckBox; + +class MODULEBASE_EXPORT ModuleBase_DoubleValueWidget: public ModuleBase_ModelWidget +{ + Q_OBJECT +public: + ModuleBase_DoubleValueWidget(QWidget* theParent, const Config_WidgetAPI* theData); + + virtual ~ModuleBase_DoubleValueWidget(); + + /// Saves the internal parameters to the given feature + /// \param theFeature a model feature to be changed + virtual bool storeValue(FeaturePtr theFeature) const; + + virtual bool restoreValue(FeaturePtr theFeature); + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + QWidget* getControl() const { return myContainer; } + +private: + std::string myAttributeID; + + QWidget* myContainer; + QLabel* myLabel; + QDoubleSpinBox* mySpinBox; +}; + + +////////////////////////////////////////////////////////////////////////////////// + +class MODULEBASE_EXPORT ModuleBase_BoolValueWidget: public ModuleBase_ModelWidget +{ + Q_OBJECT +public: + ModuleBase_BoolValueWidget(QWidget* theParent, const Config_WidgetAPI* theData); + + virtual ~ModuleBase_BoolValueWidget(); + + /// Saves the internal parameters to the given feature + /// \param theFeature a model feature to be changed + virtual bool storeValue(FeaturePtr theFeature) const; + + virtual bool restoreValue(FeaturePtr theFeature); + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + QWidget* getControl() const; + +private: + std::string myAttributeID; + + QCheckBox* myCheckBox; +}; + +#endif \ No newline at end of file diff --git a/src/NewGeom/CMakeLists.txt b/src/NewGeom/CMakeLists.txt index 4eee4a294..27b7c58f4 100644 --- a/src/NewGeom/CMakeLists.txt +++ b/src/NewGeom/CMakeLists.txt @@ -1,6 +1,4 @@ -INCLUDE(FindCAS) - SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 9ccf4e46b..fe69c3399 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -1,27 +1,33 @@ INCLUDE(Common) -INCLUDE(FindCAS) SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS PartSet.h + PartSet_Constants.h + PartSet_FeaturePrs.h PartSet_Listener.h PartSet_Module.h + PartSet_OperationConstraint.h + PartSet_OperationCreateFeature.h PartSet_OperationEditLine.h PartSet_OperationSketchBase.h PartSet_OperationSketch.h - PartSet_OperationSketchLine.h + PartSet_Presentation.h PartSet_TestOCC.h PartSet_Tools.h ) SET(PROJECT_SOURCES + PartSet_FeaturePrs.cpp PartSet_Listener.cpp PartSet_Module.cpp + PartSet_OperationConstraint.cpp + PartSet_OperationCreateFeature.cpp PartSet_OperationEditLine.cpp PartSet_OperationSketchBase.cpp PartSet_OperationSketch.cpp - PartSet_OperationSketchLine.cpp + PartSet_Presentation.cpp PartSet_TestOCC.cpp PartSet_Tools.cpp ) diff --git a/src/PartSet/PartSet_Constants.h b/src/PartSet/PartSet_Constants.h new file mode 100644 index 000000000..95b28bd00 --- /dev/null +++ b/src/PartSet/PartSet_Constants.h @@ -0,0 +1,21 @@ +// File: PartSet_Tools.h +// Created: 04 Jun 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_Constants_H +#define PartSet_Constants_H + +#include + +/// This file contains various constants used in the PartSet module + +/// Types of viewer selection in an operation +enum PartSet_SelectionMode +{ + SM_FirstPoint, + SM_SecondPoint, + SM_DonePoint +}; + + +#endif diff --git a/src/PartSet/PartSet_FeaturePrs.cpp b/src/PartSet/PartSet_FeaturePrs.cpp new file mode 100644 index 000000000..434dd94e4 --- /dev/null +++ b/src/PartSet/PartSet_FeaturePrs.cpp @@ -0,0 +1,224 @@ +// File: PartSet_FeaturePrs.h +// Created: 04 Jun 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +using namespace std; + +PartSet_FeaturePrs::PartSet_FeaturePrs(FeaturePtr theFeature) +: mySketch(theFeature) +{ +} + +PartSet_FeaturePrs::~PartSet_FeaturePrs() +{ +} + +void PartSet_FeaturePrs::init(FeaturePtr theFeature, FeaturePtr theSourceFeature) +{ + myFeature = theFeature; + if (theSourceFeature) + { + // use the last point of the previous feature as the first of the new one + boost::shared_ptr aData = theSourceFeature->data(); + boost::shared_ptr anInitPoint = boost::dynamic_pointer_cast + (aData->attribute(LINE_ATTR_END)); + setLinePoint(theFeature, anInitPoint->x(), anInitPoint->y(), LINE_ATTR_START); + setLinePoint(theFeature, anInitPoint->x(), anInitPoint->y(), LINE_ATTR_END); + + aData = theFeature->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast + (aData->attribute(LINE_ATTR_START)); + createConstraint(anInitPoint, aPoint); + } +} + +boost::shared_ptr PartSet_FeaturePrs::document() const +{ + return ModelAPI_PluginManager::get()->rootDocument(); +} + +FeaturePtr PartSet_FeaturePrs::sketch() const +{ + return mySketch; +} + +PartSet_SelectionMode PartSet_FeaturePrs::setPoint(double theX, double theY, + const PartSet_SelectionMode& theMode) +{ + PartSet_SelectionMode aMode = theMode; + switch (theMode) + { + case SM_FirstPoint: { + setLinePoint(feature(), theX, theY, LINE_ATTR_START); + setLinePoint(feature(), theX, theY, LINE_ATTR_END); + aMode = SM_SecondPoint; + } + break; + case SM_SecondPoint: { + setLinePoint(feature(), theX, theY, LINE_ATTR_END); + aMode = SM_DonePoint; + } + break; + default: + break; + } + return aMode; +} + +FeaturePtr PartSet_FeaturePrs::feature() const +{ + return myFeature; +} + +void PartSet_FeaturePrs::createConstraint(boost::shared_ptr thePoint1, + boost::shared_ptr thePoint2) +{ + boost::shared_ptr aDoc = document(); + FeaturePtr aFeature = aDoc->addFeature(SKETCH_CONSTRAINT_COINCIDENCE_KIND); + + if (sketch()) { + boost::shared_ptr aSketch = + boost::dynamic_pointer_cast(sketch()); + aSketch->addSub(aFeature); + } + + boost::shared_ptr aData = aFeature->data(); + + boost::shared_ptr aRef1 = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + aRef1->setAttr(thePoint1); + + boost::shared_ptr aRef2 = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); + aRef2->setAttr(thePoint2); + + if (aFeature) // TODO: generate an error if feature was not created + aFeature->execute(); +} + +void PartSet_FeaturePrs::setConstraints(double theX, double theY, + const PartSet_SelectionMode& theMode) +{ + std::string aPointArg; + switch (theMode) + { + case SM_FirstPoint: + aPointArg = LINE_ATTR_START; + break; + case SM_SecondPoint: + aPointArg = LINE_ATTR_END; + break; + default: + break; + } + + FeaturePtr aSkFeature = feature(); + + boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast + (aData->attribute(aPointArg)); + aData = sketch()->data(); + boost::shared_ptr aRefList = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_FEATURES)); + + std::list aFeatures = aRefList->list(); + std::list::const_iterator anIt = aFeatures.begin(), + aLast = aFeatures.end(); + for (; anIt != aLast; anIt++) { + FeaturePtr aFeature = *anIt; + boost::shared_ptr aFPoint = findLinePoint(aFeature, theX, theY); + if (aFPoint) + createConstraint(aFPoint, aPoint); + } +} + +std::string PartSet_FeaturePrs::getAttribute(const PartSet_SelectionMode& theMode) const +{ + std::string aAttribute; + switch (theMode) + { + case SM_FirstPoint: + aAttribute = LINE_ATTR_START; + break; + case SM_SecondPoint: + aAttribute = LINE_ATTR_END; + break; + default: + break; + } + return aAttribute; +} + +PartSet_SelectionMode PartSet_FeaturePrs::getNextMode(const std::string& theAttribute) const +{ + PartSet_SelectionMode aMode; + + if (theAttribute == LINE_ATTR_START) + aMode = SM_SecondPoint; + else if (theAttribute == LINE_ATTR_END) + aMode = SM_DonePoint; + return aMode; +} + +void PartSet_FeaturePrs::getLinePoint(FeaturePtr theFeature, + const std::string& theAttribute, + double& theX, double& theY) +{ + if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) + return; + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + theX = aPoint->x(); + theY = aPoint->y(); +} + +boost::shared_ptr PartSet_FeaturePrs::findLinePoint( + FeaturePtr theFeature, + double theX, double theY) +{ + boost::shared_ptr aPoint2D; + if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) + return aPoint2D; + boost::shared_ptr aData = theFeature->data(); + + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) + aPoint2D = aPoint; + else { + aPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) + aPoint2D = aPoint; + } + return aPoint2D; +} + +void PartSet_FeaturePrs::setLinePoint(FeaturePtr theFeature, + double theX, double theY, + const std::string& theAttribute) +{ + if (!theFeature) + return; + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + aPoint->setValue(theX, theY); +} diff --git a/src/PartSet/PartSet_FeaturePrs.h b/src/PartSet/PartSet_FeaturePrs.h new file mode 100644 index 000000000..0a285f522 --- /dev/null +++ b/src/PartSet/PartSet_FeaturePrs.h @@ -0,0 +1,102 @@ +// File: PartSet_FeaturePrs.h +// Created: 04 Jun 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_FeaturePrs_H +#define PartSet_FeaturePrs_H + +#include "PartSet.h" + +#include "PartSet_Constants.h" + +class GeomDataAPI_Point2D; + +/*! + \class PartSet_FeaturePrs + * \brief The abstract class to define the specific feature manipulation. It is created for + * the feature create operation to move out the feature properties set and use one operation + * for any type of features. +*/ +class PARTSET_EXPORT PartSet_FeaturePrs +{ +public: + /// Constructor + /// \param theSketch the sketch feature + PartSet_FeaturePrs(FeaturePtr theSketch); + /// Destructor + virtual ~PartSet_FeaturePrs(); + + /// Initializes some fields of feature accorging to the source feature + /// Saves the fiature as the presentation internal feature + /// \param theFeature the presentation feature + /// \param theSourceFeature the feature, which attributes are used to initialize the feature + virtual void init(FeaturePtr theFeature, FeaturePtr theSourceFeature); + + /// Returns the operation sketch feature + /// \returns the sketch instance + FeaturePtr sketch() const; + + /// Sets the point to the feature in an attribute depending on the selection mode + /// \param theX the 2D point horizontal coordinate + /// \param theY the 2D point vertical coordinate + /// \param theMode the selection mode + /// \return the new selection mode + PartSet_SelectionMode setPoint(double theX, double theY, const PartSet_SelectionMode& theMode); + + /// Creates constrains of the current + /// \param theX the horizontal coordnate of the point + /// \param theY the vertical coordnate of the point + /// \param theMode the current operation selection mode. The feature attribute depends on the mode + void setConstraints(double theX, double theY, const PartSet_SelectionMode& theMode); + + /// Returns the feature attribute name for the selection mode + /// \param theMode the current operation selection mode. The feature attribute depends on the mode + std::string getAttribute(const PartSet_SelectionMode& theMode) const; + + /// Returns the next selection mode after the attribute + /// \param theAttribute the feature attribute name + /// \return next attribute selection mode + PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; + + /// \brief Save the point to the line. + /// \param theFeature the line feature + /// \param theX the horizontal coordinate + /// \param theY the vertical coordinate + /// \param theAttribute the start or end attribute of the line + static void setLinePoint(FeaturePtr, double theX, double theY, + const std::string& theAttribute); + +protected: + /// Returns pointer to the root document. + boost::shared_ptr document() const; + + /// Returns the operation feature + /// \return the feature + FeaturePtr feature() const; + + /// Creates a constraint on two points + /// \param thePoint1 the first point + /// \param thePoint1 the second point + void createConstraint(boost::shared_ptr thePoint1, + boost::shared_ptr thePoint2); + + /// \brief Get the line point 2d coordinates. + /// \param theFeature the line feature + /// \param theAttribute the start or end attribute of the line + /// \param theX the horizontal coordinate + /// \param theY the vertical coordinate + void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute, + double& theX, double& theY); + /// Find a point in the line with given coordinates + /// \param theFeature the line feature + /// \param theX the horizontal point coordinate + /// \param theY the vertical point coordinate + boost::shared_ptr findLinePoint(FeaturePtr theFeature, + double theX, double theY); + +private: + FeaturePtr mySketch; ///< the sketch of the feature + FeaturePtr myFeature; ///< the feature +}; + +#endif diff --git a/src/PartSet/PartSet_Listener.cpp b/src/PartSet/PartSet_Listener.cpp index fbe248532..1f3505ee7 100644 --- a/src/PartSet/PartSet_Listener.cpp +++ b/src/PartSet/PartSet_Listener.cpp @@ -11,6 +11,8 @@ #include #include +#include + #ifdef _DEBUG #include #endif @@ -39,19 +41,18 @@ void PartSet_Listener::processEvent(const Events_Message* theMessage) { const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast (theMessage); - std::set > aFeatures = aUpdMsg->features(); - std::set >::const_iterator anIt = aFeatures.begin(), - aLast = aFeatures.end(); + std::set aFeatures = aUpdMsg->features(); + std::set::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); for (; anIt != aLast; anIt++) { - boost::shared_ptr aFeature = *anIt; - if (myModule->workshop()->displayer()->IsVisible(aFeature) || + FeaturePtr aFeature = *anIt; + if (myModule->workshop()->displayer()->isVisible(aFeature) || aType == EVENT_FEATURE_CREATED) { myModule->visualizePreview(aFeature, true, false); //if (aType == EVENT_FEATURE_CREATED) myModule->activateFeature(aFeature, true); } } - myModule->workshop()->displayer()->UpdateViewer(); + myModule->workshop()->displayer()->updateViewer(); } if (aType == EVENT_FEATURE_DELETED) { @@ -62,8 +63,8 @@ void PartSet_Listener::processEvent(const Events_Message* theMessage) std::set::const_iterator anIt = aGroups.begin(), aLast = aGroups.end(); for (; anIt != aLast; anIt++) { std::string aGroup = *anIt; - if (aGroup.compare("Sketch") == 0) { // Update only Sketch group - myModule->workshop()->displayer()->EraseDeletedFeatures(); + if (aGroup.compare(SKETCH_KIND) == 0) { // Update only Sketch group + myModule->workshop()->displayer()->eraseDeletedFeatures(); myModule->updateCurrentPreview(aGroup); } } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 99cab29e5..83b8fbe74 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1,11 +1,13 @@ #include #include -#include +#include #include +#include #include #include #include #include +#include #include #include @@ -33,6 +35,7 @@ #include #include +#include #include #include @@ -167,8 +170,8 @@ void PartSet_Module::onMousePressed(QMouseEvent* theEvent) if (aPreviewOp) { XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - std::list aSelected = aDisplayer->GetSelected(); - std::list aHighlighted = aDisplayer->GetHighlighted(); + std::list aSelected = aDisplayer->getSelected(); + std::list aHighlighted = aDisplayer->getHighlighted(); aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); } @@ -181,8 +184,8 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) if (aPreviewOp) { XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - std::list aSelected = aDisplayer->GetSelected(); - std::list aHighlighted = aDisplayer->GetHighlighted(); + std::list aSelected = aDisplayer->getSelected(); + std::list aHighlighted = aDisplayer->getHighlighted(); aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); } @@ -218,7 +221,7 @@ void PartSet_Module::onFitAllView() myWorkshop->viewer()->fitAll(); } -void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr theFeature) +void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeature) { ModuleBase_Operation* anOperation = createOperation(theName.c_str()); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); @@ -226,9 +229,11 @@ void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptrdisplayer(); // refill the features list with avoiding of the features, obtained only by vertex shape (TODO) - std::list aSelected = aDisplayer->GetSelected(TopAbs_VERTEX); - std::list aHighlighted = aDisplayer->GetHighlighted(TopAbs_VERTEX); + std::list aSelected = aDisplayer->getSelected(TopAbs_VERTEX); + std::list aHighlighted = aDisplayer->getHighlighted(TopAbs_VERTEX); aPreviewOp->init(theFeature, aSelected, aHighlighted); + } else { + anOperation->setEditingFeature(theFeature); } sendOperation(anOperation); myWorkshop->actionsMgr()->updateCheckState(); @@ -245,54 +250,52 @@ void PartSet_Module::onStopSelection(const std::list& theFeature XGUI_Displayer* aDisplayer = myWorkshop->displayer(); if (!isStop) { std::list::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end(); - boost::shared_ptr aFeature; + FeaturePtr aFeature; for (; anIt != aLast; anIt++) { activateFeature((*anIt).feature(), false); } } - aDisplayer->StopSelection(theFeatures, isStop, false); + aDisplayer->stopSelection(theFeatures, isStop, false); XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); aViewer->enableSelection(!isStop); - aDisplayer->UpdateViewer(); + aDisplayer->updateViewer(); } void PartSet_Module::onSetSelection(const std::list& theFeatures) { XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - aDisplayer->SetSelected(theFeatures, false); - aDisplayer->UpdateViewer(); + aDisplayer->setSelected(theFeatures, false); + aDisplayer->updateViewer(); } void PartSet_Module::onCloseLocalContext() { XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - aDisplayer->CloseLocalContexts(); + aDisplayer->closeLocalContexts(); } -void PartSet_Module::onFeatureConstructed(boost::shared_ptr theFeature, - int theMode) +void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode) { bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide; visualizePreview(theFeature, isDisplay, false); if (!isDisplay) { ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation(); - boost::shared_ptr aSketch; + FeaturePtr aSketch; PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); if (aPrevOp) { - std::map, boost::shared_ptr > - aList = aPrevOp->subPreview(); + std::map > aList = aPrevOp->subPreview(); XGUI_Displayer* aDisplayer = myWorkshop->displayer(); std::list aModes = aPrevOp->getSelectionModes(aPrevOp->feature()); - std::map, boost::shared_ptr >::const_iterator + std::map >::const_iterator anIt = aList.begin(), aLast = aList.end(); for (; anIt != aLast; anIt++) { - boost::shared_ptr aFeature = (*anIt).first; + FeaturePtr aFeature = (*anIt).first; visualizePreview(aFeature, false, false); } - aDisplayer->UpdateViewer(); + aDisplayer->updateViewer(); } } @@ -306,7 +309,7 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI // get operation xml description std::string aStdCmdId = theCmdId; if (aStdCmdId == PartSet_OperationEditLine::Type()) - aStdCmdId = PartSet_OperationSketchLine::Type(); + aStdCmdId = SKETCH_LINE_KIND; std::string aPluginFileName = featureFile(aStdCmdId); Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName); aWdgReader.readAll(); @@ -314,23 +317,25 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI std::string aDescription = aWdgReader.featureDescription(aStdCmdId); // create the operation - ModuleBase_Operation* anOperation; + ModuleBase_Operation* anOperation = 0; if (theCmdId == PartSet_OperationSketch::Type()) { anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this); } - else if(theCmdId == PartSet_OperationSketchLine::Type() || - theCmdId == PartSet_OperationEditLine::Type()) { + else { ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation(); - boost::shared_ptr aSketch; + FeaturePtr aSketch; PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); if (aPrevOp) aSketch = aPrevOp->sketch(); - if (theCmdId == PartSet_OperationSketchLine::Type()) - anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch); - else + if (theCmdId == SKETCH_LINE_KIND) + anOperation = new PartSet_OperationCreateFeature(theCmdId.c_str(), this, aSketch); + else if (theCmdId == PartSet_OperationEditLine::Type()) anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch); + else if (theCmdId == PartSet_OperationConstraint::Type()) + anOperation = new PartSet_OperationConstraint(theCmdId.c_str(), this, aSketch); } - else { + + if (!anOperation) { anOperation = new ModuleBase_Operation(theCmdId.c_str(), this); } anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg)); @@ -339,10 +344,10 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI // connect the operation PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { - connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr, int)), - this, SLOT(onFeatureConstructed(boost::shared_ptr, int))); - connect(aPreviewOp, SIGNAL(launchOperation(std::string, boost::shared_ptr)), - this, SLOT(onLaunchOperation(std::string, boost::shared_ptr))); + connect(aPreviewOp, SIGNAL(featureConstructed(FeaturePtr, int)), + this, SLOT(onFeatureConstructed(FeaturePtr, int))); + connect(aPreviewOp, SIGNAL(launchOperation(std::string, FeaturePtr)), + this, SLOT(onLaunchOperation(std::string, FeaturePtr))); connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this, SLOT(onMultiSelectionEnabled(bool))); @@ -377,7 +382,7 @@ void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation) Events_Loop::loop()->send(aMessage); } -void PartSet_Module::visualizePreview(boost::shared_ptr theFeature, bool isDisplay, +void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay, const bool isUpdateViewer) { ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); @@ -391,24 +396,31 @@ void PartSet_Module::visualizePreview(boost::shared_ptr theFea XGUI_Displayer* aDisplayer = myWorkshop->displayer(); if (isDisplay) { boost::shared_ptr aPreview = aPreviewOp->preview(theFeature); - aDisplayer->Redisplay(theFeature, - aPreview ? aPreview->impl() : TopoDS_Shape(), false); + Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( + theFeature, aPreviewOp->sketch(), + aPreview ? aPreview->impl() : TopoDS_Shape(), + aDisplayer->getAISObject(theFeature)); + + int aSelectionMode = -1; + if (theFeature->getKind() == SKETCH_CONSTRAINT_LENGTH_KIND) { + aSelectionMode = AIS_DSM_Text; + } + aDisplayer->redisplay(theFeature, anAIS, aSelectionMode, false); } else - aDisplayer->Erase(theFeature, false); + aDisplayer->erase(theFeature, false); if (isUpdateViewer) - aDisplayer->UpdateViewer(); + aDisplayer->updateViewer(); } -void PartSet_Module::activateFeature(boost::shared_ptr theFeature, - const bool isUpdateViewer) +void PartSet_Module::activateFeature(FeaturePtr theFeature, const bool isUpdateViewer) { ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - aDisplayer->ActivateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature), + aDisplayer->activateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature), isUpdateViewer); } } @@ -423,25 +435,28 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) if (!aPreviewOp) return; - boost::shared_ptr aFeature = aPreviewOp->feature(); + FeaturePtr aFeature = aPreviewOp->feature(); if (!aFeature || aFeature->getKind() != theCmdId) return; - std::map, boost::shared_ptr > - aList = aPreviewOp->subPreview(); + std::map > aList = aPreviewOp->subPreview(); XGUI_Displayer* aDisplayer = myWorkshop->displayer(); std::list aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature()); - std::map, boost::shared_ptr >::const_iterator + std::map >::const_iterator anIt = aList.begin(), aLast = aList.end(); for (; anIt != aLast; anIt++) { - boost::shared_ptr aFeature = (*anIt).first; + FeaturePtr aFeature = (*anIt).first; boost::shared_ptr aPreview = (*anIt).second; - aDisplayer->Redisplay(aFeature, - aPreview ? aPreview->impl() : TopoDS_Shape(), false); - aDisplayer->ActivateInLocalContext(aFeature, aModes, false); + Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( + aFeature, aPreviewOp->sketch(), + aPreview ? aPreview->impl() : TopoDS_Shape(), + aDisplayer->getAISObject(aFeature)); + if (!anAIS.IsNull()) + aDisplayer->redisplay(aFeature, anAIS, -1, false); + aDisplayer->activateInLocalContext(aFeature, aModes, false); } - aDisplayer->UpdateViewer(); + aDisplayer->updateViewer(); } void PartSet_Module::editFeature(FeaturePtr theFeature) @@ -449,7 +464,7 @@ void PartSet_Module::editFeature(FeaturePtr theFeature) if (!theFeature) return; - if (theFeature->getKind() == "Sketch") { +// if (theFeature->getKind() == SKETCH_KIND) { FeaturePtr aFeature = theFeature; if (XGUI_Tools::isModelObject(aFeature)) { ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); @@ -460,5 +475,5 @@ void PartSet_Module::editFeature(FeaturePtr theFeature) onLaunchOperation(aFeature->getKind(), aFeature); updateCurrentPreview(aFeature->getKind()); } - } +// } } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index d92604bbb..f906f939a 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -44,13 +44,13 @@ public: /// \param theFeature the feature instance to be displayed /// \param isDisplay the state whether the presentation should be displayed or erased /// \param isUpdateViewer the flag whether the viewer should be updated - void visualizePreview(boost::shared_ptr theFeature, bool isDisplay, + void visualizePreview(FeaturePtr theFeature, bool isDisplay, const bool isUpdateViewer = true); /// Activates the feature in the displayer /// \param theFeature the feature instance to be displayed /// \param isUpdateViewer the flag whether the viewer should be updated - void activateFeature(boost::shared_ptr theFeature, + void activateFeature(FeaturePtr theFeature, const bool isUpdateViewer); /// Updates current operation preview, if it has it. @@ -92,7 +92,7 @@ public slots: /// SLOT, to fit all current viewer void onFitAllView(); - void onLaunchOperation(std::string theName, boost::shared_ptr theFeature); + void onLaunchOperation(std::string theName, FeaturePtr theFeature); /// SLOT, to switch on/off the multi selection in the viewer /// \param theEnabled the enabled state @@ -113,7 +113,7 @@ public slots: /// SLOT, to visualize the feature in another local context mode /// \param theFeature the feature to be put in another local context mode /// \param theMode the mode appeared on the feature - void onFeatureConstructed(boost::shared_ptr theFeature, + void onFeatureConstructed(FeaturePtr theFeature, int theMode); protected: /// Creates a new operation diff --git a/src/PartSet/PartSet_OperationConstraint.cpp b/src/PartSet/PartSet_OperationConstraint.cpp new file mode 100644 index 000000000..6c65c0eac --- /dev/null +++ b/src/PartSet/PartSet_OperationConstraint.cpp @@ -0,0 +1,274 @@ +// File: PartSet_OperationConstraint.h +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include +#include + +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#ifdef _DEBUG +#include +#endif + +#include + +using namespace std; + +PartSet_OperationConstraint::PartSet_OperationConstraint(const QString& theId, + QObject* theParent, + FeaturePtr theFeature) +: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature) +{ +} + +PartSet_OperationConstraint::~PartSet_OperationConstraint() +{ +} + +bool PartSet_OperationConstraint::isGranted(ModuleBase_IOperation* theOperation) const +{ + return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type(); +} + +void PartSet_OperationConstraint::init(FeaturePtr theFeature, + const std::list& /*theSelected*/, + const std::list& /*theHighlighted*/) +{ + //if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) + // return; + // use the last point of the previous feature as the first of the new one + //boost::shared_ptr aData = theFeature->data(); + //myInitPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); +} + +FeaturePtr PartSet_OperationConstraint::sketch() const +{ + return mySketch; +} + +void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& theSelected, + const std::list& /*theHighlighted*/) +{ + /*if (myPointSelectionMode == SM_DonePoint) + { + // if the point creation is finished, the next mouse release should commit the modification + // the next release can happens by double click in the viewer + commit(); + restartOperation(PartSet_OperationConstraint::Type(), feature()); + return; + } + + double aX, anY; + + bool isFoundPoint = false; + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); +*/ + if (theSelected.empty()) { + //PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); + //isFoundPoint = true; + } + else { + XGUI_ViewerPrs aPrs = theSelected.front(); + FeaturePtr aFeature = aPrs.feature(); + + setFeature(aFeature); + setValue(120); + flushUpdated(); + + /*const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) // the point is selected + { + if (aShape.ShapeType() == TopAbs_VERTEX) { + const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); + if (!aVertex.IsNull()) { + aPoint = BRep_Tool::Pnt(aVertex); + PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); + isFoundPoint = true; + + setConstraints(aX, anY); + } + } + else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected + { + FeaturePtr aFeature = aPrs.feature(); + if (aFeature) { + double X0, X1, X2, X3; + double Y0, Y1, Y2, Y3; + getLinePoint(aFeature, LINE_ATTR_START, X2, Y2); + getLinePoint(aFeature, LINE_ATTR_END, X3, Y3); + PartSet_Tools::convertTo2D(aPoint, sketch(), theView, X1, Y1); + + switch (myPointSelectionMode) { + case SM_FirstPoint: + PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY); + break; + case SM_SecondPoint: { + getLinePoint(feature(), LINE_ATTR_START, X0, Y0); + PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY); + } + break; + default: + break; + } + isFoundPoint = true; + } + } + }*/ + } + + /*switch (myPointSelectionMode) + { + case SM_FirstPoint: { + setLinePoint(feature(), aX, anY, LINE_ATTR_START); + setLinePoint(feature(), aX, anY, LINE_ATTR_END); + flushUpdated(); + + //setPointSelectionMode(SM_SecondPoint); + } + break; + case SM_SecondPoint: { + setLinePoint(feature(), aX, anY, LINE_ATTR_END); + flushUpdated(); + + //setPointSelectionMode(SM_DonePoint); + } + break; + default: + break; + }*/ +} + +void PartSet_OperationConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) +{ +/* switch (myPointSelectionMode) + { + case SM_FirstPoint: { + double aX, anY; + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); + PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); + setLinePoint(feature(), aX, anY, LINE_ATTR_START); + setLinePoint(feature(), aX, anY, LINE_ATTR_END); + flushUpdated(); + emit focusActivated(LINE_ATTR_START); + } + break; + case SM_SecondPoint: + { + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); + setLinePoint(aPoint, theView, LINE_ATTR_END); + flushUpdated(); + emit focusActivated(LINE_ATTR_END); + } + break; + case SM_DonePoint: + { + commit(); + restartOperation(PartSet_OperationConstraint::Type(), feature()); + } + default: + break; + }*/ +} + +void PartSet_OperationConstraint::startOperation() +{ + PartSet_OperationSketchBase::startOperation(); + //setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint); + + emit multiSelectionEnabled(false); +} + +void PartSet_OperationConstraint::abortOperation() +{ + emit featureConstructed(feature(), FM_Hide); + PartSet_OperationSketchBase::abortOperation(); +} + +void PartSet_OperationConstraint::stopOperation() +{ + PartSet_OperationSketchBase::stopOperation(); + emit multiSelectionEnabled(true); +} + +void PartSet_OperationConstraint::afterCommitOperation() +{ + PartSet_OperationSketchBase::afterCommitOperation(); + emit featureConstructed(feature(), FM_Deactivation); +} + +FeaturePtr PartSet_OperationConstraint::createFeature(const bool theFlushMessage) +{ + FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false); + if (sketch()) { + boost::shared_ptr aFeature = + boost::dynamic_pointer_cast(sketch()); + + aFeature->addSub(aNewFeature); + } + /*if (myInitPoint) { + setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START); + setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END); + + boost::shared_ptr aData = aNewFeature->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast + (aData->attribute(LINE_ATTR_START)); + createConstraint(myInitPoint, aPoint); + }*/ + + emit featureConstructed(aNewFeature, FM_Activation); + if (theFlushMessage) + flushCreated(); + return aNewFeature; +} + +void PartSet_OperationConstraint::setFeature(FeaturePtr theFeature) +{ + if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) + return; + + boost::shared_ptr aData = feature()->data(); + + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + anAttr->setFeature(theFeature); +} + +void PartSet_OperationConstraint::setValue(const double theValue) +{ + boost::shared_ptr aData = feature()->data(); + + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + anAttr->setValue(theValue); + +} diff --git a/src/PartSet/PartSet_OperationConstraint.h b/src/PartSet/PartSet_OperationConstraint.h new file mode 100644 index 000000000..678964aaf --- /dev/null +++ b/src/PartSet/PartSet_OperationConstraint.h @@ -0,0 +1,103 @@ +// File: PartSet_OperationConstraint.h +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_OperationConstraint_H +#define PartSet_OperationConstraint_H + +#include "PartSet.h" + +#include + +#include + +#include + +/*! + \class PartSet_OperationConstraint + * \brief The operation for the sketch constraint feature creation +*/ +class PARTSET_EXPORT PartSet_OperationConstraint : public PartSet_OperationSketchBase +{ + Q_OBJECT + +public: + /// Returns the operation type key + static std::string Type() { return SKETCH_CONSTRAINT_LENGTH_KIND; } + +public: + /// Constructor + /// \param theId the feature identifier + /// \param theParent the operation parent + /// \param theFeature the parent feature + PartSet_OperationConstraint(const QString& theId, QObject* theParent, + FeaturePtr theSketchFeature); + /// Destructor + virtual ~PartSet_OperationConstraint(); + + /// Returns that this operator can be started above already running one. + /// The runned operation should be the sketch feature modified operation + /// \param theOperation the previous running operation + virtual bool isGranted(ModuleBase_IOperation* theOperation) const; + + /// Initializes some fields accorging to the feature + /// \param theSelected the list of selected presentations + /// \param theHighlighted the list of highlighted presentations + virtual void init(FeaturePtr theFeature, + const std::list& theSelected, + const std::list& theHighlighted); + + /// Returns the operation sketch feature + /// \returns the sketch instance + virtual FeaturePtr sketch() const; + + /// Gives the current selected objects to be processed by the operation + /// \param theEvent the mouse event + /// \param theView a viewer to have the viewer the eye position + /// \param theSelected the list of selected presentations + /// \param theHighlighted the list of highlighted presentations + virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected, + const std::list& theHighlighted); + /// Gives the current mouse point in the viewer + /// \param thePoint a point clicked in the viewer + /// \param theEvent the mouse event + virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); + +protected: + /// \brief Virtual method called when operation is started + /// Virtual method called when operation started (see start() method for more description) + /// After the parent operation body perform, set sketch feature to the created line feature + virtual void startOperation(); + + /// Virtual method called when operation aborted (see abort() method for more description) + /// Before the feature is aborted, it should be hidden from the viewer + virtual void abortOperation(); + + /// Virtual method called when operation stopped - committed or aborted. + /// Restore the multi selection state + virtual void stopOperation(); + + /// Virtual method called after operation committed (see commit() method for more description) + virtual void afterCommitOperation(); + + /// Creates an operation new feature + /// In addition to the default realization it appends the created line feature to + /// the sketch feature + /// \param theFlushMessage the flag whether the create message should be flushed + /// \returns the created feature + virtual FeaturePtr createFeature(const bool theFlushMessage = true); + + /// Set the feature for the constraint + /// \param theFeature the line feature + void setFeature(FeaturePtr theFeature); + + /// Set the value for the constraint + /// \param theValue the constraint value + void setValue(const double theValue); + +private: + FeaturePtr mySketch; ///< the sketch feature +}; + +#endif diff --git a/src/PartSet/PartSet_OperationCreateFeature.cpp b/src/PartSet/PartSet_OperationCreateFeature.cpp new file mode 100644 index 000000000..1d9044592 --- /dev/null +++ b/src/PartSet/PartSet_OperationCreateFeature.cpp @@ -0,0 +1,276 @@ +// File: PartSet_OperationCreateFeature.h +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include +#include +#include + +#include + +#include + +#include +#include + +#include +#include +#include +#include + +#ifdef _DEBUG +#include +#endif + +#include + +using namespace std; + +PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& theId, + QObject* theParent, + FeaturePtr theFeature) +: PartSet_OperationSketchBase(theId, theParent), + myPointSelectionMode(SM_FirstPoint) +{ + myFeaturePrs = new PartSet_FeaturePrs(theFeature); +} + +PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature() +{ + delete myFeaturePrs; +} + +bool PartSet_OperationCreateFeature::canBeCommitted() const +{ + return myPointSelectionMode == SM_DonePoint; +} + +bool PartSet_OperationCreateFeature::isGranted(ModuleBase_IOperation* theOperation) const +{ + return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type(); +} + +std::list PartSet_OperationCreateFeature::getSelectionModes(FeaturePtr theFeature) const +{ + std::list aModes; + if (theFeature != feature()) + aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); + return aModes; +} + +void PartSet_OperationCreateFeature::init(FeaturePtr theFeature, + const std::list& /*theSelected*/, + const std::list& /*theHighlighted*/) +{ + if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) + return; + myInitFeature = theFeature; +} + +FeaturePtr PartSet_OperationCreateFeature::sketch() const +{ + return myFeaturePrs->sketch(); +} + +void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& theSelected, + const std::list& /*theHighlighted*/) +{ + if (myPointSelectionMode == SM_DonePoint) + { + // if the point creation is finished, the next mouse release should commit the modification + // the next release can happens by double click in the viewer + commit(); + restartOperation(feature()->getKind(), feature()); + return; + } + + double aX, anY; + + bool isFoundPoint = false; + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); + if (theSelected.empty()) { + PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); + isFoundPoint = true; + } + else { + XGUI_ViewerPrs aPrs = theSelected.front(); + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) // the point is selected + { + if (aShape.ShapeType() == TopAbs_VERTEX) { + const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); + if (!aVertex.IsNull()) { + aPoint = BRep_Tool::Pnt(aVertex); + PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); + isFoundPoint = true; + + myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode); + } + } + /*else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected + { + FeaturePtr aFeature = aPrs.feature(); + if (aFeature) { + double X0, X1, X2, X3; + double Y0, Y1, Y2, Y3; + getLinePoint(aFeature, LINE_ATTR_START, X2, Y2); + getLinePoint(aFeature, LINE_ATTR_END, X3, Y3); + PartSet_Tools::convertTo2D(aPoint, sketch(), theView, X1, Y1); + + switch (myPointSelectionMode) { + case SM_FirstPoint: + PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY); + break; + case SM_SecondPoint: { + getLinePoint(feature(), LINE_ATTR_START, X0, Y0); + PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY); + } + break; + default: + break; + } + isFoundPoint = true; + } + }*/ + } + } + + switch (myPointSelectionMode) + { + case SM_FirstPoint: + case SM_SecondPoint: { + PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode); + flushUpdated(); + setPointSelectionMode(aMode); + } + break; + default: + break; + } +} + +void PartSet_OperationCreateFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) +{ + switch (myPointSelectionMode) + { + case SM_FirstPoint: + case SM_SecondPoint: + { + double aX, anY; + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); + PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); + myFeaturePrs->setPoint(aX, anY, myPointSelectionMode); + + flushUpdated(); + emit focusActivated(myFeaturePrs->getAttribute(myPointSelectionMode)); + } + break; + case SM_DonePoint: + { + commit(); + restartOperation(feature()->getKind(), feature()); + } + default: + break; + } +} + +void PartSet_OperationCreateFeature::keyReleased(std::string theName, QKeyEvent* theEvent) +{ + int aKeyType = theEvent->key(); + // the second point should be activated by any modification in the property panel + if (!theName.empty() /*&& aKeyType == Qt::Key_Return*/) + { + setPointSelectionMode(myFeaturePrs->getNextMode(theName), false); + } + keyReleased(theEvent->key()); +} + +void PartSet_OperationCreateFeature::keyReleased(const int theKey) +{ + switch (theKey) { + case Qt::Key_Return: { + if (myPointSelectionMode == SM_DonePoint) + { + commit(); + // it start a new line creation at a free point + restartOperation(feature()->getKind(), FeaturePtr()/*feature()*/); + } + //else + // abort(); + //restartOperation(feature()->getKind(), FeaturePtr()); + } + break; + case Qt::Key_Escape: { + if (myPointSelectionMode == SM_DonePoint) + { + commit(); + } + else + { + abort(); + } + } + default: + break; + } +} + +void PartSet_OperationCreateFeature::startOperation() +{ + PartSet_OperationSketchBase::startOperation(); + setPointSelectionMode(!myInitFeature ? SM_FirstPoint : SM_SecondPoint); + + emit multiSelectionEnabled(false); +} + +void PartSet_OperationCreateFeature::abortOperation() +{ + emit featureConstructed(feature(), FM_Hide); + PartSet_OperationSketchBase::abortOperation(); +} + +void PartSet_OperationCreateFeature::stopOperation() +{ + PartSet_OperationSketchBase::stopOperation(); + emit multiSelectionEnabled(true); +} + +void PartSet_OperationCreateFeature::afterCommitOperation() +{ + PartSet_OperationSketchBase::afterCommitOperation(); + emit featureConstructed(feature(), FM_Deactivation); +} + +FeaturePtr PartSet_OperationCreateFeature::createFeature(const bool theFlushMessage) +{ + FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false); + if (sketch()) { + boost::shared_ptr aFeature = + boost::dynamic_pointer_cast(sketch()); + + aFeature->addSub(aNewFeature); + } + myFeaturePrs->init(aNewFeature, myInitFeature); + + emit featureConstructed(aNewFeature, FM_Activation); + if (theFlushMessage) + flushCreated(); + return aNewFeature; +} + +void PartSet_OperationCreateFeature::setPointSelectionMode(const PartSet_SelectionMode& theMode, + const bool isToEmitSignal) +{ + myPointSelectionMode = theMode; + if (isToEmitSignal) { + std::string aName = myFeaturePrs->getAttribute(theMode); + if (aName.empty() && theMode == SM_DonePoint) { + aName = XGUI::PROP_PANEL_OK; + } + emit focusActivated(aName); + } +} diff --git a/src/PartSet/PartSet_OperationCreateFeature.h b/src/PartSet/PartSet_OperationCreateFeature.h new file mode 100644 index 000000000..e53bf9b84 --- /dev/null +++ b/src/PartSet/PartSet_OperationCreateFeature.h @@ -0,0 +1,122 @@ +// File: PartSet_OperationCreateFeature.h +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_OperationCreateFeature_H +#define PartSet_OperationCreateFeature_H + +#include "PartSet.h" + +#include +#include + +#include + +#include + +class PartSet_FeaturePrs; +class GeomDataAPI_Point2D; +class QMouseEvent; +class QKeyEvent; + +/*! + \class PartSet_OperationCreateFeature + * \brief The operation for the sketch feature creation +*/ +class PARTSET_EXPORT PartSet_OperationCreateFeature : public PartSet_OperationSketchBase +{ + Q_OBJECT + +public: + +public: + /// Constructor + /// \param theId the feature identifier + /// \param theParent the operation parent + /// \param theSketch the parent feature + PartSet_OperationCreateFeature(const QString& theId, QObject* theParent, + FeaturePtr theSketch); + /// Destructor + virtual ~PartSet_OperationCreateFeature(); + + /// Verifies whether this operator can be commited. + /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled + virtual bool canBeCommitted() const; + + /// Returns that this operator can be started above already running one. + /// The runned operation should be the sketch feature modified operation + /// \param theOperation the previous running operation + virtual bool isGranted(ModuleBase_IOperation* theOperation) const; + + /// Returns the operation local selection mode + /// \param theFeature the feature object to get the selection mode + /// \return the selection mode + virtual std::list getSelectionModes(FeaturePtr theFeature) const; + + /// Initializes some fields accorging to the feature + /// \param theSelected the list of selected presentations + /// \param theHighlighted the list of highlighted presentations + virtual void init(FeaturePtr theFeature, + const std::list& theSelected, + const std::list& theHighlighted); + + /// Returns the operation sketch feature + /// \returns the sketch instance + virtual FeaturePtr sketch() const; + + /// Gives the current selected objects to be processed by the operation + /// \param theEvent the mouse event + /// \param theView a viewer to have the viewer the eye position + /// \param theSelected the list of selected presentations + /// \param theHighlighted the list of highlighted presentations + virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected, + const std::list& theHighlighted); + /// Gives the current mouse point in the viewer + /// \param thePoint a point clicked in the viewer + /// \param theEvent the mouse event + virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); + /// Processes the key pressed in the view + /// \param theKey a key value + virtual void keyReleased(const int theKey); + + virtual void keyReleased(std::string theName, QKeyEvent* theEvent); + +protected: + /// \brief Virtual method called when operation is started + /// Virtual method called when operation started (see start() method for more description) + /// After the parent operation body perform, set sketch feature to the created line feature + virtual void startOperation(); + + /// Virtual method called when operation aborted (see abort() method for more description) + /// Before the feature is aborted, it should be hidden from the viewer + virtual void abortOperation(); + + /// Virtual method called when operation stopped - committed or aborted. + /// Restore the multi selection state + virtual void stopOperation(); + + /// Virtual method called after operation committed (see commit() method for more description) + virtual void afterCommitOperation(); + + /// Creates an operation new feature + /// In addition to the default realization it appends the created line feature to + /// the sketch feature + /// \param theFlushMessage the flag whether the create message should be flushed + /// \returns the created feature + virtual FeaturePtr createFeature(const bool theFlushMessage = true); + +protected: + ///< Set the point selection mode. Emit signal about focus change if necessary. + /// \param theMode a new selection mode + /// \param isToEmitSignal the neccessity to emit signal + void setPointSelectionMode(const PartSet_SelectionMode& theMode, + const bool isToEmitSignal = true); + +private: + PartSet_FeaturePrs* myFeaturePrs; ///< the feature presentation + FeaturePtr myInitFeature; ///< the initial feature + PartSet_SelectionMode myPointSelectionMode; ///< point selection mode +}; + +#endif diff --git a/src/PartSet/PartSet_OperationEditLine.cpp b/src/PartSet/PartSet_OperationEditLine.cpp index 2edee70af..af46da90d 100644 --- a/src/PartSet/PartSet_OperationEditLine.cpp +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -34,7 +34,7 @@ using namespace std; PartSet_OperationEditLine::PartSet_OperationEditLine(const QString& theId, QObject* theParent, - boost::shared_ptr theFeature) + FeaturePtr theFeature) : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false) { } @@ -48,12 +48,12 @@ bool PartSet_OperationEditLine::isGranted(ModuleBase_IOperation* theOperation) c return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type(); } -std::list PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr theFeature) const +std::list PartSet_OperationEditLine::getSelectionModes(FeaturePtr theFeature) const { return PartSet_OperationSketchBase::getSelectionModes(theFeature); } -void PartSet_OperationEditLine::init(boost::shared_ptr theFeature, +void PartSet_OperationEditLine::init(FeaturePtr theFeature, const std::list& theSelected, const std::list& theHighlighted) { @@ -78,7 +78,7 @@ void PartSet_OperationEditLine::init(boost::shared_ptr theFeat myFeatures = theSelected; } -boost::shared_ptr PartSet_OperationEditLine::sketch() const +FeaturePtr PartSet_OperationEditLine::sketch() const { return mySketch; } @@ -89,7 +89,7 @@ void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_V { if (myFeatures.size() == 1) { - boost::shared_ptr aFeature; + FeaturePtr aFeature; if (!theHighlighted.empty()) aFeature = theHighlighted.front().feature(); @@ -119,15 +119,15 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie if (!(theEvent->buttons() & Qt::LeftButton)) return; - gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); blockSelection(true); if (myCurPoint.myIsInitialized) { double aCurX, aCurY; - PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY); + PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY); double aX, anY; - PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); + PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); double aDeltaX = aX - aCurX; double aDeltaY = anY - aCurY; @@ -137,7 +137,7 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); for (; anIt != aLast; anIt++) { - boost::shared_ptr aFeature = (*anIt).feature(); + FeaturePtr aFeature = (*anIt).feature(); if (!aFeature || aFeature == feature()) continue; moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START); @@ -161,7 +161,7 @@ void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_ commit(); std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); for (; anIt != aLast; anIt++) { - boost::shared_ptr aFeature = (*anIt).feature(); + FeaturePtr aFeature = (*anIt).feature(); if (aFeature) emit featureConstructed(aFeature, FM_Deactivation); } @@ -205,17 +205,17 @@ void PartSet_OperationEditLine::blockSelection(bool isBlocked, const bool isRest } } -boost::shared_ptr PartSet_OperationEditLine::createFeature(const bool /*theFlushMessage*/) +FeaturePtr PartSet_OperationEditLine::createFeature(const bool /*theFlushMessage*/) { // do nothing in order to do not create a new feature - return boost::shared_ptr(); + return FeaturePtr(); } -void PartSet_OperationEditLine::moveLinePoint(boost::shared_ptr theFeature, +void PartSet_OperationEditLine::moveLinePoint(FeaturePtr theFeature, double theDeltaX, double theDeltaY, const std::string& theAttribute) { - if (!theFeature || theFeature->getKind() != "SketchLine") + if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) return; boost::shared_ptr aData = theFeature->data(); @@ -231,10 +231,10 @@ void PartSet_OperationEditLine::sendFeatures() { static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED); - std::list > aFeatures; + std::list aFeatures; std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); for (; anIt != aLast; anIt++) { - boost::shared_ptr aFeature = (*anIt).feature(); + FeaturePtr aFeature = (*anIt).feature(); if (!aFeature) continue; diff --git a/src/PartSet/PartSet_OperationEditLine.h b/src/PartSet/PartSet_OperationEditLine.h index d42d0e545..1e18c1511 100644 --- a/src/PartSet/PartSet_OperationEditLine.h +++ b/src/PartSet/PartSet_OperationEditLine.h @@ -56,7 +56,7 @@ public: /// \param theParent the operation parent /// \param theFeature the parent feature PartSet_OperationEditLine(const QString& theId, QObject* theParent, - boost::shared_ptr theFeature); + FeaturePtr theFeature); /// Destructor virtual ~PartSet_OperationEditLine(); @@ -68,19 +68,19 @@ public: /// Returns the operation local selection mode /// \param theFeature the feature object to get the selection mode /// \return the selection mode - virtual std::list getSelectionModes(boost::shared_ptr theFeature) const; + virtual std::list getSelectionModes(FeaturePtr theFeature) const; /// Initializes some fields accorging to the feature /// \param theFeature the feature /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations - virtual void init(boost::shared_ptr theFeature, + virtual void init(FeaturePtr theFeature, const std::list& theSelected, const std::list& theHighlighted); /// Returns the operation sketch feature /// \returns the sketch instance - virtual boost::shared_ptr sketch() const; + virtual FeaturePtr sketch() const; /// Processes the mouse pressed in the point /// \param theEvent the mouse event @@ -116,7 +116,7 @@ protected: /// Returns NULL feature. This is an operation of edition, not creation. /// \param theFlushMessage the flag whether the create message should be flushed /// \returns the created feature - virtual boost::shared_ptr createFeature(const bool theFlushMessage = true); + virtual FeaturePtr createFeature(const bool theFlushMessage = true); protected: /// Emits a signal about the selection blocking. Emits a signal to change the selection. @@ -131,17 +131,16 @@ protected: /// \param theDeltaX the delta for X coordinate is moved /// \param theDeltaY the delta for Y coordinate is moved /// \param theAttribute the start or end attribute of the line - void moveLinePoint(boost::shared_ptr theFeature, + void moveLinePoint(FeaturePtr theFeature, double theDeltaX, double theDeltaY, const std::string& theAttribute); /// Sends the features void sendFeatures(); private: - boost::shared_ptr mySketch; ///< the sketch feature + FeaturePtr mySketch; ///< the sketch feature std::list myFeatures; ///< the features to apply the edit operation Point myCurPoint; ///< the current 3D point clicked or moved - gp_Pnt myCurPressed; ///< the current 3D point clicked or moved bool myIsBlockedSelection; ///< the state of the last state of selection blocked signal }; diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index af60900da..039d293b3 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -22,6 +22,9 @@ #include #include +#include +#include +#include #include #ifdef _DEBUG @@ -42,24 +45,25 @@ PartSet_OperationSketch::~PartSet_OperationSketch() { } -std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr theFeature) const +std::list PartSet_OperationSketch::getSelectionModes(FeaturePtr theFeature) const { std::list aModes; if (!hasSketchPlane()) aModes.push_back(TopAbs_FACE); else aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); + return aModes; } -void PartSet_OperationSketch::init(boost::shared_ptr theFeature, +void PartSet_OperationSketch::init(FeaturePtr theFeature, const std::list& /*theSelected*/, const std::list& /*theHighlighted*/) { setFeature(theFeature); } -boost::shared_ptr PartSet_OperationSketch::sketch() const +FeaturePtr PartSet_OperationSketch::sketch() const { return feature(); } @@ -84,7 +88,7 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie return; if (theHighlighted.size() == 1) { - boost::shared_ptr aFeature = theHighlighted.front().feature(); + FeaturePtr aFeature = theHighlighted.front().feature(); if (aFeature) restartOperation(PartSet_OperationEditLine::Type(), aFeature); } @@ -93,23 +97,56 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie } } +#include +void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected, + const std::list& theHighlighted) +{ + if (!hasSketchPlane()) { + } + else { + if (!theSelected.empty()) { + XGUI_ViewerPrs aPrs = theSelected.front(); + if (!aPrs.owner().IsNull()) { + Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aPrs.owner()); + if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) { + Handle(SelectMgr_SelectableObject) anObject = anOwner->Selectable(); + double aValue = 0; + if (!anObject.IsNull()) { + Handle(AIS_LengthDimension) aLenDim = Handle(AIS_LengthDimension)::DownCast(anObject); + if (!aLenDim.IsNull()) + aValue = aLenDim->GetValue(); + } + + QLineEdit* aLine = new QLineEdit(); + QPoint aViewPos = theEvent->globalPos(); + QPoint aLinePos(aViewPos.x(), aViewPos.y()); + aLine->move(aLinePos); + aLine->setText(QString::number(aValue)); + aLine->show(); + } + } + } + } +} + void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) { if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty()) return; if (myFeatures.size() != 1) { - boost::shared_ptr aFeature = PartSet_Tools::NearestFeature(theEvent->pos(), + FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), theView, feature(), myFeatures); if (aFeature) restartOperation(PartSet_OperationEditLine::Type(), aFeature); } } -std::map, boost::shared_ptr > +std::map > PartSet_OperationSketch::subPreview() const { - std::map, boost::shared_ptr > aPreviewMap; + std::map > aPreviewMap; boost::shared_ptr aFeature; @@ -119,8 +156,8 @@ std::map, boost::shared_ptr > boost::shared_ptr aRefList = boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_FEATURES)); - std::list > aFeatures = aRefList->list(); - std::list >::const_iterator anIt = aFeatures.begin(), + std::list aFeatures = aRefList->list(); + std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); for (; anIt != aLast; anIt++) { aFeature = boost::dynamic_pointer_cast(*anIt); @@ -189,7 +226,7 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero)); boost::shared_ptr anOrigPnt(new GeomAPI_Pnt(aCoords)); // X axis is preferable to be dirX on the sketch - const double tol = 1e-7; + const double tol = Precision::Confusion(); bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol; boost::shared_ptr aTempDir(isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0)); boost::shared_ptr aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir))); diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 9c76414e9..27c0d8641 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -8,8 +8,13 @@ #include "PartSet.h" #include + +#include + #include +class Handle_AIS_InteractiveObject; + /*! \class PartSet_OperationSketch * \brief The operation for the sketch feature creation @@ -19,7 +24,7 @@ class PARTSET_EXPORT PartSet_OperationSketch : public PartSet_OperationSketchBas Q_OBJECT public: /// Returns the operation type key - static std::string Type() { return "Sketch"; } + static std::string Type() { return SKETCH_KIND; } public: /// Constructor @@ -32,18 +37,18 @@ public: /// Returns the operation local selection mode /// \param theFeature the feature object to get the selection mode /// \return the selection mode - virtual std::list getSelectionModes(boost::shared_ptr theFeature) const; + virtual std::list getSelectionModes(FeaturePtr theFeature) const; /// Initializes some fields accorging to the feature /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations - virtual void init(boost::shared_ptr theFeature, + virtual void init(FeaturePtr theFeature, const std::list& theSelected, const std::list& theHighlighted); /// Returns the operation sketch feature /// \returns the sketch instance - virtual boost::shared_ptr sketch() const; + virtual FeaturePtr sketch() const; /// Processes the mouse pressed in the point /// \param theEvent the mouse event @@ -53,6 +58,15 @@ public: virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, const std::list& theSelected, const std::list& theHighlighted); + /// Processes the mouse release in the point + /// \param theEvent the mouse event + /// \param theView a viewer to have the viewer the eye position + /// \param theSelected the list of selected presentations + /// \param theHighlighted the list of highlighted presentations + virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected, + const std::list& theHighlighted); + /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event @@ -60,7 +74,7 @@ public: /// Returns the map of the operation previews including the nested feature previews /// \return the map of feature to the feature preview - virtual std::map, boost::shared_ptr > + virtual std::map > subPreview() const; /// Virtual method called when operation stopped - committed or aborted. diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index ae751b269..8bb9e3be2 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -27,7 +27,7 @@ PartSet_OperationSketchBase::~PartSet_OperationSketchBase() } boost::shared_ptr PartSet_OperationSketchBase::preview( - boost::shared_ptr theFeature) + FeaturePtr theFeature) { boost::shared_ptr aFeature = boost::dynamic_pointer_cast(theFeature); @@ -36,22 +36,22 @@ boost::shared_ptr PartSet_OperationSketchBase::preview( return aFeature->preview(); } -std::map, boost::shared_ptr > +std::map > PartSet_OperationSketchBase::subPreview() const { - return std::map, boost::shared_ptr >(); + return std::map >(); } -std::list PartSet_OperationSketchBase::getSelectionModes(boost::shared_ptr theFeature) const +std::list PartSet_OperationSketchBase::getSelectionModes(FeaturePtr theFeature) const { std::list aModes; aModes.push_back(TopAbs_VERTEX); aModes.push_back(TopAbs_EDGE); return aModes; } -boost::shared_ptr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage) +FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage) { - boost::shared_ptr aFeature = ModuleBase_Operation::createFeature(theFlushMessage); + FeaturePtr aFeature = ModuleBase_Operation::createFeature(theFlushMessage); if (aFeature) emit featureConstructed(aFeature, FM_Activation); return aFeature; @@ -90,7 +90,7 @@ void PartSet_OperationSketchBase::keyReleased(std::string theName, QKeyEvent* th } void PartSet_OperationSketchBase::restartOperation(const std::string& theType, - boost::shared_ptr theFeature) + FeaturePtr theFeature) { emit launchOperation(theType, theFeature); } diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 0c10c6c1a..ff6f06847 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -43,27 +43,27 @@ public: /// Returns the feature preview shape /// \param theFeature the feature object to obtain the preview - static boost::shared_ptr preview(boost::shared_ptr theFeature); + static boost::shared_ptr preview(FeaturePtr theFeature); /// Returns the map of the operation previews including the nested feature previews /// \return the map of feature to the feature preview - virtual std::map, boost::shared_ptr > subPreview() const; + virtual std::map > subPreview() const; /// Returns the operation local selection mode /// \param theFeature the feature object to get the selection mode /// \return the selection mode - virtual std::list getSelectionModes(boost::shared_ptr theFeature) const = 0; + virtual std::list getSelectionModes(FeaturePtr theFeature) const; /// Initializes some fields accorging to the feature /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations - virtual void init(boost::shared_ptr theFeature, + virtual void init(FeaturePtr theFeature, const std::list& theSelected, const std::list& theHighlighted) {} /// Returns the operation sketch feature /// \returns the sketch instance - virtual boost::shared_ptr sketch() const = 0; + virtual FeaturePtr sketch() const = 0; /// Processes the mouse pressed in the point /// \param theEvent the mouse event @@ -99,13 +99,13 @@ public: /// \param theType a type of an operation started /// theFeature the operation argument void restartOperation(const std::string& theType, - boost::shared_ptr theFeature = boost::shared_ptr()); + FeaturePtr theFeature = FeaturePtr()); signals: /// signal about the request to launch operation /// theName the operation name /// theFeature the operation argument - void launchOperation(std::string theName, boost::shared_ptr theFeature); + void launchOperation(std::string theName, FeaturePtr theFeature); /// signal about the focus activated /// theName the attribute name void focusActivated(const std::string& theAttibuteName); @@ -113,7 +113,7 @@ signals: /// Signal about the feature construing is finished /// \param theFeature the result feature /// \param theMode the mode of the feature modification - void featureConstructed(boost::shared_ptr theFeature, + void featureConstructed(FeaturePtr theFeature, int theMode); /// Signal about the features should be selected /// \param theSelected the list of selected presentations @@ -139,7 +139,7 @@ protected: /// the sketch feature /// \param theFlushMessage the flag whether the create message should be flushed /// \returns the created feature - virtual boost::shared_ptr createFeature(const bool theFlushMessage = true); + virtual FeaturePtr createFeature(const bool theFlushMessage = true); }; #endif diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp deleted file mode 100644 index 1a1cdbc0e..000000000 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ /dev/null @@ -1,442 +0,0 @@ -// File: PartSet_OperationSketchLine.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include - -#include -#include - -#include -#include - -#include - -#include - -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include - -#ifdef _DEBUG -#include -#endif - -#include - -using namespace std; - -PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId, - QObject* theParent, - boost::shared_ptr theFeature) -: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), - myPointSelectionMode(SM_FirstPoint) -{ -} - -PartSet_OperationSketchLine::~PartSet_OperationSketchLine() -{ -} - -bool PartSet_OperationSketchLine::canBeCommitted() const -{ - return myPointSelectionMode == SM_DonePoint; -} - -bool PartSet_OperationSketchLine::isGranted(ModuleBase_IOperation* theOperation) const -{ - return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type(); -} - -std::list PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr theFeature) const -{ - std::list aModes; - if (theFeature != feature()) - aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); - return aModes; -} - -void PartSet_OperationSketchLine::init(boost::shared_ptr theFeature, - const std::list& /*theSelected*/, - const std::list& /*theHighlighted*/) -{ - if (!theFeature || theFeature->getKind() != "SketchLine") - return; - // use the last point of the previous feature as the first of the new one - boost::shared_ptr aData = theFeature->data(); - myInitPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); -} - -boost::shared_ptr PartSet_OperationSketchLine::sketch() const -{ - return mySketch; -} - -void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, - const std::list& theSelected, - const std::list& /*theHighlighted*/) -{ - if (myPointSelectionMode == SM_DonePoint) - { - // if the point creation is finished, the next mouse release should commit the modification - // the next release can happens by double click in the viewer - commit(); - restartOperation(PartSet_OperationSketchLine::Type(), feature()); - return; - } - - double aX, anY; - - bool isFoundPoint = false; - gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); - if (theSelected.empty()) { - PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); - isFoundPoint = true; - } - else { - XGUI_ViewerPrs aPrs = theSelected.front(); - const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull()) // the point is selected - { - if (aShape.ShapeType() == TopAbs_VERTEX) { - const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); - if (!aVertex.IsNull()) { - aPoint = BRep_Tool::Pnt(aVertex); - PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); - isFoundPoint = true; - - setConstraints(aX, anY); - } - } - else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected - { - boost::shared_ptr aFeature = aPrs.feature(); - if (aFeature) { - double X0, X1, X2, X3; - double Y0, Y1, Y2, Y3; - getLinePoint(aFeature, LINE_ATTR_START, X2, Y2); - getLinePoint(aFeature, LINE_ATTR_END, X3, Y3); - PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, X1, Y1); - - switch (myPointSelectionMode) { - case SM_FirstPoint: - PartSet_Tools::ProjectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY); - break; - case SM_SecondPoint: { - getLinePoint(feature(), LINE_ATTR_START, X0, Y0); - PartSet_Tools::IntersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY); - } - break; - default: - break; - } - isFoundPoint = true; - } - } - } - } - - switch (myPointSelectionMode) - { - case SM_FirstPoint: { - setLinePoint(feature(), aX, anY, LINE_ATTR_START); - setLinePoint(feature(), aX, anY, LINE_ATTR_END); - flushUpdated(); - - setPointSelectionMode(SM_SecondPoint); - } - break; - case SM_SecondPoint: { - setLinePoint(feature(), aX, anY, LINE_ATTR_END); - flushUpdated(); - - setPointSelectionMode(SM_DonePoint); - } - break; - default: - break; - } -} - -void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) -{ - switch (myPointSelectionMode) - { - case SM_FirstPoint: { - double aX, anY; - gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); - PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); - setLinePoint(feature(), aX, anY, LINE_ATTR_START); - setLinePoint(feature(), aX, anY, LINE_ATTR_END); - flushUpdated(); - emit focusActivated(LINE_ATTR_START); - } - break; - case SM_SecondPoint: - { - gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); - setLinePoint(aPoint, theView, LINE_ATTR_END); - flushUpdated(); - emit focusActivated(LINE_ATTR_END); - } - break; - case SM_DonePoint: - { - commit(); - restartOperation(PartSet_OperationSketchLine::Type(), feature()); - } - default: - break; - } -} - -void PartSet_OperationSketchLine::keyReleased(std::string theName, QKeyEvent* theEvent) -{ - int aKeyType = theEvent->key(); - // the second point should be activated by any modification in the property panel - if (!theName.empty() /*&& aKeyType == Qt::Key_Return*/) { - if (theName == LINE_ATTR_START) { - setPointSelectionMode(SM_SecondPoint, false); - } - else if (theName == LINE_ATTR_END) { - setPointSelectionMode(SM_DonePoint, false); - } - } - keyReleased(theEvent->key()); -} - -void PartSet_OperationSketchLine::keyReleased(const int theKey) -{ - switch (theKey) { - case Qt::Key_Return: { - if (myPointSelectionMode == SM_DonePoint) - { - commit(); - restartOperation(PartSet_OperationSketchLine::Type(), feature()); - } - //else - // abort(); - //emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr()); - } - break; - case Qt::Key_Escape: { - if (myPointSelectionMode == SM_DonePoint) - { - commit(); - } - else - abort(); - } - default: - break; - } -} - -void PartSet_OperationSketchLine::startOperation() -{ - PartSet_OperationSketchBase::startOperation(); - setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint); - - emit multiSelectionEnabled(false); -} - -void PartSet_OperationSketchLine::abortOperation() -{ - emit featureConstructed(feature(), FM_Hide); - PartSet_OperationSketchBase::abortOperation(); -} - -void PartSet_OperationSketchLine::stopOperation() -{ - PartSet_OperationSketchBase::stopOperation(); - emit multiSelectionEnabled(true); -} - -void PartSet_OperationSketchLine::afterCommitOperation() -{ - PartSet_OperationSketchBase::afterCommitOperation(); - emit featureConstructed(feature(), FM_Deactivation); -} - -boost::shared_ptr PartSet_OperationSketchLine::createFeature(const bool theFlushMessage) -{ - boost::shared_ptr aNewFeature = ModuleBase_Operation::createFeature(false); - if (sketch()) { - boost::shared_ptr aFeature = - boost::dynamic_pointer_cast(sketch()); - - aFeature->addSub(aNewFeature); - } - if (myInitPoint) { - setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START); - setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END); - - boost::shared_ptr aData = aNewFeature->data(); - boost::shared_ptr aPoint = boost::dynamic_pointer_cast - (aData->attribute(LINE_ATTR_START)); - createConstraint(myInitPoint, aPoint); - } - - emit featureConstructed(aNewFeature, FM_Activation); - if (theFlushMessage) - flushCreated(); - return aNewFeature; -} - -void PartSet_OperationSketchLine::createConstraint(boost::shared_ptr thePoint1, - boost::shared_ptr thePoint2) -{ - boost::shared_ptr aDoc = document(); - boost::shared_ptr aFeature = aDoc->addFeature("SketchConstraintCoincidence"); - - if (sketch()) { - boost::shared_ptr aSketch = - boost::dynamic_pointer_cast(sketch()); - aSketch->addSub(aFeature); - } - - boost::shared_ptr aData = aFeature->data(); - - boost::shared_ptr aRef1 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); - aRef1->setAttr(thePoint1); - - boost::shared_ptr aRef2 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); - aRef2->setAttr(thePoint2); - - if (aFeature) // TODO: generate an error if feature was not created - aFeature->execute(); -} - -void PartSet_OperationSketchLine::setConstraints(double theX, double theY) -{ - std::string aPointArg; - switch (myPointSelectionMode) - { - case SM_FirstPoint: - aPointArg = LINE_ATTR_START; - break; - case SM_SecondPoint: - aPointArg = LINE_ATTR_END; - break; - default: - break; - } - - boost::shared_ptr aSkFeature = feature(); - - boost::shared_ptr aData = feature()->data(); - boost::shared_ptr aPoint = boost::dynamic_pointer_cast - (aData->attribute(aPointArg)); - aData = sketch()->data(); - boost::shared_ptr aRefList = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_FEATURES)); - - std::list > aFeatures = aRefList->list(); - std::list >::const_iterator anIt = aFeatures.begin(), - aLast = aFeatures.end(); - for (; anIt != aLast; anIt++) { - boost::shared_ptr aFeature = *anIt; - boost::shared_ptr aFPoint = findLinePoint(aFeature, theX, theY); - if (aFPoint) - createConstraint(aFPoint, aPoint); - } -} - -void PartSet_OperationSketchLine::getLinePoint(boost::shared_ptr theFeature, - const std::string& theAttribute, - double& theX, double& theY) -{ - if (!theFeature || theFeature->getKind() != "SketchLine") - return; - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - theX = aPoint->x(); - theY = aPoint->y(); -} - -boost::shared_ptr PartSet_OperationSketchLine::findLinePoint( - boost::shared_ptr theFeature, - double theX, double theY) -{ - boost::shared_ptr aPoint2D; - if (!theFeature || theFeature->getKind() != "SketchLine") - return aPoint2D; - boost::shared_ptr aData = theFeature->data(); - - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) - aPoint2D = aPoint; - else { - aPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) - aPoint2D = aPoint; - } - return aPoint2D; -} - -void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr theFeature, - double theX, double theY, - const std::string& theAttribute) -{ - if (!theFeature) - return; - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - aPoint->setValue(theX, theY); -} - -void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, - Handle(V3d_View) theView, - const std::string& theAttribute) -{ - double aX, anY; - PartSet_Tools::ConvertTo2D(thePoint, sketch(), theView, aX, anY); - boost::shared_ptr aData = feature()->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - aPoint->setValue(aX, anY); -} - -void PartSet_OperationSketchLine::setPointSelectionMode(const PointSelectionMode& theMode, - const bool isToEmitSignal) -{ - myPointSelectionMode = theMode; - if (isToEmitSignal) { - std::string aName; - switch (theMode) { - case SM_FirstPoint: - aName = LINE_ATTR_START; - break; - case SM_SecondPoint: - aName = LINE_ATTR_END; - break; - case SM_DonePoint: - aName = XGUI::PROP_PANEL_OK; - break; - default: - break; - } - emit focusActivated(aName); - } -} diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h deleted file mode 100644 index cda1781c4..000000000 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ /dev/null @@ -1,160 +0,0 @@ -// File: PartSet_OperationSketchLine.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef PartSet_OperationSketchLine_H -#define PartSet_OperationSketchLine_H - -#include "PartSet.h" - -#include -#include - -class GeomDataAPI_Point2D; -class QMouseEvent; -class QKeyEvent; - -/*! - \class PartSet_OperationSketchLine - * \brief The operation for the sketch feature creation -*/ -class PARTSET_EXPORT PartSet_OperationSketchLine : public PartSet_OperationSketchBase -{ - Q_OBJECT - -public: - /// Returns the operation type key - static std::string Type() { return "SketchLine"; } - -public: - /// Constructor - /// \param theId the feature identifier - /// \param theParent the operation parent - /// \param theFeature the parent feature - PartSet_OperationSketchLine(const QString& theId, QObject* theParent, - boost::shared_ptr theSketchFeature); - /// Destructor - virtual ~PartSet_OperationSketchLine(); - - /// Verifies whether this operator can be commited. - /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled - virtual bool canBeCommitted() const; - - /// Returns that this operator can be started above already running one. - /// The runned operation should be the sketch feature modified operation - /// \param theOperation the previous running operation - virtual bool isGranted(ModuleBase_IOperation* theOperation) const; - - /// Returns the operation local selection mode - /// \param theFeature the feature object to get the selection mode - /// \return the selection mode - virtual std::list getSelectionModes(boost::shared_ptr theFeature) const; - - /// Initializes some fields accorging to the feature - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void init(boost::shared_ptr theFeature, - const std::list& theSelected, - const std::list& theHighlighted); - - /// Returns the operation sketch feature - /// \returns the sketch instance - virtual boost::shared_ptr sketch() const; - - /// Gives the current selected objects to be processed by the operation - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); - /// Gives the current mouse point in the viewer - /// \param thePoint a point clicked in the viewer - /// \param theEvent the mouse event - virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); - /// Processes the key pressed in the view - /// \param theKey a key value - virtual void keyReleased(const int theKey); - - virtual void keyReleased(std::string theName, QKeyEvent* theEvent); - - /// \brief Save the point to the line. - /// \param theFeature the line feature - /// \param theX the horizontal coordinate - /// \param theY the vertical coordinate - /// \param theAttribute the start or end attribute of the line - static void setLinePoint(boost::shared_ptr, double theX, double theY, - const std::string& theAttribute); - -protected: - /// \brief Virtual method called when operation is started - /// Virtual method called when operation started (see start() method for more description) - /// After the parent operation body perform, set sketch feature to the created line feature - virtual void startOperation(); - - /// Virtual method called when operation aborted (see abort() method for more description) - /// Before the feature is aborted, it should be hidden from the viewer - virtual void abortOperation(); - - /// Virtual method called when operation stopped - committed or aborted. - /// Restore the multi selection state - virtual void stopOperation(); - - /// Virtual method called after operation committed (see commit() method for more description) - virtual void afterCommitOperation(); - - /// Creates an operation new feature - /// In addition to the default realization it appends the created line feature to - /// the sketch feature - /// \param theFlushMessage the flag whether the create message should be flushed - /// \returns the created feature - virtual boost::shared_ptr createFeature(const bool theFlushMessage = true); - - /// Creates a constraint on two points - /// \param thePoint1 the first point - /// \param thePoint1 the second point - void createConstraint(boost::shared_ptr thePoint1, - boost::shared_ptr thePoint2); - - /// Creates constrains of the current - /// \param theX the horizontal coordnate of the point - /// \param theY the vertical coordnate of the point - void setConstraints(double theX, double theY); - -protected: - /// \brief Get the line point 2d coordinates. - /// \param theFeature the line feature - /// \param theAttribute the start or end attribute of the line - /// \param theX the horizontal coordinate - /// \param theY the vertical coordinate - void getLinePoint(boost::shared_ptr theFeature, const std::string& theAttribute, - double& theX, double& theY); - /// Find a point in the line with given coordinates - /// \param theFeature the line feature - /// \param theX the horizontal point coordinate - /// \param theY the vertical point coordinate - boost::shared_ptr findLinePoint(boost::shared_ptr theFeature, - double theX, double theY); - - /// \brief Save the point to the line. - /// \param thePoint the 3D point in the viewer - /// \param theAttribute the start or end attribute of the line - void setLinePoint(const gp_Pnt& thePoint, Handle(V3d_View) theView, const std::string& theAttribute); - -protected: - ///< Structure to lists the possible types of point selection modes - enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_DonePoint}; - - ///< Set the point selection mode. Emit signal about focus change if necessary. - /// \param theMode a new selection mode - /// \param isToEmitSignal the neccessity to emit signal - void setPointSelectionMode(const PointSelectionMode& theMode, const bool isToEmitSignal = true); - -private: - boost::shared_ptr mySketch; ///< the sketch feature - boost::shared_ptr myInitPoint; ///< the first line point - PointSelectionMode myPointSelectionMode; ///< point selection mode -}; - -#endif diff --git a/src/PartSet/PartSet_Presentation.cpp b/src/PartSet/PartSet_Presentation.cpp new file mode 100644 index 000000000..28d9ce3d1 --- /dev/null +++ b/src/PartSet/PartSet_Presentation.cpp @@ -0,0 +1,150 @@ +// File: PartSet_Presentation.h +// Created: 02 June 2014 +// Author: Natalia ERMOLAEVA + +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color +const int SKETCH_WIDTH = 4; /// the plane edge width + +Handle(AIS_InteractiveObject) PartSet_Presentation::createPresentation( + FeaturePtr theFeature, + FeaturePtr theSketch, + const TopoDS_Shape& theShape, + Handle_AIS_InteractiveObject thePrevPrs) +{ + Handle(AIS_InteractiveObject) anAIS; + + if (theFeature->getKind() == SKETCH_CONSTRAINT_LENGTH_KIND) + anAIS = createSketchConstraintLength(theFeature, theSketch, thePrevPrs); + else { + anAIS = createFeature(theFeature, theShape, thePrevPrs); + if (theFeature->getKind() == SKETCH_KIND) + { + Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS); + aShapeAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR)); + aShapeAIS->SetWidth(SKETCH_WIDTH); + aShapeAIS->Redisplay(); + } + } + + return anAIS; +} + +Handle(AIS_InteractiveObject) PartSet_Presentation::createFeature( + FeaturePtr theFeature, + const TopoDS_Shape& theShape, + Handle_AIS_InteractiveObject thePrevPrs) +{ + Handle(AIS_InteractiveObject) anAIS = thePrevPrs; + if (!anAIS.IsNull()) + { + Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS); + if (!aShapeAIS.IsNull()) { + // if the AIS object is displayed in the opened local context in some mode, additional + // AIS sub objects are created there. They should be rebuild for correct selecting. + // It is possible to correct it by closing local context before the shape set and opening + // after. Another workaround to thrown down the selection and reselecting the AIS. + // If there was a problem here, try the first solution with close/open local context. + aShapeAIS->Set(theShape); + aShapeAIS->Redisplay(Standard_True); + } + } + else + { + anAIS = new AIS_Shape(theShape); + } + return anAIS; +} + +Handle(AIS_InteractiveObject) PartSet_Presentation::createSketchConstraintLength( + FeaturePtr theFeature, + FeaturePtr theSketch, + Handle(AIS_InteractiveObject) thePrevPrs) +{ + if (!theFeature || !theSketch) + return thePrevPrs; + + boost::shared_ptr aData = theSketch->data(); + boost::shared_ptr anOrigin = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + boost::shared_ptr aNormal = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0/*D*/); + + aData = theFeature->data(); + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + if (!anAttr) + return thePrevPrs; + FeaturePtr aFeature = anAttr->feature(); + if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND) + return thePrevPrs; + + aData = aFeature->data(); + if (!aData->isValid()) + return thePrevPrs; + + boost::shared_ptr aPointStart = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::shared_ptr aPointEnd = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + + gp_Pnt aPoint1, aPoint2; + PartSet_Tools::convertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1); + PartSet_Tools::convertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2); + + //Build dimension here + gp_Pnt aP1 = aPoint1; + gp_Pnt aP2 = aPoint2; + + Handle(AIS_InteractiveObject) anAIS = thePrevPrs; + if (anAIS.IsNull()) + { + Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (aP1, aP2, aPlane); + + Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); + anAspect->MakeArrows3d (Standard_False); + anAspect->MakeText3d(false/*is text 3d*/); + anAspect->TextAspect()->SetHeight(28); + anAspect->MakeTextShaded(false/*is test shaded*/); + aLenDim->DimensionAspect()->MakeUnitsDisplayed(false/*is units displayed*/); + /*if (isUnitsDisplayed) + { + aLenDim->SetDisplayUnits (aDimDlg->GetUnits ()); + }*/ + aLenDim->SetDimensionAspect (anAspect); + aLenDim->SetFlyout(12); + + anAIS = aLenDim; + } + else { + // update presentation + Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); + if (!aDimAIS.IsNull()) { + aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane); + aDimAIS->Redisplay(Standard_True); + } + } + return anAIS; +} diff --git a/src/PartSet/PartSet_Presentation.h b/src/PartSet/PartSet_Presentation.h new file mode 100644 index 000000000..8e4b2ae6f --- /dev/null +++ b/src/PartSet/PartSet_Presentation.h @@ -0,0 +1,45 @@ +// File: PartSet_Presentation.h +// Created: 02 Jun 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_Presentation_H +#define PartSet_Presentation_H + +#include "PartSet.h" + +#include + +#include + +#include + +class Handle_AIS_InteractiveObject; + +/*! + \class PartSet_Presentation + * \brief The operation for the sketch feature creation +*/ +class PARTSET_EXPORT PartSet_Presentation +{ +public: + /// Creates AIS presentation for the given feature + /// \param theFeature a feature + /// \return the presentation + static Handle_AIS_InteractiveObject createPresentation( + FeaturePtr theFeature, + FeaturePtr theSketch, + const TopoDS_Shape& theShape, + Handle_AIS_InteractiveObject thePrevPrs); +protected: + static Handle_AIS_InteractiveObject createFeature( + FeaturePtr theFeature, + const TopoDS_Shape& theShape, + Handle_AIS_InteractiveObject thePrevPrs); + + static Handle_AIS_InteractiveObject createSketchConstraintLength( + FeaturePtr theFeature, + FeaturePtr theSketch, + Handle_AIS_InteractiveObject thePrevPrs); +}; + +#endif diff --git a/src/PartSet/PartSet_TestOCC.cpp b/src/PartSet/PartSet_TestOCC.cpp index 60798a78b..ef0ea9a75 100644 --- a/src/PartSet/PartSet_TestOCC.cpp +++ b/src/PartSet/PartSet_TestOCC.cpp @@ -9,7 +9,9 @@ #include #include #include -#include +#include +#include +#include #include @@ -17,7 +19,7 @@ #include static double myTestDelta; -static boost::shared_ptr myTestFeature; +static FeaturePtr myTestFeature; #include #include @@ -36,7 +38,7 @@ void PartSet_TestOCC::testSelection(XGUI_Workshop* theWorkshop) theWorkshop->viewer()->activeView()); PartSet_TestOCC::changeTestLine(theWorkshop); } - Handle(AIS_InteractiveObject) anIO = theWorkshop->displayer()->GetAISObject(myTestFeature); + Handle(AIS_InteractiveObject) anIO = theWorkshop->displayer()->getAISObject(myTestFeature); if (!anIO.IsNull()) { theWorkshop->viewer()->AISContext()->MoveTo(0, 0, theWorkshop->viewer()->activeView()); theWorkshop->viewer()->AISContext()->Select(0, 0, 2500, 2500, theWorkshop->viewer()->activeView()); @@ -126,13 +128,12 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) ModuleBase_Operation* anOperation = theWorkshop->operationMgr()->currentOperation(); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - boost::shared_ptr aSketch; + FeaturePtr aSketch; if (aPreviewOp) { // create a line boost::shared_ptr aDoc = ModelAPI_PluginManager::get()->rootDocument(); - boost::shared_ptr aFeature = aDoc->addFeature( - PartSet_OperationSketchLine::Type().c_str()); + FeaturePtr aFeature = aDoc->addFeature(SKETCH_LINE_KIND); if (aFeature) // TODO: generate an error if feature was not created aFeature->execute(); @@ -140,27 +141,37 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) boost::dynamic_pointer_cast(aPreviewOp->sketch()); aSketch->addSub(aFeature); - PartSet_OperationSketchLine::setLinePoint(aFeature, 100, 100, LINE_ATTR_START); - PartSet_OperationSketchLine::setLinePoint(aFeature, 150, 300, LINE_ATTR_END); + PartSet_FeaturePrs::setLinePoint(aFeature, 100, 100, LINE_ATTR_START); + PartSet_FeaturePrs::setLinePoint(aFeature, 150, 300, LINE_ATTR_END); - boost::shared_ptr aPreview = PartSet_OperationSketchLine::preview(aFeature); + boost::shared_ptr aPreview = PartSet_OperationSketchBase::preview(aFeature); XGUI_Displayer* aDisplayer = theWorkshop->displayer(); - aDisplayer->Redisplay(aFeature, aPreview ? aPreview->impl() : TopoDS_Shape(), false); + + Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( + aFeature, aSketch, + aPreview ? aPreview->impl() : TopoDS_Shape(), NULL); + if (!anAIS.IsNull()) + aDisplayer->redisplay(aFeature, anAIS, -1, false); + std::list aModes; aModes.push_back(TopAbs_VERTEX); aModes.push_back(TopAbs_EDGE); - aDisplayer->ActivateInLocalContext(aFeature, aModes, true); + aDisplayer->activateInLocalContext(aFeature, aModes, true); // change the line /*double aDelta = -200; for (int i = 0; i < 20; i++) { aDelta = aDelta - i*2; - PartSet_OperationSketchLine::setLinePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START); - PartSet_OperationSketchLine::setLinePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END); - boost::shared_ptr aPreview = PartSet_OperationSketchLine::preview(aFeature); + PartSet_FeaturePrs::setLinePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START); + PartSet_FeaturePrs::setLinePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END); - theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl() : TopoDS_Shape(), true); + boost::shared_ptr aPreview = PartSet_OperationSketchBase::preview(aFeature); + Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( + aFeature, aSketch, + aPreview ? aPreview->impl() : TopoDS_Shape(), NULL); + if (!anAIS.IsNull()) + aDisplayer->redisplay(aFeature, anAIS, -1, true); int aVal = 90; for (int j = 0; j < 10000000; j++) @@ -170,12 +181,12 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) //aModes.clear(); //aModes.push_back(TopAbs_VERTEX); //aModes.push_back(TopAbs_EDGE); - //aDisplayer->ActivateInLocalContext(aFeature, aModes, true); + //aDisplayer->activateInLocalContext(aFeature, aModes, true); myTestFeature = aFeature; std::list aPrs; - aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape())); - aDisplayer->SetSelected(aPrs, true); + aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape(), NULL)); + aDisplayer->setSelected(aPrs, true); } } @@ -184,26 +195,33 @@ void PartSet_TestOCC::changeTestLine(XGUI_Workshop* theWorkshop) // change the line if (!myTestFeature) return; - boost::shared_ptr aFeature = myTestFeature; + FeaturePtr aFeature = myTestFeature; myTestDelta = myTestDelta - 50; double aDelta = myTestDelta; - PartSet_OperationSketchLine::setLinePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START); - PartSet_OperationSketchLine::setLinePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END); - boost::shared_ptr aPreview = PartSet_OperationSketchLine::preview(aFeature); - - theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl() : TopoDS_Shape(), true); + PartSet_FeaturePrs::setLinePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START); + PartSet_FeaturePrs::setLinePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END); + boost::shared_ptr aPreview = PartSet_OperationSketchBase::preview(aFeature); + + Handle(AIS_InteractiveObject) aPrevAIS; + FeaturePtr aSketch;//NULL + Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( + aFeature, aSketch, + aPreview ? aPreview->impl() : TopoDS_Shape(), + aPrevAIS); + if (!anAIS.IsNull()) + theWorkshop->displayer()->redisplay(aFeature, anAIS, -1, true); //std::list aModes; //aModes.clear(); //aModes.push_back(TopAbs_VERTEX); //aModes.push_back(TopAbs_EDGE); - //aDisplayer->ActivateInLocalContext(aFeature, aModes, true); + //aDisplayer->activateInLocalContext(aFeature, aModes, true); /*std::list aPrs; aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape())); - theWorkshop->displayer()->SetSelected(aPrs, true);*/ + theWorkshop->displayer()->setSelected(aPrs, true);*/ - theWorkshop->displayer()->UpdateViewer(); + theWorkshop->displayer()->updateViewer(); } void PartSet_TestOCC::moveMouse(Handle(AIS_InteractiveContext) theContext, Handle(V3d_View) theView) diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 2c7a93b06..ae51d7b20 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -32,7 +32,7 @@ const double PRECISION_TOLERANCE = 0.000001; -gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theView) +gp_Pnt PartSet_Tools::convertClickToPoint(QPoint thePoint, Handle(V3d_View) theView) { if (theView.IsNull()) return gp_Pnt(); @@ -57,7 +57,7 @@ gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theV return ResultPoint; } -void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr theSketch, +void PartSet_Tools::convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch, Handle(V3d_View) theView, double& theX, double& theY) { if (!theSketch) @@ -103,7 +103,30 @@ void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptrx() + aVec.Y() * anY->y() + aVec.Z() * anY->z(); } -void PartSet_Tools::IntersectLines(double theX0, double theY0, double theX1, double theY1, +void PartSet_Tools::convertTo3D(const double theX, const double theY, + FeaturePtr theSketch, + gp_Pnt& thePoint) +{ + if (!theSketch) + return; + + boost::shared_ptr aData = theSketch->data(); + + boost::shared_ptr aC = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + boost::shared_ptr aX = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); + boost::shared_ptr aY = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); + + boost::shared_ptr aSum = aC->pnt()->xyz()->added( + aX->dir()->xyz()->multiplied(theX))->added(aY->dir()->xyz()->multiplied(theY)); + + boost::shared_ptr aPoint = boost::shared_ptr(new GeomAPI_Pnt(aSum)); + thePoint = gp_Pnt(aPoint->x(), aPoint->y(), aPoint->z()); +} + +void PartSet_Tools::intersectLines(double theX0, double theY0, double theX1, double theY1, double theX2, double theY2, double theX3, double theY3, double& theX, double& theY) { @@ -123,11 +146,11 @@ void PartSet_Tools::IntersectLines(double theX0, double theY0, double theX1, dou //It is not possible to use Precision::Confusion(), because it is e-0.8, but V is sometimes e-6 Standard_Real aPrec = PRECISION_TOLERANCE; if (fabs(theX - theX0) < aPrec && fabs(theY - theY0) < aPrec) { - ProjectPointOnLine(theX2, theY2, theX3, theY3, theX1, theY1, theX, theY); + projectPointOnLine(theX2, theY2, theX3, theY3, theX1, theY1, theX, theY); } } -void PartSet_Tools::ProjectPointOnLine(double theX1, double theY1, double theX2, double theY2, +void PartSet_Tools::projectPointOnLine(double theX1, double theY1, double theX2, double theY2, double thePointX, double thePointY, double& theX, double& theY) { theX = theY = 0; @@ -144,26 +167,26 @@ void PartSet_Tools::ProjectPointOnLine(double theX1, double theY1, double theX2, } } -boost::shared_ptr PartSet_Tools::NearestFeature(QPoint thePoint, +FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView, - boost::shared_ptr theSketch, + FeaturePtr theSketch, const std::list& theFeatures) { double aX, anY; - gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, theView); - PartSet_Tools::ConvertTo2D(aPoint, theSketch, theView, aX, anY); + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView); + PartSet_Tools::convertTo2D(aPoint, theSketch, theView, aX, anY); - boost::shared_ptr aFeature; + FeaturePtr aFeature; std::list::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end(); - boost::shared_ptr aDeltaFeature; + FeaturePtr aDeltaFeature; double aMinDelta = -1; XGUI_ViewerPrs aPrs; for (; anIt != aLast; anIt++) { aPrs = *anIt; if (!aPrs.feature()) continue; - double aDelta = DistanceToPoint(aPrs.feature(), aX, anY); + double aDelta = distanceToPoint(aPrs.feature(), aX, anY); if (aMinDelta < 0 || aMinDelta > aDelta) { aMinDelta = aDelta; aDeltaFeature = aPrs.feature(); @@ -172,11 +195,11 @@ boost::shared_ptr PartSet_Tools::NearestFeature(QPoint thePoin return aDeltaFeature; } -double PartSet_Tools::DistanceToPoint(boost::shared_ptr theFeature, +double PartSet_Tools::distanceToPoint(FeaturePtr theFeature, double theX, double theY) { double aDelta = 0; - if (theFeature->getKind() != "SketchLine") + if (theFeature->getKind() != SKETCH_LINE_KIND) return aDelta; boost::shared_ptr aData = theFeature->data(); @@ -187,7 +210,7 @@ double PartSet_Tools::DistanceToPoint(boost::shared_ptr theFea boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); double aX, anY; - PartSet_Tools::ProjectPointOnLine(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y(), theX, theY, aX, anY); + PartSet_Tools::projectPointOnLine(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y(), theX, theY, aX, anY); aDelta = gp_Pnt(theX, theY, 0).Distance(gp_Pnt(aX, anY, 0)); diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 957585b26..c8fa30660 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -11,12 +11,13 @@ #include +#include + #include #include class Handle_V3d_View; -class ModelAPI_Feature; class XGUI_ViewerPrs; /*! @@ -29,16 +30,25 @@ public: /// Converts the 2D screen point to the 3D point on the view according to the point of view /// \param thePoint a screen point /// \param theView a 3D view - static gp_Pnt ConvertClickToPoint(QPoint thePoint, Handle_V3d_View theView); + static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView); /// \brief Converts the 3D point to the projected coodinates on the sketch plane. /// \param thePoint the 3D point in the viewer /// \param theSketch the sketch feature /// \param theX the X coordinate /// \param theY the Y coordinate - static void ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr theSketch, + static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch, Handle(V3d_View) theView, double& theX, double& theY); + /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point. + /// \param theX the X coordinate + /// \param theY the Y coordinate + /// \param theSketch the sketch feature + /// \param thePoint the 3D point in the viewer + static void convertTo3D(const double theX, const double theY, + FeaturePtr theSketch, + gp_Pnt& thePoint); + /// Returns the point of intersection of the two lines, the first is (v0, v1), the second is (v2, v3), /// where vi - {xi,yi}. If the v0 is on the second line, the result is a projection of the v1 to this line /// \param theX0 the horizontal coordinate of 0 point @@ -51,7 +61,7 @@ public: /// \param theY3 the vertical coordinate of 3 point /// \param theX the output horizontal coordinate of the intersection point /// \param theY the outpup vertical coordinate of the intersection point - static void IntersectLines(double theX0, double theY0, double theX1, double theY1, + static void intersectLines(double theX0, double theY0, double theX1, double theY1, double theX2, double theY2, double theX3, double theY3, double& theX, double& theY); @@ -62,7 +72,7 @@ public: /// \param theY1 the vertical coordinate of the first line point /// \param theX2 the horizontal coordinate of the second line point /// \param theY2 the vertical coordinate of the second line point - static void ProjectPointOnLine(double theX1, double theY1, double theX2, double theY2, + static void projectPointOnLine(double theX1, double theY1, double theX2, double theY2, double thePointX, double thePointY, double& theX, double& theY); /// Returns a feature that is under the mouse point @@ -70,15 +80,15 @@ public: /// \param theView a 3D view /// \param theSketch the sketch feature /// \param theFeatures the list of selected presentations - static boost::shared_ptr NearestFeature(QPoint thePoint, Handle_V3d_View theView, - boost::shared_ptr theSketch, + static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, + FeaturePtr theSketch, const std::list& theFeatures); private: /// Return the distance between the feature and the point /// \param theFeature feature object /// \param theX the horizontal coordinate of the point /// \param theX the vertical coordinate of the point - static double DistanceToPoint(boost::shared_ptr theFeature, + static double distanceToPoint(FeaturePtr theFeature, double theX, double theY); }; diff --git a/src/PartSetPlugin/PartSetPlugin_Part.h b/src/PartSetPlugin/PartSetPlugin_Part.h index eaae463ad..0f9217271 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.h +++ b/src/PartSetPlugin/PartSetPlugin_Part.h @@ -8,6 +8,9 @@ #include "PartSetPlugin.h" #include +/// Part kind +const std::string PARTSET_PART_KIND("Part"); + /// part reference attribute const std::string PART_ATTR_DOC_REF = "PartDocument"; @@ -20,7 +23,7 @@ class PartSetPlugin_Part: public ModelAPI_Feature public: /// Returns the kind of a feature PARTSETPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "Part"; return MY_KIND;} + {static std::string MY_KIND = PARTSET_PART_KIND; return MY_KIND;} /// Returns to which group in the document must be added feature PARTSETPLUGIN_EXPORT virtual const std::string& getGroup() diff --git a/src/PartSetPlugin/PartSetPlugin_Plugin.cpp b/src/PartSetPlugin/PartSetPlugin_Plugin.cpp index 76ea7b441..4ba7fa5ca 100644 --- a/src/PartSetPlugin/PartSetPlugin_Plugin.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Plugin.cpp @@ -16,17 +16,17 @@ PartSetPlugin_Plugin::PartSetPlugin_Plugin() ModelAPI_PluginManager::get()->registerPlugin(this); } -boost::shared_ptr PartSetPlugin_Plugin::createFeature(string theFeatureID) +FeaturePtr PartSetPlugin_Plugin::createFeature(string theFeatureID) { - if (theFeatureID == "Part") { - return boost::shared_ptr(new PartSetPlugin_Part); + if (theFeatureID == PARTSET_PART_KIND) { + return FeaturePtr(new PartSetPlugin_Part); } if (theFeatureID == "duplicate") { - return boost::shared_ptr(new PartSetPlugin_Duplicate); + return FeaturePtr(new PartSetPlugin_Duplicate); } if (theFeatureID == "remove") { - return boost::shared_ptr(new PartSetPlugin_Remove); + return FeaturePtr(new PartSetPlugin_Remove); } // feature of such kind is not found - return boost::shared_ptr(); + return FeaturePtr(); } diff --git a/src/PartSetPlugin/PartSetPlugin_Plugin.h b/src/PartSetPlugin/PartSetPlugin_Plugin.h index ff577f79a..d1ccd314b 100644 --- a/src/PartSetPlugin/PartSetPlugin_Plugin.h +++ b/src/PartSetPlugin/PartSetPlugin_Plugin.h @@ -8,12 +8,13 @@ #include "PartSetPlugin.h" #include "ModelAPI_Plugin.h" +#include "ModelAPI_Feature.h" class PARTSETPLUGIN_EXPORT PartSetPlugin_Plugin: public ModelAPI_Plugin { public: /// Creates the feature object of this plugin by the feature string ID - virtual boost::shared_ptr createFeature(std::string theFeatureID); + virtual FeaturePtr createFeature(std::string theFeatureID); public: /// Is needed for python wrapping by swig diff --git a/src/PartSetPlugin/PartSetPlugin_Remove.cpp b/src/PartSetPlugin/PartSetPlugin_Remove.cpp index 5e99cb1f9..0e09f3a60 100644 --- a/src/PartSetPlugin/PartSetPlugin_Remove.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Remove.cpp @@ -15,8 +15,8 @@ void PartSetPlugin_Remove::execute() boost::shared_ptr aCurrent; boost::shared_ptr a; for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { - boost::shared_ptr aFeature = aRoot->feature(getGroup(), a, true); - if (aFeature->getKind() == "Part") { + FeaturePtr aFeature = aRoot->feature(getGroup(), a, true); + if (aFeature->getKind() == PARTSET_PART_KIND) { boost::shared_ptr aPart = boost::static_pointer_cast(aFeature); if (aPart->data()->docRef(PART_ATTR_DOC_REF)->value() == aPManager->currentDocument()) { diff --git a/src/PartSetPlugin/PartSetPlugin_Remove.h b/src/PartSetPlugin/PartSetPlugin_Remove.h index f12066c3e..87b7e258c 100644 --- a/src/PartSetPlugin/PartSetPlugin_Remove.h +++ b/src/PartSetPlugin/PartSetPlugin_Remove.h @@ -8,6 +8,9 @@ #include "PartSetPlugin.h" #include +/// Extrusion kind +const std::string PARTSET_REMOVE_KIND("Remove"); + /**\class PartSetPlugin_Remove * \ingroup DataModel * \brief Feature for creation of the new part in PartSet. @@ -17,7 +20,7 @@ class PartSetPlugin_Remove: public ModelAPI_Feature public: /// Returns the kind of a feature PARTSETPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "Remove"; return MY_KIND;} + {static std::string MY_KIND = PARTSET_REMOVE_KIND; return MY_KIND;} /// Returns to which group in the document must be added feature PARTSETPLUGIN_EXPORT virtual const std::string& getGroup() diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 9a4d7cf76..5c0f982e9 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -40,8 +40,12 @@ SET(PROJECT_LIBRARIES ModelAPI ) +SET(XML_RESOURCES + plugin-Sketch.xml +) + ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS}) -ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES}) TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES}) INCLUDE_DIRECTORIES( @@ -51,9 +55,5 @@ INCLUDE_DIRECTORIES( ../GeomDataAPI ) -SET(XML_RESOURCES - plugin-Sketch.xml -) - INSTALL(TARGETS SketchPlugin DESTINATION plugins) INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index f22e92b4c..928a76083 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -7,6 +7,10 @@ #include "SketchPlugin.h" #include +#include + +/// Arc feature kind +const std::string SKETCH_ARC_KIND("SketchArc"); /// Central 2D point of the circle which contains the arc const std::string ARC_ATTR_CENTER("ArcCenter"); @@ -24,11 +28,11 @@ class SketchPlugin_Arc: public SketchPlugin_Feature public: /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "SketchArc"; return MY_KIND;} + {static std::string MY_KIND = SKETCH_ARC_KIND; 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;} + {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); @@ -42,7 +46,7 @@ public: /// 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) {}; + const FeaturePtr& theFeature) {}; /// Use plugin manager for features creation SketchPlugin_Arc(); diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index 18fa1e71f..10fee4f7b 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -7,6 +7,10 @@ #include "SketchPlugin.h" #include +#include + +/// Circle feature kind +const std::string SKETCH_CIRCLE_KIND("SketchCircle"); /// 2D point - center of the circle const std::string CIRCLE_ATTR_CENTER("CircleCenter"); @@ -22,11 +26,11 @@ class SketchPlugin_Circle: public SketchPlugin_Feature public: /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "SketchCircle"; return MY_KIND;} + {static std::string MY_KIND = SKETCH_CIRCLE_KIND; 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;} + {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); @@ -40,7 +44,7 @@ public: /// 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) {}; + const FeaturePtr& theFeature) {}; /// Use plugin manager for features creation SketchPlugin_Circle(); diff --git a/src/SketchPlugin/SketchPlugin_Constraint.h b/src/SketchPlugin/SketchPlugin_Constraint.h index 98680830a..b4e8bcca6 100644 --- a/src/SketchPlugin/SketchPlugin_Constraint.h +++ b/src/SketchPlugin/SketchPlugin_Constraint.h @@ -7,6 +7,7 @@ #include "SketchPlugin.h" #include "SketchPlugin_Feature.h" +#include #include #include #include @@ -48,19 +49,15 @@ const std::string CONSTRAINT_ATTRIBUTES[CONSTRAINT_ATTR_SIZE] = class SketchPlugin_Constraint: public SketchPlugin_Feature { public: - /// \brief Returns the kind of a feature - SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "SketchConstraint"; return MY_KIND;} - /// \brief 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;} + {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} /** \brief 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) {} + const FeaturePtr& theFeature) {} protected: /// \brief Use plugin manager for features creation diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h index 1c5f2adf3..5da46cf88 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h @@ -7,8 +7,11 @@ #include "SketchPlugin.h" #include "SketchPlugin_Constraint.h" +#include #include +/// Coincidence constraint kind +const std::string SKETCH_CONSTRAINT_COINCIDENCE_KIND("SketchConstraintCoincidence"); /** \class SketchPlugin_ConstraintCoincidence * \ingroup DataModel @@ -22,11 +25,11 @@ class SketchPlugin_ConstraintCoincidence: public SketchPlugin_Constraint public: /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "SketchConstraintCoincidence"; return MY_KIND;} + {static std::string MY_KIND = SKETCH_CONSTRAINT_COINCIDENCE_KIND; return MY_KIND;} /// \brief 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;} + {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index 4295e8c2d..1a90e2dd3 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -7,8 +7,11 @@ #include "SketchPlugin.h" #include "SketchPlugin_Constraint.h" +#include #include +/// Distance constraint kind +const std::string SKETCH_CONSTRAINT_DISTANCE_KIND("SketchConstraintDistance"); /** \class SketchPlugin_ConstraintDistance * \ingroup DataModel @@ -23,11 +26,11 @@ class SketchPlugin_ConstraintDistance: public SketchPlugin_Constraint public: /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "SketchConstraintDistance"; return MY_KIND;} + {static std::string MY_KIND = SKETCH_CONSTRAINT_DISTANCE_KIND; return MY_KIND;} /// \brief 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;} + {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.h b/src/SketchPlugin/SketchPlugin_ConstraintLength.h index 3e4cde4a0..bc614e137 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.h @@ -7,8 +7,11 @@ #include "SketchPlugin.h" #include "SketchPlugin_Constraint.h" +#include #include +/// Length constraint kind +const std::string SKETCH_CONSTRAINT_LENGTH_KIND("SketchConstraintLength"); /** \class SketchPlugin_ConstraintLength * \ingroup DataModel @@ -22,11 +25,11 @@ class SketchPlugin_ConstraintLength: public SketchPlugin_Constraint public: /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "SketchConstraintLength"; return MY_KIND;} + {static std::string MY_KIND = SKETCH_CONSTRAINT_LENGTH_KIND; return MY_KIND;} /// \brief 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;} + {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h index dfc894d36..ac209b68f 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h @@ -6,8 +6,11 @@ #define SketchPlugin_ConstraintParallel_HeaderFile #include "SketchPlugin.h" +#include #include "SketchPlugin_Constraint.h" +/// Parallel constraint kind +const std::string SKETCH_CONSTRAINT_PARALLEL_KIND("SketchConstraintParallel"); /** \class SketchPlugin_ConstraintParallel * \ingroup DataModel @@ -21,11 +24,11 @@ class SketchPlugin_ConstraintParallel: public SketchPlugin_Constraint public: /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "SketchConstraintParallel"; return MY_KIND;} + {static std::string MY_KIND = SKETCH_CONSTRAINT_PARALLEL_KIND; return MY_KIND;} /// \brief 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;} + {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h index 6c5074a90..475c33084 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h @@ -6,8 +6,11 @@ #define SketchPlugin_ConstraintPerpendicular_HeaderFile #include "SketchPlugin.h" +#include #include "SketchPlugin_Constraint.h" +/// Perpendicular constraint kind +const std::string SKETCH_CONSTRAINT_PERPENDICULAR_KIND("SketchConstraintPerpendicular"); /** \class SketchPlugin_ConstraintPerpendicular * \ingroup DataModel @@ -21,11 +24,11 @@ class SketchPlugin_ConstraintPerpendicular: public SketchPlugin_Constraint public: /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "SketchConstraintPerpendicular"; return MY_KIND;} + {static std::string MY_KIND = SKETCH_CONSTRAINT_PERPENDICULAR_KIND; return MY_KIND;} /// \brief 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;} + {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h index 26a0ecbdc..bdfaa4297 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h @@ -6,8 +6,12 @@ #define SketchPlugin_ConstraintRadius_HeaderFile #include "SketchPlugin.h" +#include #include "SketchPlugin_Constraint.h" +/// Radius constraint kind +const std::string SKETCH_CONSTRAINT_RADIUS_KIND("SketchConstraintRadius"); + /** \class SketchPlugin_ConstraintRadius * \ingroup DataModel @@ -22,11 +26,11 @@ class SketchPlugin_ConstraintRadius: public SketchPlugin_Constraint public: /// \brief Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "SketchConstraintRadius"; return MY_KIND;} + {static std::string MY_KIND = SKETCH_CONSTRAINT_RADIUS_KIND; return MY_KIND;} /// \brief 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;} + {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_Feature.cpp b/src/SketchPlugin/SketchPlugin_Feature.cpp index ae771b556..7bda5720b 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.cpp +++ b/src/SketchPlugin/SketchPlugin_Feature.cpp @@ -29,9 +29,9 @@ SketchPlugin_Sketch* SketchPlugin_Feature::sketch() boost::shared_ptr aSketch = boost:: dynamic_pointer_cast(document()->feature("Construction", a, true)); if (aSketch) { - std::list > aList = + std::list aList = aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list(); - std::list >::iterator aSub = aList.begin(); + std::list::iterator aSub = aList.begin(); for(; aSub != aList.end(); aSub++) { if ((*aSub)->data()->isEqual(data())) { mySketch = aSketch.get(); diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index db6a6d660..8e59b5489 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -27,7 +27,7 @@ public: /// 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; + const FeaturePtr& theFeature) = 0; /// Returns true if this feature must be displayed in the history (top level of Part tree) SKETCHPLUGIN_EXPORT virtual bool isInHistory() {return false;} diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index 62dc6cfa9..6acefd294 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -7,8 +7,12 @@ #include "SketchPlugin.h" #include +#include #include +/// Line feature kind +const std::string SKETCH_LINE_KIND("SketchLine"); + /// Start 2D point of the line const std::string LINE_ATTR_START("StartPoint"); /// End 2D point of the line @@ -23,11 +27,11 @@ 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;} + {static std::string MY_KIND = SKETCH_LINE_KIND; 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;} + {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); @@ -41,7 +45,7 @@ public: /// 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) {}; + const FeaturePtr& theFeature) {}; /// Use plugin manager for features creation SketchPlugin_Line(); diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 23a6cf05a..14e61b236 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -24,38 +24,38 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() ModelAPI_PluginManager::get()->registerPlugin(this); } -boost::shared_ptr SketchPlugin_Plugin::createFeature(string theFeatureID) +FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID) { - if (theFeatureID == "Sketch") { - return boost::shared_ptr(new SketchPlugin_Sketch); + if (theFeatureID == SKETCH_KIND) { + return FeaturePtr(new SketchPlugin_Sketch); } - else if (theFeatureID == "SketchPoint") { - return boost::shared_ptr(new SketchPlugin_Point); + else if (theFeatureID == SKETCH_POINT_KIND) { + return FeaturePtr(new SketchPlugin_Point); } - else if (theFeatureID == "SketchLine") { - return boost::shared_ptr(new SketchPlugin_Line); + else if (theFeatureID == SKETCH_LINE_KIND) { + return FeaturePtr(new SketchPlugin_Line); } - else if (theFeatureID == "SketchCircle") { - return boost::shared_ptr(new SketchPlugin_Circle); + else if (theFeatureID == SKETCH_CIRCLE_KIND) { + return FeaturePtr(new SketchPlugin_Circle); } - else if (theFeatureID == "SketchConstraintCoincidence") { - return boost::shared_ptr(new SketchPlugin_ConstraintCoincidence); + else if (theFeatureID == SKETCH_CONSTRAINT_COINCIDENCE_KIND) { + return FeaturePtr(new SketchPlugin_ConstraintCoincidence); } - else if (theFeatureID == "SketchConstraintDistance") { - return boost::shared_ptr(new SketchPlugin_ConstraintDistance); + else if (theFeatureID == SKETCH_CONSTRAINT_DISTANCE_KIND) { + return FeaturePtr(new SketchPlugin_ConstraintDistance); } - else if (theFeatureID == "SketchConstraintLength") { - return boost::shared_ptr(new SketchPlugin_ConstraintLength); + else if (theFeatureID == SKETCH_CONSTRAINT_LENGTH_KIND) { + return FeaturePtr(new SketchPlugin_ConstraintLength); } - else if (theFeatureID == "SketchConstraintParallel") { - return boost::shared_ptr(new SketchPlugin_ConstraintParallel); + else if (theFeatureID == SKETCH_CONSTRAINT_PARALLEL_KIND) { + return FeaturePtr(new SketchPlugin_ConstraintParallel); } - else if (theFeatureID == "SketchConstraintPerpendicular") { - return boost::shared_ptr(new SketchPlugin_ConstraintPerpendicular); + else if (theFeatureID == SKETCH_CONSTRAINT_PERPENDICULAR_KIND) { + return FeaturePtr(new SketchPlugin_ConstraintPerpendicular); } - else if (theFeatureID == "SketchConstraintRadius") { - return boost::shared_ptr(new SketchPlugin_ConstraintRadius); + else if (theFeatureID == SKETCH_CONSTRAINT_RADIUS_KIND) { + return FeaturePtr(new SketchPlugin_ConstraintRadius); } // feature of such kind is not found - return boost::shared_ptr(); + return FeaturePtr(); } diff --git a/src/SketchPlugin/SketchPlugin_Plugin.h b/src/SketchPlugin/SketchPlugin_Plugin.h index f232b68fa..408ae73cc 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.h +++ b/src/SketchPlugin/SketchPlugin_Plugin.h @@ -8,12 +8,13 @@ #include "SketchPlugin.h" #include "ModelAPI_Plugin.h" +#include "ModelAPI_Feature.h" class SKETCHPLUGIN_EXPORT SketchPlugin_Plugin: public ModelAPI_Plugin { public: /// Creates the feature object of this plugin by the feature string ID - virtual boost::shared_ptr createFeature(std::string theFeatureID); + virtual FeaturePtr createFeature(std::string theFeatureID); public: /// Is needed for python wrapping by swig diff --git a/src/SketchPlugin/SketchPlugin_Point.h b/src/SketchPlugin/SketchPlugin_Point.h index b18bffb08..8d37e19e1 100644 --- a/src/SketchPlugin/SketchPlugin_Point.h +++ b/src/SketchPlugin/SketchPlugin_Point.h @@ -6,9 +6,13 @@ #define SketchPlugin_Point_HeaderFile #include "SketchPlugin.h" +#include #include "SketchPlugin_Feature.h" #include +/// Point feature kind +const std::string SKETCH_POINT_KIND("SketchPoint"); + /// Coordinates of the point const std::string POINT_ATTR_COORD("PointCoordindates"); @@ -21,11 +25,11 @@ class SketchPlugin_Point: public SketchPlugin_Feature public: /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "SketchPoint"; return MY_KIND;} + {static std::string MY_KIND = SKETCH_POINT_KIND; 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;} + {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;} /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); @@ -39,7 +43,7 @@ public: /// 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) {}; + const FeaturePtr& theFeature) {}; /// Use plugin manager for features creation SketchPlugin_Point(); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index a0adedd05..bc9d72735 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -83,7 +83,7 @@ const boost::shared_ptr& SketchPlugin_Sketch::preview() return getPreview(); } -const void SketchPlugin_Sketch::addSub(const boost::shared_ptr& theFeature) +const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature) { boost::dynamic_pointer_cast(theFeature)->setSketch(this); data()->reflist(SKETCH_ATTR_FEATURES)->append(theFeature); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 7c0894995..8337c8d24 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -10,6 +10,9 @@ #include #include +/// Sketch feature kind +const std::string SKETCH_KIND("Sketch"); + /// Origin point of the sketcher in 3D space const std::string SKETCH_ATTR_ORIGIN("Origin"); /// Vector X inside of the sketch plane @@ -30,7 +33,7 @@ class SketchPlugin_Sketch: public SketchPlugin_Feature public: /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() - {static std::string MY_KIND = "Sketch"; return MY_KIND;} + {static std::string MY_KIND = SKETCH_KIND; return MY_KIND;} /// Returns to which group in the document must be added feature SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() @@ -48,7 +51,7 @@ public: /// 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); + const FeaturePtr& theFeature); /// Converts a 2D sketch space point into point in 3D space SKETCHPLUGIN_EXPORT boost::shared_ptr to3D( diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index d91e6066c..be4bb9e41 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -1,7 +1,7 @@ - + @@ -20,7 +20,9 @@ - + + diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 2e8a1fae8..d4f55e00d 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -5,6 +5,16 @@ #include "SketchSolver_Constraint.h" #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include @@ -83,7 +93,7 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptrdata()->attribute(CONSTRAINT_ATTRIBUTES[indAttr]) ); if (!anAttr) continue; - if (anAttr->isFeature()) + if (anAttr->isFeature() && anAttr->feature()) { // verify posiible entities const std::string& aKind = anAttr->feature()->getKind(); - if (aKind.compare("SketchPoint") == 0) + if (aKind.compare(SKETCH_POINT_KIND) == 0) { myAttributesList[aNbPoints++] = CONSTRAINT_ATTRIBUTES[indAttr]; continue; } - else if(aKind.compare("SketchLine") == 0) + else if(aKind.compare(SKETCH_LINE_KIND) == 0) { // entities are placed starting from CONSTRAINT_ATTR_ENTITY_C attribute myAttributesList[2 + aNbEntities++] = CONSTRAINT_ATTRIBUTES[indAttr]; @@ -139,7 +149,7 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptrdata()->attribute(CONSTRAINT_ATTRIBUTES[indAttr]) ); if (!anAttr) continue; - if (anAttr->isFeature() && anAttr->feature()->getKind().compare("SketchLine") == 0) + if (anAttr->isFeature() && anAttr->feature() && + anAttr->feature()->getKind().compare(SKETCH_LINE_KIND) == 0) { myAttributesList[aNbLines++] = CONSTRAINT_ATTRIBUTES[indAttr]; break; @@ -161,8 +172,8 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptrisFeature()) continue; const std::string& aKind = anAttr->feature()->getKind(); - if (aKind.compare("SketchLine") == 0) + if (aKind.compare(SKETCH_LINE_KIND) == 0) { myAttributesList[aNbEntities++] = CONSTRAINT_ATTRIBUTES[indAttr]; continue; @@ -186,7 +197,7 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptrisFeature()) continue; const std::string& aKind = anAttr->feature()->getKind(); - if (aKind.compare("SketchCircle") == 0 || aKind.compare("SketchArc") == 0) + if (aKind.compare(SKETCH_CIRCLE_KIND) == 0 || aKind.compare(SKETCH_ARC_KIND) == 0) { myAttributesList[aNbEntities++] = CONSTRAINT_ATTRIBUTES[indAttr]; continue; diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp index 7c0bd3784..186e80505 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp @@ -15,6 +15,8 @@ #include #include +#include +#include #include #include @@ -186,7 +188,7 @@ bool SketchSolver_ConstraintGroup::changeConstraint( if (!aConstrAttr) continue; // For the length constraint the start and end points of the line should be added to the entities list instead of line - if (aConstrType == SLVS_C_PT_PT_DISTANCE && theConstraint->getKind().compare("SketchConstraintLength") == 0) + if (aConstrType == SLVS_C_PT_PT_DISTANCE && theConstraint->getKind().compare(SKETCH_CONSTRAINT_LENGTH_KIND) == 0) { boost::shared_ptr aData = aConstrAttr->feature()->data(); aConstrEnt[indAttr] = changeEntity(aData->attribute(LINE_ATTR_START)); @@ -315,10 +317,10 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( // Purpose: create/update the element defined by the feature affected by any constraint // ============================================================================ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( - boost::shared_ptr theEntity) + FeaturePtr theEntity) { // If the entity is already in the group, try to find it - std::map, Slvs_hEntity>::const_iterator + std::map::const_iterator aEntIter = myEntityFeatMap.find(theEntity); // defines that the entity already exists const bool isEntExists = (myEntityFeatMap.find(theEntity) != myEntityFeatMap.end()); @@ -331,7 +333,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( const std::string& aFeatureKind = aFeature->getKind(); // Line - if (aFeatureKind.compare("SketchLine") == 0) + if (aFeatureKind.compare(SKETCH_LINE_KIND) == 0) { Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(LINE_ATTR_START)); Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(LINE_ATTR_END)); @@ -346,7 +348,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( return aLineEntity.h; } // Circle - else if (aFeatureKind.compare("SketchCircle") == 0) + else if (aFeatureKind.compare(SKETCH_CIRCLE_KIND) == 0) { Slvs_hEntity aCenter = changeEntity(aFeature->data()->attribute(CIRCLE_ATTR_CENTER)); Slvs_hEntity aRadius = changeEntity(aFeature->data()->attribute(CIRCLE_ATTR_RADIUS)); @@ -362,7 +364,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( return aCircleEntity.h; } // Arc - else if (aFeatureKind.compare("SketchArc") == 0) + else if (aFeatureKind.compare(SKETCH_ARC_KIND) == 0) { Slvs_hEntity aCenter = changeEntity(aFeature->data()->attribute(ARC_ATTR_CENTER)); Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(ARC_ATTR_START)); @@ -378,7 +380,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( return anArcEntity.h; } // Point (it has low probability to be an attribute of constraint, so it is checked at the end) - else if (aFeatureKind.compare("SketchPoint") == 0) + else if (aFeatureKind.compare(SKETCH_POINT_KIND) == 0) { Slvs_hEntity aPoint = changeEntity(aFeature->data()->attribute(POINT_ATTR_COORD)); @@ -461,7 +463,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeNormal( bool SketchSolver_ConstraintGroup::addWorkplane( boost::shared_ptr theSketch) { - if (myWorkplane.h || theSketch->getKind().compare("Sketch") != 0) + if (myWorkplane.h || theSketch->getKind().compare(SKETCH_KIND) != 0) return false; // the workplane already exists or the function parameter is not Sketch mySketch = theSketch; @@ -744,7 +746,7 @@ bool SketchSolver_ConstraintGroup::updateGroup() { if (!aConstrIter->first->data()->isValid()) { - if (aConstrIter->first->getKind().compare("SketchConstraintCoincidence") == 0) + if (aConstrIter->first->getKind().compare(SKETCH_CONSTRAINT_COINCIDENCE_KIND) == 0) isCCRemoved = true; std::map, Slvs_hConstraint>::reverse_iterator aCopyIter = aConstrIter++; @@ -994,13 +996,13 @@ void SketchSolver_ConstraintGroup::removeConstraint(boost::shared_ptr, Slvs_hEntity>::iterator + std::map::iterator anEntFeatIter = myEntityFeatMap.begin(); while (anEntFeatIter != myEntityFeatMap.end()) { if (anEntToRemove.find(anEntFeatIter->second) != anEntToRemove.end()) { - std::map, Slvs_hEntity>::iterator + std::map::iterator aRemovedIter = anEntFeatIter; anEntFeatIter++; myEntityFeatMap.erase(aRemovedIter); diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.h b/src/SketchSolver/SketchSolver_ConstraintGroup.h index 7baeac158..69c1a7c04 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.h +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.h @@ -104,7 +104,7 @@ protected: * \return identifier of changed entity or 0 if entity could not be changed */ Slvs_hEntity changeEntity(boost::shared_ptr theEntity); - Slvs_hEntity changeEntity(boost::shared_ptr theEntity); + Slvs_hEntity changeEntity(FeaturePtr theEntity); /** \brief Adds or updates a normal in the group * @@ -192,7 +192,7 @@ private: myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints std::map, Slvs_hEntity> myEntityAttrMap; ///< The map between "attribute" parameters of constraints and their equivalent SolveSpace entities - std::map, Slvs_hEntity> + std::map myEntityFeatMap; ///< The map between "feature" parameters of constraints and their equivalent SolveSpace entities // Conincident items diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index dd502982b..e91d65a16 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -64,17 +64,17 @@ void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessa theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_MOVED)) { const Model_FeatureUpdatedMessage* anUpdateMsg = dynamic_cast(theMessage); - std::set< boost::shared_ptr > aFeatures = anUpdateMsg->features(); + std::set< FeaturePtr > aFeatures = anUpdateMsg->features(); bool isModifiedEvt = theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_MOVED); if (!isModifiedEvt) { - std::set< boost::shared_ptr >::iterator aFeatIter; + std::set< FeaturePtr >::iterator aFeatIter; for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { // Only sketches and constraints can be added by Create event const std::string& aFeatureKind = (*aFeatIter)->getKind(); - if (aFeatureKind.compare("Sketch") == 0) + if (aFeatureKind.compare(SKETCH_KIND) == 0) { boost::shared_ptr aSketch = boost::dynamic_pointer_cast(*aFeatIter); @@ -105,10 +105,10 @@ void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessa const Model_FeatureDeletedMessage* aDeleteMsg = dynamic_cast(theMessage); const std::set& aFeatureGroups = aDeleteMsg->groups(); - // Find "Sketch" in groups. The constraint groups should be updated when an object removed from Sketch + // Find SKETCH_KIND in groups. The constraint groups should be updated when an object removed from Sketch std::set::const_iterator aFGrIter; for (aFGrIter = aFeatureGroups.begin(); aFGrIter != aFeatureGroups.end(); aFGrIter++) - if (aFGrIter->compare("Sketch") == 0) + if (aFGrIter->compare(SKETCH_KIND) == 0) break; if (aFGrIter != aFeatureGroups.end()) @@ -256,22 +256,22 @@ void SketchSolver_ConstraintManager::updateEntity(boost::shared_ptr anAttrList; const std::string& aFeatureKind = theFeature->getKind(); // Point - if (aFeatureKind.compare("SketchPoint") == 0) + if (aFeatureKind.compare(SKETCH_POINT_KIND) == 0) anAttrList.push_back(POINT_ATTR_COORD); // Line - else if (aFeatureKind.compare("SketchLine") == 0) + else if (aFeatureKind.compare(SKETCH_LINE_KIND) == 0) { anAttrList.push_back(LINE_ATTR_START); anAttrList.push_back(LINE_ATTR_END); } // Circle - else if (aFeatureKind.compare("SketchCircle") == 0) + else if (aFeatureKind.compare(SKETCH_CIRCLE_KIND) == 0) { anAttrList.push_back(CIRCLE_ATTR_CENTER); anAttrList.push_back(CIRCLE_ATTR_RADIUS); } // Arc - else if (aFeatureKind.compare("SketchArc") == 0) + else if (aFeatureKind.compare(SKETCH_ARC_KIND) == 0) { anAttrList.push_back(ARC_ATTR_CENTER); anAttrList.push_back(ARC_ATTR_START); @@ -343,8 +343,8 @@ boost::shared_ptr SketchSolver_ConstraintManager::findWork boost::shared_ptr aWPFeatures = boost::dynamic_pointer_cast(aWP->data()->attribute(SKETCH_ATTR_FEATURES)); - std::list< boost::shared_ptr > aFeaturesList = aWPFeatures->list(); - std::list< boost::shared_ptr >::const_iterator anIter; + std::list< FeaturePtr > aFeaturesList = aWPFeatures->list(); + std::list< FeaturePtr >::const_iterator anIter; for (anIter = aFeaturesList.begin(); anIter != aFeaturesList.end(); anIter++) if (*anIter == theConstraint) return aWP; // workplane is found diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index ea9af50b6..1775cb125 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -1,4 +1,3 @@ -INCLUDE(FindCAS) SET(CMAKE_AUTOMOC ON) @@ -33,6 +32,7 @@ SET(PROJECT_HEADERS XGUI_ViewerPrs.h XGUI_PropertyPanel.h XGUI_ContextMenuMgr.h + XGUI_ModuleConnector.h ) SET(PROJECT_AUTOMOC @@ -64,6 +64,7 @@ SET(PROJECT_SOURCES XGUI_ViewerPrs.cpp XGUI_PropertyPanel.cpp XGUI_ContextMenuMgr.cpp + XGUI_ModuleConnector.cpp ) SET(PROJECT_RESOURCES @@ -116,6 +117,7 @@ INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Events ${PROJECT_SOURCE_DIR}/src/ModelAPI ${PROJECT_SOURCE_DIR}/src/Model ${PROJECT_SOURCE_DIR}/src/ModuleBase + ${PROJECT_SOURCE_DIR}/src/PartSetPlugin ${CAS_INCLUDE_DIRS}) LINK_DIRECTORIES($ENV{PYTHON_LIB_DIR}) diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 0abbb09ff..b114aa315 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -5,6 +5,8 @@ #include "XGUI_SelectionMgr.h" #include "XGUI_Displayer.h" +#include "PartSetPlugin_Part.h" + #include #include #include @@ -96,7 +98,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const FeaturePtr aFeature = aFeatures.first(); //Process Feature if (aFeature) { - if (aFeature->getKind() == "Part") { + if (aFeature->getKind() == PARTSET_PART_KIND) { ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); DocumentPtr aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value(); if (aMgr->currentDocument() == aFeaDoc) @@ -107,7 +109,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const aMenu->addAction(action("EDIT_CMD")); XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - if (aDisplayer->IsVisible(aFeature)) + if (aDisplayer->isVisible(aFeature)) aMenu->addAction(action("HIDE_CMD")); else aMenu->addAction(action("SHOW_CMD")); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index d81b6e59f..54f3728ed 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -31,17 +32,17 @@ XGUI_Displayer::~XGUI_Displayer() { } -bool XGUI_Displayer::IsVisible(boost::shared_ptr theFeature) +bool XGUI_Displayer::isVisible(FeaturePtr theFeature) { return myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end(); } -void XGUI_Displayer::Display(boost::shared_ptr theFeature, - const bool isUpdateViewer) -{ -} +//void XGUI_Displayer::Display(FeaturePtr theFeature, +// const bool isUpdateViewer) +//{ +//} -/*void XGUI_Displayer::Display(boost::shared_ptr theFeature, +/*void XGUI_Displayer::Display(FeaturePtr theFeature, const TopoDS_Shape& theShape, const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); @@ -51,34 +52,36 @@ void XGUI_Displayer::Display(boost::shared_ptr theFeature, aContext->Display(anAIS, Standard_False); if (isUpdateViewer) - UpdateViewer(); + updateViewer(); }*/ -std::list XGUI_Displayer::GetSelected(const int theShapeTypeToSkip) +std::list XGUI_Displayer::getSelected(const int theShapeTypeToSkip) { - std::set > aPrsFeatures; + std::set aPrsFeatures; std::list aPresentations; Handle(AIS_InteractiveContext) aContext = AISContext(); for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); TopoDS_Shape aShape = aContext->SelectedShape(); + if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip) continue; - boost::shared_ptr aFeature = GetFeature(anIO); + FeaturePtr aFeature = getFeature(anIO); if (aPrsFeatures.find(aFeature) != aPrsFeatures.end()) continue; - aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape)); + Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); + aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, anOwner)); aPrsFeatures.insert(aFeature); } return aPresentations; } -std::list XGUI_Displayer::GetHighlighted(const int theShapeTypeToSkip) +std::list XGUI_Displayer::getHighlighted(const int theShapeTypeToSkip) { - std::set > aPrsFeatures; + std::set aPrsFeatures; std::list aPresentations; Handle(AIS_InteractiveContext) aContext = AISContext(); @@ -88,17 +91,17 @@ std::list XGUI_Displayer::GetHighlighted(const int theShapeTypeT if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip) continue; - boost::shared_ptr aFeature = GetFeature(anIO); + FeaturePtr aFeature = getFeature(anIO); if (aPrsFeatures.find(aFeature) != aPrsFeatures.end()) continue; - aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape)); + aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, NULL)); aPrsFeatures.insert(aFeature); } return aPresentations; } -void XGUI_Displayer::Erase(boost::shared_ptr theFeature, +void XGUI_Displayer::erase(FeaturePtr theFeature, const bool isUpdateViewer) { if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end()) @@ -114,12 +117,15 @@ void XGUI_Displayer::Erase(boost::shared_ptr theFeature, myFeature2AISObjectMap.erase(theFeature); if (isUpdateViewer) - UpdateViewer(); + updateViewer(); } -void XGUI_Displayer::Redisplay(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape, const bool isUpdateViewer) +bool XGUI_Displayer::redisplay(FeaturePtr theFeature, + Handle(AIS_InteractiveObject) theAIS, + const int theSelectionMode, + const bool isUpdateViewer) { + bool isCreated = false; Handle(AIS_InteractiveContext) aContext = AISContext(); // Open local context if there is no one if (!aContext->HasOpenedContext()) { @@ -130,30 +136,28 @@ void XGUI_Displayer::Redisplay(boost::shared_ptr theFeature, //aContext->SetPixelTolerance(MOUSE_SENSITIVITY_IN_PIXEL); } // display or redisplay presentation - Handle(AIS_Shape) anAIS; - if (IsVisible(theFeature)) { - anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]); - if (!anAIS.IsNull()) { - // if the AIS object is displayed in the opened local context in some mode, additional - // AIS sub objects are created there. They should be rebuild for correct selecting. - // It is possible to correct it by closing local context before the shape set and opening - // after. Another workaround to thrown down the selection and reselecting the AIS. - // If there was a problem here, try the first solution with close/open local context. - anAIS->Set(theShape); - anAIS->Redisplay(Standard_True); - aContext->RecomputeSelectionOnly(anAIS); - } + if (isVisible(theFeature) && !myFeature2AISObjectMap[theFeature].IsNull()) { + aContext->RecomputeSelectionOnly(theAIS); } else { - anAIS = new AIS_Shape(theShape); - myFeature2AISObjectMap[theFeature] = anAIS; - aContext->Display(anAIS, false); + myFeature2AISObjectMap[theFeature] = theAIS; + if (theSelectionMode < 0) + { + aContext->Display(theAIS, false); + } + else + { + aContext->Display(theAIS, 0, theSelectionMode, false); + } + isCreated = true; } if (isUpdateViewer) - UpdateViewer(); + updateViewer(); + + return isCreated; } -void XGUI_Displayer::ActivateInLocalContext(boost::shared_ptr theFeature, +void XGUI_Displayer::activateInLocalContext(FeaturePtr theFeature, const std::list& theModes, const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); @@ -164,7 +168,7 @@ void XGUI_Displayer::ActivateInLocalContext(boost::shared_ptr } // display or redisplay presentation Handle(AIS_Shape) anAIS; - if (IsVisible(theFeature)) + if (isVisible(theFeature)) anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]); // Activate selection of objects from prs @@ -180,20 +184,20 @@ void XGUI_Displayer::ActivateInLocalContext(boost::shared_ptr } if (isUpdateViewer) - UpdateViewer(); + updateViewer(); } -void XGUI_Displayer::StopSelection(const std::list& theFeatures, const bool isStop, +void XGUI_Displayer::stopSelection(const std::list& theFeatures, const bool isStop, const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); Handle(AIS_Shape) anAIS; std::list::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end(); - boost::shared_ptr aFeature; + FeaturePtr aFeature; for (; anIt != aLast; anIt++) { aFeature = (*anIt).feature(); - if (IsVisible(aFeature)) + if (isVisible(aFeature)) anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]); if (anAIS.IsNull()) continue; @@ -210,15 +214,15 @@ void XGUI_Displayer::StopSelection(const std::list& theFeatures, } } if (isUpdateViewer) - UpdateViewer(); + updateViewer(); } -void XGUI_Displayer::SetSelected(const std::list& theFeatures, const bool isUpdateViewer) +void XGUI_Displayer::setSelected(const std::list& theFeatures, const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); std::list::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end(); - boost::shared_ptr aFeature; + FeaturePtr aFeature; Handle(AIS_Shape) anAIS; // we need to unhighligth objects manually in the current local context @@ -230,7 +234,7 @@ void XGUI_Displayer::SetSelected(const std::list& theFeatures, c for (; anIt != aLast; anIt++) { aFeature = (*anIt).feature(); - if (IsVisible(aFeature)) + if (isVisible(aFeature)) anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]); if (anAIS.IsNull()) continue; @@ -238,10 +242,10 @@ void XGUI_Displayer::SetSelected(const std::list& theFeatures, c } if (isUpdateViewer) - UpdateViewer(); + updateViewer(); } -void XGUI_Displayer::EraseAll(const bool isUpdateViewer) +/*void XGUI_Displayer::EraseAll(const bool isUpdateViewer) { Handle(AIS_InteractiveContext) ic = AISContext(); @@ -258,19 +262,19 @@ void XGUI_Displayer::EraseAll(const bool isUpdateViewer) } myFeature2AISObjectMap.clear(); if (isUpdateViewer) - UpdateViewer(); -} + updateViewer(); +}*/ -void XGUI_Displayer::EraseDeletedFeatures(const bool isUpdateViewer) +void XGUI_Displayer::eraseDeletedFeatures(const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(), aFLast = myFeature2AISObjectMap.end(); - std::list> aRemoved; + std::list aRemoved; for (; aFIt != aFLast; aFIt++) { - boost::shared_ptr aFeature = (*aFIt).first; + FeaturePtr aFeature = (*aFIt).first; if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) { Handle(AIS_InteractiveObject) anAIS = (*aFIt).second; if (!anAIS.IsNull()) { @@ -279,23 +283,23 @@ void XGUI_Displayer::EraseDeletedFeatures(const bool isUpdateViewer) } } } - std::list>::const_iterator anIt = aRemoved.begin(), + std::list::const_iterator anIt = aRemoved.begin(), aLast = aRemoved.end(); for (; anIt != aLast; anIt++) { myFeature2AISObjectMap.erase(myFeature2AISObjectMap.find(*anIt)); } if (isUpdateViewer) - UpdateViewer(); + updateViewer(); } -void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer) +void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer) { - CloseAllContexts(true); + closeAllContexts(true); } -Handle(AIS_InteractiveObject) XGUI_Displayer::GetAISObject( - boost::shared_ptr theFeature) const +Handle(AIS_InteractiveObject) XGUI_Displayer::getAISObject( + FeaturePtr theFeature) const { Handle(AIS_InteractiveObject) anIO; if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) @@ -303,9 +307,9 @@ Handle(AIS_InteractiveObject) XGUI_Displayer::GetAISObject( return anIO; } -boost::shared_ptr XGUI_Displayer::GetFeature(Handle(AIS_InteractiveObject) theIO) const +FeaturePtr XGUI_Displayer::getFeature(Handle(AIS_InteractiveObject) theIO) const { - boost::shared_ptr aFeature; + FeaturePtr aFeature; FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(), aFLast = myFeature2AISObjectMap.end(); for (; aFIt != aFLast && !aFeature; aFIt++) { @@ -317,17 +321,17 @@ boost::shared_ptr XGUI_Displayer::GetFeature(Handle(AIS_Intera return aFeature; } -void XGUI_Displayer::CloseAllContexts(const bool isUpdateViewer) +void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer) { Handle(AIS_InteractiveContext) ic = AISContext(); if (!ic.IsNull()) { ic->CloseAllContexts(false); if (isUpdateViewer) - UpdateViewer(); + updateViewer(); } } -void XGUI_Displayer::UpdateViewer() +void XGUI_Displayer::updateViewer() { Handle(AIS_InteractiveContext) ic = AISContext(); if (!ic.IsNull()) diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 6606ebf06..b8389af5d 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -15,6 +15,8 @@ #include #include +#include + #include #include @@ -44,91 +46,97 @@ public: /// Returns the feature visibility state. /// \param theFeature a feature instance - bool IsVisible(boost::shared_ptr theFeature); + bool isVisible(FeaturePtr theFeature); /// Display the feature. Obtain the visualized object from the feature. /// \param theFeature a feature instance /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void Display(boost::shared_ptr theFeature, const bool isUpdateViewer = true); + //void Display(FeaturePtr theFeature, const bool isUpdateViewer = true); /// Display the feature and a shape. This shape would be associated to the given feature /// \param theFeature a feature instance /// \param theShape a shape /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - //void Display(boost::shared_ptr theFeature, const TopoDS_Shape& theShape, + //void Display(FeaturePtr theFeature, const TopoDS_Shape& theShape, // const bool isUpdateViewer = true); /// Returns a list of viewer selected presentations /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build /// \return list of presentations - std::list GetSelected(const int theShapeTypeToSkip = -1); + std::list getSelected(const int theShapeTypeToSkip = -1); /// Returns a list of viewer highlited presentations /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build /// \return list of presentations - std::list GetHighlighted(const int theShapeTypeToSkip = -1); + std::list getHighlighted(const int theShapeTypeToSkip = -1); /// Display the shape and activate selection of sub-shapes /// \param theFeature a feature instance - /// \param theShape a shape - /// \param theMode a local selection mode + /// \param theAIS an AIS object + /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + /// \returns true if the presentation is created + bool redisplay(FeaturePtr theFeature, + Handle(AIS_InteractiveObject) theAIS, + const int theSelectionMode, const bool isUpdateViewer = true); + + /// Redisplay the shape and activate selection of sub-shapes + /// \param theFeature a feature instance /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void Redisplay(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape, const bool isUpdateViewer = true); + //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true); /// Display the shape and activate selection of sub-shapes /// \param theFeature a feature instance /// \param theShape a shape /// \param theMode a list of local selection modes /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void ActivateInLocalContext(boost::shared_ptr theFeature, + void activateInLocalContext(FeaturePtr theFeature, const std::list& theModes, const bool isUpdateViewer = true); /// Stop the current selection and color the given features to the selection color /// \param theFeatures a list of features to be disabled /// \param theToStop the boolean state whether it it stopped or non stopped /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void StopSelection(const std::list& theFeatures, const bool isStop, + void stopSelection(const std::list& theFeatures, const bool isStop, const bool isUpdateViewer); /// Set the features are selected /// \param theFeatures a list of features to be selected /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void SetSelected(const std::list& theFeatures, const bool isUpdateViewer); + void setSelected(const std::list& theFeatures, const bool isUpdateViewer); /// Erase the feature and a shape. /// \param theFeature a feature instance /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void Erase(boost::shared_ptr theFeature, const bool isUpdateViewer = true); + void erase(FeaturePtr theFeature, const bool isUpdateViewer = true); /// Erase all presentations /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void EraseAll(const bool isUpdateViewer = true); + //void EraseAll(const bool isUpdateViewer = true); /// Erase AIS interactive objects, which has an empty feature in the internal map /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void EraseDeletedFeatures(const bool isUpdateViewer = true); + void eraseDeletedFeatures(const bool isUpdateViewer = true); /// Deactivates selection of sub-shapes /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void CloseLocalContexts(const bool isUpdateViewer = true); + void closeLocalContexts(const bool isUpdateViewer = true); /// Updates the viewer - void UpdateViewer(); + void updateViewer(); /// Searches the interactive object by feature - /// \param feature the feature or NULL if it not visualized + /// \param theFeature the feature or NULL if it not visualized /// \return theIO an interactive object - Handle(AIS_InteractiveObject) GetAISObject(boost::shared_ptr) const; + Handle(AIS_InteractiveObject) getAISObject(FeaturePtr theFeature) const; protected: /// Searches the feature by interactive object /// \param theIO an interactive object /// \return feature the feature or NULL if it not visualized - boost::shared_ptr GetFeature(Handle(AIS_InteractiveObject) theIO) const; + FeaturePtr getFeature(Handle(AIS_InteractiveObject) theIO) const; /// Deactivate local selection /// \param isUpdateViewer the state wether the viewer should be updated immediatelly - void CloseAllContexts(const bool isUpdateViewer); + void closeAllContexts(const bool isUpdateViewer); /// Returns currently installed AIS_InteractiveContext Handle(AIS_InteractiveContext) AISContext() const; @@ -136,7 +144,7 @@ protected: protected: XGUI_Workshop* myWorkshop; - typedef std::map, Handle(AIS_InteractiveObject) > FeatureToAISMap; + typedef std::map FeatureToAISMap; FeatureToAISMap myFeature2AISObjectMap; }; diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp new file mode 100644 index 000000000..542eca0cf --- /dev/null +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -0,0 +1,33 @@ +// File: XGUI_ModuleConnector.cpp +// Created: 3 June 2014 +// Author: Vitaly Smetannikov + + +#include "XGUI_ModuleConnector.h" +#include "XGUI_Workshop.h" +#include "XGUI_ViewerProxy.h" +#include "XGUI_SelectionMgr.h" + + + +XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop) +: ModuleBase_IWorkshop(theWorkshop), myWorkshop(theWorkshop) +{ + XGUI_SelectionMgr* aSelector = myWorkshop->selector(); + connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); +} + +XGUI_ModuleConnector::~XGUI_ModuleConnector() +{ +} + +Handle(AIS_InteractiveContext) XGUI_ModuleConnector::AISContext() const +{ + return myWorkshop->viewer()->AISContext(); +} + + +QFeatureList XGUI_ModuleConnector::selectedFeatures() const +{ + return myWorkshop->selector()->selectedFeatures(); +} \ No newline at end of file diff --git a/src/XGUI/XGUI_ModuleConnector.h b/src/XGUI/XGUI_ModuleConnector.h new file mode 100644 index 000000000..04d7b3ef1 --- /dev/null +++ b/src/XGUI/XGUI_ModuleConnector.h @@ -0,0 +1,38 @@ +// File: XGUI_ModuleConnector.h +// Created: 3 June 2014 +// Author: Vitaly Smetannikov + +#ifndef XGUI_ModuleConnector_H +#define XGUI_ModuleConnector_H + + +#include "XGUI.h" +#include "XGUI_Constants.h" + +#include + +class Handle_AIS_InteractiveContext; +class XGUI_Workshop; + +/** +* Implementation of IWorkshop interface which provides access to Workshop sevices at module level +*/ +class XGUI_EXPORT XGUI_ModuleConnector: public ModuleBase_IWorkshop +{ + Q_OBJECT +public: + XGUI_ModuleConnector(XGUI_Workshop* theWorkshop); + + virtual ~XGUI_ModuleConnector(); + + //! Returns AIS_InteractiveContext from current OCCViewer + virtual Handle(AIS_InteractiveContext) AISContext() const; + + //! Returns list of currently selected data objects + QFeatureList selectedFeatures() const; + +private: + XGUI_Workshop* myWorkshop; +}; + +#endif \ No newline at end of file diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 125e1aaf4..818e72210 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -146,7 +146,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) aLabelWgt->setFrameShape(myTreeView->frameShape()); aLabelWgt->setFrameShadow(myTreeView->frameShadow()); - connect(myTreeView, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); + connect(myTreeView, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr))); connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr))); @@ -315,4 +315,11 @@ void XGUI_ObjectsBrowser::onEditItem() myActiveDocLbl->setProperty("OldText", myActiveDocLbl->text()); } } +} + +//*************************************************** +void XGUI_ObjectsBrowser::onSelectionChanged() +{ + myFeaturesList = myTreeView->selectedFeatures(); + emit selectionChanged(); } \ No newline at end of file diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index b8e275ae6..8e4842df5 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -96,6 +96,8 @@ private slots: //! Called on Edit command request void onEditItem(); + void onSelectionChanged(); + private: void closeDocNameEditing(bool toSave); diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index f511a5750..ce30a89c1 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -119,7 +119,7 @@ QWidget* XGUI_PropertyPanel::contentWidget() return myCustomWidget; } -void XGUI_PropertyPanel::updateContentWidget(boost::shared_ptr theFeature) +void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature) { foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) { eachWidget->restoreValue(theFeature); diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index d034d7289..67c9857c3 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -30,7 +30,7 @@ public: virtual bool eventFilter(QObject *theObject, QEvent *theEvent); public slots: - void updateContentWidget(boost::shared_ptr theFeature); + void updateContentWidget(FeaturePtr theFeature); /// slot to set the focus to the widget visualized an attribute with the given name /// \param theAttributteName void onFocusActivated(const std::string& theAttributeName); diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 339d08369..3148bc274 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -56,13 +56,13 @@ QRect makeRect(const int x1, const int y1, const int x2, const int y2) } //****************************************************************** -bool isModelObject(boost::shared_ptr theFeature) +bool isModelObject(FeaturePtr theFeature) { return theFeature && !theFeature->data(); } //****************************************************************** -std::string featureInfo(boost::shared_ptr theFeature) +std::string featureInfo(FeaturePtr theFeature) { std::ostringstream aStream; if (theFeature) diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index d20260f8e..f2f2b9d88 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -5,10 +5,11 @@ #include #include +#include + #include class TopoDS_Shape; -class ModelAPI_Feature; /*! \brief Return directory part of the file path. @@ -64,13 +65,13 @@ namespace XGUI_Tools Returns true if the feature is a model object \param theFeature a feature */ - bool XGUI_EXPORT isModelObject(boost::shared_ptr theFeature); + bool XGUI_EXPORT isModelObject(FeaturePtr theFeature); /*! Returns the string presentation of the given feature \param theFeature a feature */ - std::string XGUI_EXPORT featureInfo(boost::shared_ptr theFeature); + std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature); } #endif diff --git a/src/XGUI/XGUI_ViewerProxy.h b/src/XGUI/XGUI_ViewerProxy.h index 1f7f63344..dfd632bda 100644 --- a/src/XGUI/XGUI_ViewerProxy.h +++ b/src/XGUI/XGUI_ViewerProxy.h @@ -64,4 +64,4 @@ private: XGUI_Workshop* myWorkshop; }; -#endif \ No newline at end of file +#endif diff --git a/src/XGUI/XGUI_ViewerPrs.cpp b/src/XGUI/XGUI_ViewerPrs.cpp index 4ab8801aa..e0958f76f 100644 --- a/src/XGUI/XGUI_ViewerPrs.cpp +++ b/src/XGUI/XGUI_ViewerPrs.cpp @@ -4,13 +4,16 @@ #include "XGUI_ViewerPrs.h" +#include "SelectMgr_EntityOwner.hxx" + XGUI_ViewerPrs::XGUI_ViewerPrs() { } -XGUI_ViewerPrs::XGUI_ViewerPrs(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape) -: myFeature(theFeature), myShape(theShape) +XGUI_ViewerPrs::XGUI_ViewerPrs(FeaturePtr theFeature, + const TopoDS_Shape& theShape, + Handle(SelectMgr_EntityOwner) theOwner) +: myFeature(theFeature), myShape(theShape), myOwner(theOwner) { } @@ -18,19 +21,29 @@ XGUI_ViewerPrs::~XGUI_ViewerPrs() { } -void XGUI_ViewerPrs::setFeature(boost::shared_ptr theFeature) +void XGUI_ViewerPrs::setFeature(FeaturePtr theFeature) { myFeature = theFeature; } -void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape) +FeaturePtr XGUI_ViewerPrs::feature() const { - myShape = theShape; + return myFeature; } -boost::shared_ptr XGUI_ViewerPrs::feature() const +void XGUI_ViewerPrs::setOwner(Handle(SelectMgr_EntityOwner) theOwner) { - return myFeature; + myOwner = theOwner; +} + +Handle(SelectMgr_EntityOwner) XGUI_ViewerPrs::owner() const +{ + return myOwner; +} + +void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape) +{ + myShape = theShape; } const TopoDS_Shape& XGUI_ViewerPrs::shape() const diff --git a/src/XGUI/XGUI_ViewerPrs.h b/src/XGUI/XGUI_ViewerPrs.h index 957e4dc7c..585b65cc3 100644 --- a/src/XGUI/XGUI_ViewerPrs.h +++ b/src/XGUI/XGUI_ViewerPrs.h @@ -9,12 +9,13 @@ #include #include +#include -class ModelAPI_Feature; +#include /**\class XGUI_ViewerPrs * \ingroup GUI - * \brief Presentation. Provides container to have feature and the shape + * \brief Presentation. Provides container to have feature, shape and/or selection owner. */ class XGUI_EXPORT XGUI_ViewerPrs { @@ -22,29 +23,42 @@ public: /// Constructor XGUI_ViewerPrs(); /// Constructor - XGUI_ViewerPrs(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape); + /// \param theFeature a model feature + /// \param theShape a viewer shape + /// \param theOwner a selection owner + XGUI_ViewerPrs(FeaturePtr theFeature, + const TopoDS_Shape& theShape, + Handle_SelectMgr_EntityOwner theOwner); /// Destructor virtual ~XGUI_ViewerPrs(); /// Sets the feature. /// \param theFeature a feature instance - void setFeature(boost::shared_ptr theFeature); + void setFeature(FeaturePtr theFeature); + + /// Returns the feature. + /// \return a feature instance + FeaturePtr feature() const; + + /// Returns the presentation owner + /// \param the owner + void setOwner(Handle_SelectMgr_EntityOwner theOwner); + + /// Returns the presentation owner + /// \return an owner + Handle_SelectMgr_EntityOwner owner() const; /// Sets the shape /// \param theShape a shape instance void setShape(const TopoDS_Shape& theShape); - /// Returns the feature. - /// \return a feature instance - boost::shared_ptr feature() const; - /// Returns the shape /// \return a shape instance const TopoDS_Shape& shape() const; private: - boost::shared_ptr myFeature; /// the feature + FeaturePtr myFeature; /// the feature + Handle(SelectMgr_EntityOwner) myOwner; /// the selection owner TopoDS_Shape myShape; /// the shape }; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 980b8c8e0..25f3b5317 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -20,6 +20,7 @@ #include "XGUI_ViewerProxy.h" #include "XGUI_PropertyPanel.h" #include "XGUI_ContextMenuMgr.h" +#include "XGUI_ModuleConnector.h" #include #include @@ -28,6 +29,8 @@ #include #include +#include + #include #include #include @@ -91,6 +94,8 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) this, SLOT(onContextMenuCommand(const QString&, bool))); myViewerProxy = new XGUI_ViewerProxy(this); + + myModuleConnector = new XGUI_ModuleConnector(this); connect(myOperationMgr, SIGNAL(operationStarted()), SLOT(onOperationStarted())); connect(myOperationMgr, SIGNAL(operationResumed()), SLOT(onOperationStarted())); @@ -225,7 +230,7 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) bool aHasPart = false; for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { FeaturePtr aFeature = (*aIt); - if (aFeature->getKind() == "Part") { + if (aFeature->getKind() == PARTSET_PART_KIND) { aHasPart = true; break; } @@ -289,7 +294,7 @@ void XGUI_Workshop::onOperationStarted() showPropertyPanel(); - ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation); + ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation, myModuleConnector); QWidget* aContent = myPropertyPanel->contentWidget(); qDeleteAll(aContent->children()); aFactory.createWidget(aContent); @@ -806,7 +811,7 @@ void XGUI_Workshop::deleteFeatures(QFeatureList theList) PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); aMgr->rootDocument()->startOperation(); foreach (FeaturePtr aFeature, theList) { - if (aFeature->getKind() == "Part") { + if (aFeature->getKind() == PARTSET_PART_KIND) { DocumentPtr aDoc; if (!XGUI_Tools::isModelObject(aFeature)) { aDoc = aFeature->data()->docRef("PartDocument")->value(); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index d7ace358b..dad085707 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -25,6 +25,7 @@ class XGUI_SalomeViewer; class XGUI_ViewerProxy; class XGUI_PropertyPanel; class XGUI_ContextMenuMgr; +class XGUI_ModuleConnector; class ModuleBase_Operation; @@ -174,6 +175,7 @@ private: XGUI_ErrorDialog* myErrorDlg; XGUI_ViewerProxy* myViewerProxy; XGUI_ContextMenuMgr* myContextMenuMgr; + XGUI_ModuleConnector* myModuleConnector; QString myCurrentDir; static QMap myIcons;