From: Nicolas RECHATIN Date: Thu, 22 Jul 2021 11:22:58 +0000 (+0200) Subject: refacto ModelAPI_ResultMeta class inheritance X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=60eb86c23c2174095653b793c61edc6fa2094078;p=modules%2Fshaper.git refacto ModelAPI_ResultMeta class inheritance --- diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 620650aa7..96248507d 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -48,9 +48,7 @@ SET(PROJECT_HEADERS Model_FeatureValidator.h Model_FiltersFactory.h Model_ResultBody.h - Model_ResultVolume.h - Model_ResultConstruction.h Model_ResultPart.h Model_ResultField.h @@ -89,9 +87,7 @@ SET(PROJECT_SOURCES Model_FeatureValidator.cpp Model_FiltersFactory.cpp Model_ResultBody.cpp - Model_ResultVolume.cpp - Model_ResultConstruction.cpp Model_ResultPart.cpp Model_ResultField.cpp diff --git a/src/Model/Model_ResultVolume.cpp b/src/Model/Model_ResultVolume.cpp index eda5d6984..cc852ede1 100644 --- a/src/Model/Model_ResultVolume.cpp +++ b/src/Model/Model_ResultVolume.cpp @@ -156,7 +156,7 @@ void Model_ResultVolume::colorConfigInfo(std::string& theSection, std::string& t std::string& theDefault) { theSection = "Visualization"; - theName = "result_body_color"; + theName = "result_volume_color"; theDefault = DEFAULT_COLOR(); } diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index b9977abdf..3db02400d 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -60,10 +60,9 @@ SET(PROJECT_HEADERS ModelAPI_Object.h ModelAPI_Plugin.h ModelAPI_Result.h + ModelAPI_ResultMeta.h ModelAPI_ResultBody.h - ModelAPI_ResultVolume.h - ModelAPI_ResultConstruction.h ModelAPI_ResultField.h ModelAPI_ResultGroup.h @@ -107,6 +106,7 @@ SET(PROJECT_SOURCES ModelAPI_Object.cpp ModelAPI_Plugin.cpp ModelAPI_Result.cpp + ModelAPI_ResultMeta.cpp ModelAPI_ResultBody.cpp ModelAPI_ResultVolume.cpp ModelAPI_ResultConstruction.cpp diff --git a/src/ModelAPI/ModelAPI_ResultBody.cpp b/src/ModelAPI/ModelAPI_ResultBody.cpp index 0187d2534..0d88bef99 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.cpp +++ b/src/ModelAPI/ModelAPI_ResultBody.cpp @@ -19,133 +19,13 @@ #include "ModelAPI_ResultBody.h" -#include -#include -#include +ModelAPI_ResultBody::ModelAPI_ResultBody() {} -ModelAPI_ResultBody::ModelAPI_ResultBody() - : myBuilder(0) -{ - myConnect = ConnectionNotComputed; -} - -ModelAPI_ResultBody::~ModelAPI_ResultBody() -{ -} +ModelAPI_ResultBody::~ModelAPI_ResultBody() {} std::string ModelAPI_ResultBody::groupName() { - return group(); -} - -void ModelAPI_ResultBody::store(const GeomShapePtr& theShape, - const bool theIsStoreSameShapes) -{ - myBuilder->store(theShape, theIsStoreSameShapes); - myConnect = ConnectionNotComputed; - - static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - aECreator->sendUpdated(data()->owner(), aRedispEvent); - - updateSubs(theShape); -} - -void ModelAPI_ResultBody::storeGenerated(const GeomShapePtr& theFromShape, - const GeomShapePtr& theToShape) -{ - myBuilder->storeGenerated(theFromShape, theToShape); - myConnect = ConnectionNotComputed; - - static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - aECreator->sendUpdated(data()->owner(), aRedispEvent); - - updateSubs(theToShape); -} - -void ModelAPI_ResultBody::storeGenerated( - const std::list& theFromShapes, const GeomShapePtr& theToShape, - const std::shared_ptr theMakeShape) -{ - myBuilder->storeGenerated(theFromShapes, theToShape, theMakeShape); - myConnect = ConnectionNotComputed; - - static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - aECreator->sendUpdated(data()->owner(), aRedispEvent); - - updateSubs(theToShape, theFromShapes, theMakeShape, true); -} - -void ModelAPI_ResultBody::storeModified(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const bool theIsCleanStored) -{ - myBuilder->storeModified(theOldShape, theNewShape, theIsCleanStored); - myConnect = ConnectionNotComputed; - - static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - aECreator->sendUpdated(data()->owner(), aRedispEvent); - - updateSubs(theNewShape); -} - -void ModelAPI_ResultBody::storeModified( - const std::list& theOldShapes, const GeomShapePtr& theNewShape, - const std::shared_ptr theMakeShape) -{ - myBuilder->storeModified(theOldShapes, theNewShape, theMakeShape); - myConnect = ConnectionNotComputed; - - static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - aECreator->sendUpdated(data()->owner(), aRedispEvent); - - updateSubs(theNewShape, theOldShapes, theMakeShape, false); -} - -GeomShapePtr ModelAPI_ResultBody::shape() -{ - return myBuilder->shape(); -} - -void ModelAPI_ResultBody::generated(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const std::string& theName) -{ - myBuilder->generated(theOldShape, theNewShape, theName); -} - -void ModelAPI_ResultBody::modified(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const std::string& theName) -{ - myBuilder->modified(theOldShape, theNewShape, theName); -} - - -void ModelAPI_ResultBody::loadDeletedShapes(const GeomMakeShapePtr& theAlgo, - const GeomShapePtr& theOldShape, - const GeomAPI_Shape::ShapeType theShapeTypeToExplore, - const GeomShapePtr& theShapesToExclude) -{ - myBuilder->loadDeletedShapes(theAlgo, theOldShape, theShapeTypeToExplore, theShapesToExclude); -} - -// LCOV_EXCL_START -bool ModelAPI_ResultBody::isConnectedTopology() -{ - if (myConnect == ConnectionNotComputed) { - myConnect = shape()->isConnectedTopology() ? IsConnected : IsNotConnected; - } - return myConnect == IsConnected; + return ModelAPI_ResultBody::group(); } void ModelAPI_ResultBody::setDisplayed(const bool theDisplay) @@ -154,4 +34,3 @@ void ModelAPI_ResultBody::setDisplayed(const bool theDisplay) for (int i = 0; i < numberOfSubs(); i++) subResult(i)->setDisplayed(theDisplay); } -// LCOV_EXCL_STOP diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index 5c19f711c..53cd19109 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -20,7 +20,7 @@ #ifndef ModelAPI_ResultBody_H_ #define ModelAPI_ResultBody_H_ -#include "ModelAPI_Result.h" +#include "ModelAPI_ResultMeta.h" #include #include #include @@ -39,176 +39,39 @@ class GeomAlgoAPI_MakeShape; * of result must be optimized. * Also provides a container of sub-body result in case it is compound or compsolid. */ -class ModelAPI_ResultBody : public ModelAPI_Result +class ModelAPI_ResultBody : public ModelAPI_ResultMeta { -public: - /// Internal enumeration for storage the information of connected topology flag - enum ConnectedTopologyFlag { - ConnectionNotComputed, ///< not yet computed - IsConnected, ///< the topology is connected - IsNotConnected ///< the topology is connected - }; + public: + MODELAPI_EXPORT virtual ~ModelAPI_ResultBody(); -protected: - /// Keeps (not persistently) the connected topology flag - ConnectedTopologyFlag myConnect; + // /// Returns the group identifier of this result + MODELAPI_EXPORT virtual std::string groupName(); - ModelAPI_BodyBuilder* myBuilder; ///< provides the body processing in naming shape - -public: - MODELAPI_EXPORT virtual ~ModelAPI_ResultBody(); - - /// Returns the group identifier of this result - MODELAPI_EXPORT virtual std::string groupName(); - - /// Returns the group identifier of this result - inline static std::string group() - { - static std::string MY_GROUP = "Bodies"; - return MY_GROUP; - } - - /// default color for a result body - inline static const std::string& DEFAULT_COLOR() - { - static const std::string RESULT_BODY_COLOR("200,200,230"); - return RESULT_BODY_COLOR; - } - - /// default deflection for a result body - inline static const std::string DEFAULT_DEFLECTION() - { - return "0.0001"; - } - - /// Returns the number of sub-elements - MODELAPI_EXPORT virtual int numberOfSubs(bool forTree = false) const = 0; - - /// Returns the sub-result by zero-base index - MODELAPI_EXPORT virtual std::shared_ptr subResult( + /// Returns the sub-result by zero-base index + MODELAPI_EXPORT virtual std::shared_ptr subResult( const int theIndex, bool forTree = false) const = 0; - /// Returns true if theResult belong to this composite result as sub. - /// Returns theIndex - zero based index of sub if found - MODELAPI_EXPORT virtual bool isSub(ObjectPtr theResult, int& theIndex) const = 0; - - /// \brief Stores the shape (called by the execution method). - /// param[in] theShape shape to store. - /// param[in] theIsStoreSameShapes if false stores reference to the same shape - /// if it is already in document. - MODELAPI_EXPORT virtual void store(const GeomShapePtr& theShape, - const bool theIsStoreSameShapes = true); - - /// Stores the generated shape (called by the execution method). - MODELAPI_EXPORT virtual void storeGenerated(const GeomShapePtr& theFromShape, - const GeomShapePtr& theToShape); - - /// Stores the root modified shapes (called by the execution method). - MODELAPI_EXPORT virtual void storeGenerated( - const std::list& theFromShapes, const GeomShapePtr& theToShape, - const std::shared_ptr theMakeShape); - - /// Stores the modified shape (called by the execution method). - MODELAPI_EXPORT virtual void storeModified(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const bool theIsCleanStored = true); - - /// Stores the root modified shapes (called by the execution method). - MODELAPI_EXPORT virtual void storeModified( - const std::list& theOldShapes, const GeomShapePtr& theNewShape, - const std::shared_ptr theMakeShape); - - /// Returns the shape-result produced by this feature - MODELAPI_EXPORT virtual GeomShapePtr shape(); - - /// Records the subshape newShape which was generated during a topological construction. - /// As an example, consider the case of a face generated in construction of a box. - /// Returns true if it is stored correctly (the final shape contains this new sub-shape) - MODELAPI_EXPORT virtual bool generated(const GeomShapePtr& theNewShape, - const std::string& theName, const bool theCheckIsInResult = true) = 0; - - /// Records the shape newShape which was generated from the shape oldShape during a topological - /// construction. As an example, consider the case of a face generated from an edge in - /// construction of a prism. - MODELAPI_EXPORT virtual void generated(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const std::string& theName = ""); - - /// Records the shape newShape which is a modification of the shape oldShape. - /// As an example, consider the case of a face split or merged in a Boolean operation. - MODELAPI_EXPORT virtual void modified(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const std::string& theName = ""); - - /// load deleted shapes - MODELAPI_EXPORT - virtual void loadDeletedShapes(const std::shared_ptr& theAlgo, - const GeomShapePtr& theOldShape, - const GeomAPI_Shape::ShapeType theShapeTypeToExplore, - const GeomShapePtr& theShapesToExclude = GeomShapePtr()); - - /// load and orient modified shapes - MODELAPI_EXPORT - virtual void loadModifiedShapes(const std::shared_ptr& theAlgo, - const GeomShapePtr& theOldShape, - const GeomAPI_Shape::ShapeType theShapeTypeToExplore, - const std::string& theName = "") = 0; - - /// load and orient generated shapes - MODELAPI_EXPORT - virtual void loadGeneratedShapes(const std::shared_ptr& theAlgo, - const GeomShapePtr& theOldShape, - const GeomAPI_Shape::ShapeType theShapeTypeToExplore, - const std::string& theName = "", - const bool theSaveOldIfNotInTree = false) = 0; - - /// load shapes of the first level (to be used during shape import) - MODELAPI_EXPORT virtual void loadFirstLevel(GeomShapePtr theShape, - const std::string& theName) = 0; - - /// Returns true is the topology is connected. - MODELAPI_EXPORT virtual bool isConnectedTopology() = 0; - - /// Set displayed flag to the result and all sub results - /// \param theDisplay a boolean value - MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay); - - /// Updates the sub-bodies if shape of this object is compsolid or compound - MODELAPI_EXPORT virtual void updateSubs(const GeomShapePtr& theThisShape, - const bool theShapeChanged = true) = 0; - - /// Updates the sub-bodies in accordance to the algorithm history information - MODELAPI_EXPORT virtual void updateSubs( - const GeomShapePtr& theThisShape, const std::list& theOlds, - const std::shared_ptr theMakeShape, const bool isGenerated) = 0; - - /// Cleans cash related to the already stored elements - MODELAPI_EXPORT virtual void cleanCash() = 0; - - /// Add shape Name for read shape in step file - MODELAPI_EXPORT virtual std::wstring addShapeName - (std::shared_ptr,const std::wstring& theName) = 0; - - /// Add color for shape Name read shape in step file - MODELAPI_EXPORT virtual void addShapeColor - (const std::wstring& theName,std::vector& theColor) = 0; - - /// Set the map of name and color read shape in step file - MODELAPI_EXPORT virtual void setShapeName - (std::map< std::wstring, std::shared_ptr > &theShapeName, - std::map< std::wstring, std::vector> & theColorsShape) = 0; - - /// Clear the map of name and color read shape in step file - MODELAPI_EXPORT virtual void clearShapeNameAndColor() = 0; + /// Set displayed flag to the result and all sub results + /// \param theDisplay a boolean value + MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay); - /// find the name of shapp read in step file - MODELAPI_EXPORT virtual std::wstring findShapeName(std::shared_ptr theShape) = 0; + inline static std::string group() + { + static std::string MY_GROUP = "Bodies"; + return MY_GROUP; + } + /// default color for a result volume + inline static const std::string DEFAULT_COLOR() + { + static const std::string RESULT_BODY_COLOR("200,200,230"); + return RESULT_BODY_COLOR; + } -protected: - /// Default constructor accessible only from Model_Objects - MODELAPI_EXPORT ModelAPI_ResultBody(); + protected: + /// Default constructor accessible only from Model_Objects + MODELAPI_EXPORT ModelAPI_ResultBody(); }; //! Pointer on feature object diff --git a/src/ModelAPI/ModelAPI_ResultMeta.cpp b/src/ModelAPI/ModelAPI_ResultMeta.cpp new file mode 100644 index 000000000..337f8f488 --- /dev/null +++ b/src/ModelAPI/ModelAPI_ResultMeta.cpp @@ -0,0 +1,145 @@ +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "ModelAPI_ResultMeta.h" + +#include +#include +#include + +ModelAPI_ResultMeta::ModelAPI_ResultMeta() + : myBuilder(0) +{ + myConnect = ConnectionNotComputed; +} + +ModelAPI_ResultMeta::~ModelAPI_ResultMeta() +{ +} + +void ModelAPI_ResultMeta::store(const GeomShapePtr& theShape, + const bool theIsStoreSameShapes) +{ + myBuilder->store(theShape, theIsStoreSameShapes); + myConnect = ConnectionNotComputed; + + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + aECreator->sendUpdated(data()->owner(), aRedispEvent); + + updateSubs(theShape); +} + +void ModelAPI_ResultMeta::storeGenerated(const GeomShapePtr& theFromShape, + const GeomShapePtr& theToShape) +{ + myBuilder->storeGenerated(theFromShape, theToShape); + myConnect = ConnectionNotComputed; + + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + aECreator->sendUpdated(data()->owner(), aRedispEvent); + + updateSubs(theToShape); +} + +void ModelAPI_ResultMeta::storeGenerated( + const std::list& theFromShapes, const GeomShapePtr& theToShape, + const std::shared_ptr theMakeShape) +{ + myBuilder->storeGenerated(theFromShapes, theToShape, theMakeShape); + myConnect = ConnectionNotComputed; + + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + aECreator->sendUpdated(data()->owner(), aRedispEvent); + + updateSubs(theToShape, theFromShapes, theMakeShape, true); +} + +void ModelAPI_ResultMeta::storeModified(const GeomShapePtr& theOldShape, + const GeomShapePtr& theNewShape, + const bool theIsCleanStored) +{ + myBuilder->storeModified(theOldShape, theNewShape, theIsCleanStored); + myConnect = ConnectionNotComputed; + + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + aECreator->sendUpdated(data()->owner(), aRedispEvent); + + updateSubs(theNewShape); +} + +void ModelAPI_ResultMeta::storeModified( + const std::list& theOldShapes, const GeomShapePtr& theNewShape, + const std::shared_ptr theMakeShape) +{ + myBuilder->storeModified(theOldShapes, theNewShape, theMakeShape); + myConnect = ConnectionNotComputed; + + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + aECreator->sendUpdated(data()->owner(), aRedispEvent); + + updateSubs(theNewShape, theOldShapes, theMakeShape, false); +} + +GeomShapePtr ModelAPI_ResultMeta::shape() +{ + return myBuilder->shape(); +} + +void ModelAPI_ResultMeta::generated(const GeomShapePtr& theOldShape, + const GeomShapePtr& theNewShape, + const std::string& theName) +{ + myBuilder->generated(theOldShape, theNewShape, theName); +} + +void ModelAPI_ResultMeta::modified(const GeomShapePtr& theOldShape, + const GeomShapePtr& theNewShape, + const std::string& theName) +{ + myBuilder->modified(theOldShape, theNewShape, theName); +} + + +void ModelAPI_ResultMeta::loadDeletedShapes(const GeomMakeShapePtr& theAlgo, + const GeomShapePtr& theOldShape, + const GeomAPI_Shape::ShapeType theShapeTypeToExplore, + const GeomShapePtr& theShapesToExclude) +{ + myBuilder->loadDeletedShapes(theAlgo, theOldShape, theShapeTypeToExplore, theShapesToExclude); +} + +// LCOV_EXCL_START +bool ModelAPI_ResultMeta::isConnectedTopology() +{ + if (myConnect == ConnectionNotComputed) { + myConnect = shape()->isConnectedTopology() ? IsConnected : IsNotConnected; + } + return myConnect == IsConnected; +} +// LCOV_EXCL_STOP diff --git a/src/ModelAPI/ModelAPI_ResultMeta.h b/src/ModelAPI/ModelAPI_ResultMeta.h new file mode 100644 index 000000000..56bfb788f --- /dev/null +++ b/src/ModelAPI/ModelAPI_ResultMeta.h @@ -0,0 +1,192 @@ +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef ModelAPI_ResultMeta_H_ +#define ModelAPI_ResultMeta_H_ + +#include "ModelAPI_Result.h" +#include +#include +#include +#include +#include + +class ModelAPI_BodyBuilder; +class GeomAlgoAPI_MakeShape; + +/**\class ModelAPI_ResultMeta +* \ingroup DataModel +* \brief The body (shape) result of a feature. +* +* Provides a shape that may be displayed in the viewer. +* May provide really huge results, so, working with this kind +* of result must be optimized. +* Also provides a container of sub-body result in case it is compound or compsolid. +*/ +class ModelAPI_ResultMeta : public ModelAPI_Result +{ +public: + /// Internal enumeration for storage the information of connected topology flag + enum ConnectedTopologyFlag { + ConnectionNotComputed, ///< not yet computed + IsConnected, ///< the topology is connected + IsNotConnected ///< the topology is connected + }; + +protected: + /// Keeps (not persistently) the connected topology flag + ConnectedTopologyFlag myConnect; + + ModelAPI_BodyBuilder* myBuilder; ///< provides the body processing in naming shape + +public: + /// default deflection for a result body + inline static const std::string DEFAULT_DEFLECTION() + { + return "0.0001"; + } + + MODELAPI_EXPORT virtual ~ModelAPI_ResultMeta(); + + /// Returns the number of sub-elements + MODELAPI_EXPORT virtual int numberOfSubs(bool forTree = false) const = 0; + + /// Returns true if theResult belong to this composite result as sub. + /// Returns theIndex - zero based index of sub if found + MODELAPI_EXPORT virtual bool isSub(ObjectPtr theResult, int& theIndex) const = 0; + + /// \brief Stores the shape (called by the execution method). + /// param[in] theShape shape to store. + /// param[in] theIsStoreSameShapes if false stores reference to the same shape + /// if it is already in document. + MODELAPI_EXPORT virtual void store(const GeomShapePtr& theShape, + const bool theIsStoreSameShapes = true); + + /// Stores the generated shape (called by the execution method). + MODELAPI_EXPORT virtual void storeGenerated(const GeomShapePtr& theFromShape, + const GeomShapePtr& theToShape); + + /// Stores the root modified shapes (called by the execution method). + MODELAPI_EXPORT virtual void storeGenerated( + const std::list& theFromShapes, const GeomShapePtr& theToShape, + const std::shared_ptr theMakeShape); + + /// Stores the modified shape (called by the execution method). + MODELAPI_EXPORT virtual void storeModified(const GeomShapePtr& theOldShape, + const GeomShapePtr& theNewShape, + const bool theIsCleanStored = true); + + /// Stores the root modified shapes (called by the execution method). + MODELAPI_EXPORT virtual void storeModified( + const std::list& theOldShapes, const GeomShapePtr& theNewShape, + const std::shared_ptr theMakeShape); + + /// Returns the shape-result produced by this feature + MODELAPI_EXPORT virtual GeomShapePtr shape(); + + /// Records the subshape newShape which was generated during a topological construction. + /// As an example, consider the case of a face generated in construction of a box. + /// Returns true if it is stored correctly (the final shape contains this new sub-shape) + MODELAPI_EXPORT virtual bool generated(const GeomShapePtr& theNewShape, + const std::string& theName, const bool theCheckIsInResult = true) = 0; + + /// Records the shape newShape which was generated from the shape oldShape during a topological + /// construction. As an example, consider the case of a face generated from an edge in + /// construction of a prism. + MODELAPI_EXPORT virtual void generated(const GeomShapePtr& theOldShape, + const GeomShapePtr& theNewShape, + const std::string& theName = ""); + + /// Records the shape newShape which is a modification of the shape oldShape. + /// As an example, consider the case of a face split or merged in a Boolean operation. + MODELAPI_EXPORT virtual void modified(const GeomShapePtr& theOldShape, + const GeomShapePtr& theNewShape, + const std::string& theName = ""); + + /// load deleted shapes + MODELAPI_EXPORT + virtual void loadDeletedShapes(const std::shared_ptr& theAlgo, + const GeomShapePtr& theOldShape, + const GeomAPI_Shape::ShapeType theShapeTypeToExplore, + const GeomShapePtr& theShapesToExclude = GeomShapePtr()); + + /// load and orient modified shapes + MODELAPI_EXPORT + virtual void loadModifiedShapes(const std::shared_ptr& theAlgo, + const GeomShapePtr& theOldShape, + const GeomAPI_Shape::ShapeType theShapeTypeToExplore, + const std::string& theName = "") = 0; + + /// load and orient generated shapes + MODELAPI_EXPORT + virtual void loadGeneratedShapes(const std::shared_ptr& theAlgo, + const GeomShapePtr& theOldShape, + const GeomAPI_Shape::ShapeType theShapeTypeToExplore, + const std::string& theName = "", + const bool theSaveOldIfNotInTree = false) = 0; + + /// load shapes of the first level (to be used during shape import) + MODELAPI_EXPORT virtual void loadFirstLevel(GeomShapePtr theShape, + const std::string& theName) = 0; + + /// Returns true is the topology is connected. + MODELAPI_EXPORT virtual bool isConnectedTopology() = 0; + + /// Updates the sub-bodies if shape of this object is compsolid or compound + MODELAPI_EXPORT virtual void updateSubs(const GeomShapePtr& theThisShape, + const bool theShapeChanged = true) = 0; + + /// Updates the sub-bodies in accordance to the algorithm history information + MODELAPI_EXPORT virtual void updateSubs( + const GeomShapePtr& theThisShape, const std::list& theOlds, + const std::shared_ptr theMakeShape, const bool isGenerated) = 0; + + /// Cleans cash related to the already stored elements + MODELAPI_EXPORT virtual void cleanCash() = 0; + + /// Add shape Name for read shape in step file + MODELAPI_EXPORT virtual std::wstring addShapeName + (std::shared_ptr,const std::wstring& theName) = 0; + + /// Add color for shape Name read shape in step file + MODELAPI_EXPORT virtual void addShapeColor + (const std::wstring& theName,std::vector& theColor) = 0; + + /// Set the map of name and color read shape in step file + MODELAPI_EXPORT virtual void setShapeName + (std::map< std::wstring, std::shared_ptr > &theShapeName, + std::map< std::wstring, std::vector> & theColorsShape) = 0; + + /// Clear the map of name and color read shape in step file + MODELAPI_EXPORT virtual void clearShapeNameAndColor() = 0; + + /// find the name of shapp read in step file + MODELAPI_EXPORT virtual std::wstring findShapeName(std::shared_ptr theShape) = 0; + + +protected: + /// Default constructor accessible only from Model_Objects + MODELAPI_EXPORT ModelAPI_ResultMeta(); + +}; + +//! Pointer on feature object +typedef std::shared_ptr ResultMetaPtr; + +#endif diff --git a/src/ModelAPI/ModelAPI_ResultVolume.cpp b/src/ModelAPI/ModelAPI_ResultVolume.cpp index 39537a7d1..99175e884 100644 --- a/src/ModelAPI/ModelAPI_ResultVolume.cpp +++ b/src/ModelAPI/ModelAPI_ResultVolume.cpp @@ -19,133 +19,13 @@ #include "ModelAPI_ResultVolume.h" -#include -#include -#include +ModelAPI_ResultVolume::ModelAPI_ResultVolume() {} -ModelAPI_ResultVolume::ModelAPI_ResultVolume() - : myBuilder(0) -{ - myConnect = ConnectionNotComputed; -} - -ModelAPI_ResultVolume::~ModelAPI_ResultVolume() -{ -} +ModelAPI_ResultVolume::~ModelAPI_ResultVolume() {} std::string ModelAPI_ResultVolume::groupName() { - return group(); -} - -void ModelAPI_ResultVolume::store(const GeomShapePtr& theShape, - const bool theIsStoreSameShapes) -{ - myBuilder->store(theShape, theIsStoreSameShapes); - myConnect = ConnectionNotComputed; - - static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - aECreator->sendUpdated(data()->owner(), aRedispEvent); - - updateSubs(theShape); -} - -void ModelAPI_ResultVolume::storeGenerated(const GeomShapePtr& theFromShape, - const GeomShapePtr& theToShape) -{ - myBuilder->storeGenerated(theFromShape, theToShape); - myConnect = ConnectionNotComputed; - - static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - aECreator->sendUpdated(data()->owner(), aRedispEvent); - - updateSubs(theToShape); -} - -void ModelAPI_ResultVolume::storeGenerated( - const std::list& theFromShapes, const GeomShapePtr& theToShape, - const std::shared_ptr theMakeShape) -{ - myBuilder->storeGenerated(theFromShapes, theToShape, theMakeShape); - myConnect = ConnectionNotComputed; - - static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - aECreator->sendUpdated(data()->owner(), aRedispEvent); - - updateSubs(theToShape, theFromShapes, theMakeShape, true); -} - -void ModelAPI_ResultVolume::storeModified(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const bool theIsCleanStored) -{ - myBuilder->storeModified(theOldShape, theNewShape, theIsCleanStored); - myConnect = ConnectionNotComputed; - - static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - aECreator->sendUpdated(data()->owner(), aRedispEvent); - - updateSubs(theNewShape); -} - -void ModelAPI_ResultVolume::storeModified( - const std::list& theOldShapes, const GeomShapePtr& theNewShape, - const std::shared_ptr theMakeShape) -{ - myBuilder->storeModified(theOldShapes, theNewShape, theMakeShape); - myConnect = ConnectionNotComputed; - - static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - aECreator->sendUpdated(data()->owner(), aRedispEvent); - - updateSubs(theNewShape, theOldShapes, theMakeShape, false); -} - -GeomShapePtr ModelAPI_ResultVolume::shape() -{ - return myBuilder->shape(); -} - -void ModelAPI_ResultVolume::generated(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const std::string& theName) -{ - myBuilder->generated(theOldShape, theNewShape, theName); -} - -void ModelAPI_ResultVolume::modified(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const std::string& theName) -{ - myBuilder->modified(theOldShape, theNewShape, theName); -} - - -void ModelAPI_ResultVolume::loadDeletedShapes(const GeomMakeShapePtr& theAlgo, - const GeomShapePtr& theOldShape, - const GeomAPI_Shape::ShapeType theShapeTypeToExplore, - const GeomShapePtr& theShapesToExclude) -{ - myBuilder->loadDeletedShapes(theAlgo, theOldShape, theShapeTypeToExplore, theShapesToExclude); -} - -// LCOV_EXCL_START -bool ModelAPI_ResultVolume::isConnectedTopology() -{ - if (myConnect == ConnectionNotComputed) { - myConnect = shape()->isConnectedTopology() ? IsConnected : IsNotConnected; - } - return myConnect == IsConnected; + return ModelAPI_ResultVolume::group(); } void ModelAPI_ResultVolume::setDisplayed(const bool theDisplay) @@ -154,4 +34,3 @@ void ModelAPI_ResultVolume::setDisplayed(const bool theDisplay) for (int i = 0; i < numberOfSubs(); i++) subResult(i)->setDisplayed(theDisplay); } -// LCOV_EXCL_STOP diff --git a/src/ModelAPI/ModelAPI_ResultVolume.h b/src/ModelAPI/ModelAPI_ResultVolume.h index 3bf86b1a6..e8c0cd276 100644 --- a/src/ModelAPI/ModelAPI_ResultVolume.h +++ b/src/ModelAPI/ModelAPI_ResultVolume.h @@ -20,15 +20,7 @@ #ifndef ModelAPI_ResultVolume_H_ #define ModelAPI_ResultVolume_H_ -#include "ModelAPI_Result.h" -#include -#include -#include -#include -#include - -class ModelAPI_BodyBuilder; -class GeomAlgoAPI_MakeShape; +#include "ModelAPI_ResultMeta.h" /**\class ModelAPI_ResultVolume * \ingroup DataModel @@ -39,175 +31,39 @@ class GeomAlgoAPI_MakeShape; * of result must be optimized. * Also provides a container of sub-body result in case it is compound or compsolid. */ -class ModelAPI_ResultVolume : public ModelAPI_Result +class ModelAPI_ResultVolume : public ModelAPI_ResultMeta { -public: - /// Internal enumeration for storage the information of connected topology flag - enum ConnectedTopologyFlag { - ConnectionNotComputed, ///< not yet computed - IsConnected, ///< the topology is connected - IsNotConnected ///< the topology is connected - }; - -protected: - /// Keeps (not persistently) the connected topology flag - ConnectedTopologyFlag myConnect; - - ModelAPI_BodyBuilder* myBuilder; ///< provides the body processing in naming shape - -public: - MODELAPI_EXPORT virtual ~ModelAPI_ResultVolume(); - - /// Returns the group identifier of this result - MODELAPI_EXPORT virtual std::string groupName(); + public: + MODELAPI_EXPORT virtual ~ModelAPI_ResultVolume(); - /// Returns the group identifier of this result - inline static std::string group() - { - static std::string MY_GROUP = "Volumes"; - return MY_GROUP; - } + /// Returns the group identifier of this result + MODELAPI_EXPORT std::string groupName(); - /// default color for a result body - inline static const std::string& DEFAULT_COLOR() - { - static const std::string RESULT_BODY_COLOR("200,200,230"); - return RESULT_BODY_COLOR; - } - - /// default deflection for a result body - inline static const std::string DEFAULT_DEFLECTION() - { - return "0.0001"; - } - - /// Returns the number of sub-elements - MODELAPI_EXPORT virtual int numberOfSubs(bool forTree = false) const = 0; - - /// Returns the sub-result by zero-base index - MODELAPI_EXPORT virtual std::shared_ptr subResult( + /// Returns the sub-result by zero-base index + MODELAPI_EXPORT virtual std::shared_ptr subResult( const int theIndex, bool forTree = false) const = 0; - /// Returns true if theResult belong to this composite result as sub. - /// Returns theIndex - zero based index of sub if found - MODELAPI_EXPORT virtual bool isSub(ObjectPtr theResult, int& theIndex) const = 0; - - /// \brief Stores the shape (called by the execution method). - /// param[in] theShape shape to store. - /// param[in] theIsStoreSameShapes if false stores reference to the same shape - /// if it is already in document. - MODELAPI_EXPORT virtual void store(const GeomShapePtr& theShape, - const bool theIsStoreSameShapes = true); - - /// Stores the generated shape (called by the execution method). - MODELAPI_EXPORT virtual void storeGenerated(const GeomShapePtr& theFromShape, - const GeomShapePtr& theToShape); - - /// Stores the root modified shapes (called by the execution method). - MODELAPI_EXPORT virtual void storeGenerated( - const std::list& theFromShapes, const GeomShapePtr& theToShape, - const std::shared_ptr theMakeShape); - - /// Stores the modified shape (called by the execution method). - MODELAPI_EXPORT virtual void storeModified(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const bool theIsCleanStored = true); - - /// Stores the root modified shapes (called by the execution method). - MODELAPI_EXPORT virtual void storeModified( - const std::list& theOldShapes, const GeomShapePtr& theNewShape, - const std::shared_ptr theMakeShape); - - /// Returns the shape-result produced by this feature - MODELAPI_EXPORT virtual GeomShapePtr shape(); - - /// Records the subshape newShape which was generated during a topological construction. - /// As an example, consider the case of a face generated in construction of a box. - /// Returns true if it is stored correctly (the final shape contains this new sub-shape) - MODELAPI_EXPORT virtual bool generated(const GeomShapePtr& theNewShape, - const std::string& theName, const bool theCheckIsInResult = true) = 0; - - /// Records the shape newShape which was generated from the shape oldShape during a topological - /// construction. As an example, consider the case of a face generated from an edge in - /// construction of a prism. - MODELAPI_EXPORT virtual void generated(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const std::string& theName = ""); - - /// Records the shape newShape which is a modification of the shape oldShape. - /// As an example, consider the case of a face split or merged in a Boolean operation. - MODELAPI_EXPORT virtual void modified(const GeomShapePtr& theOldShape, - const GeomShapePtr& theNewShape, - const std::string& theName = ""); - - /// load deleted shapes - MODELAPI_EXPORT - virtual void loadDeletedShapes(const std::shared_ptr& theAlgo, - const GeomShapePtr& theOldShape, - const GeomAPI_Shape::ShapeType theShapeTypeToExplore, - const GeomShapePtr& theShapesToExclude = GeomShapePtr()); - - /// load and orient modified shapes - MODELAPI_EXPORT - virtual void loadModifiedShapes(const std::shared_ptr& theAlgo, - const GeomShapePtr& theOldShape, - const GeomAPI_Shape::ShapeType theShapeTypeToExplore, - const std::string& theName = "") = 0; - - /// load and orient generated shapes - MODELAPI_EXPORT - virtual void loadGeneratedShapes(const std::shared_ptr& theAlgo, - const GeomShapePtr& theOldShape, - const GeomAPI_Shape::ShapeType theShapeTypeToExplore, - const std::string& theName = "", - const bool theSaveOldIfNotInTree = false) = 0; - - /// load shapes of the first level (to be used during shape import) - MODELAPI_EXPORT virtual void loadFirstLevel(GeomShapePtr theShape, - const std::string& theName) = 0; - - /// Returns true is the topology is connected. - MODELAPI_EXPORT virtual bool isConnectedTopology() = 0; - - /// Set displayed flag to the result and all sub results - /// \param theDisplay a boolean value - MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay); - - /// Updates the sub-bodies if shape of this object is compsolid or compound - MODELAPI_EXPORT virtual void updateSubs(const GeomShapePtr& theThisShape, - const bool theShapeChanged = true) = 0; - - /// Updates the sub-bodies in accordance to the algorithm history information - MODELAPI_EXPORT virtual void updateSubs( - const GeomShapePtr& theThisShape, const std::list& theOlds, - const std::shared_ptr theMakeShape, const bool isGenerated) = 0; - - /// Cleans cash related to the already stored elements - MODELAPI_EXPORT virtual void cleanCash() = 0; - - /// Add shape Name for read shape in step file - MODELAPI_EXPORT virtual std::wstring addShapeName - (std::shared_ptr,const std::wstring& theName) = 0; - - /// Add color for shape Name read shape in step file - MODELAPI_EXPORT virtual void addShapeColor - (const std::wstring& theName,std::vector& theColor) = 0; - - /// Set the map of name and color read shape in step file - MODELAPI_EXPORT virtual void setShapeName - (std::map< std::wstring, std::shared_ptr > &theShapeName, - std::map< std::wstring, std::vector> & theColorsShape) = 0; - - /// Clear the map of name and color read shape in step file - MODELAPI_EXPORT virtual void clearShapeNameAndColor() = 0; - - /// find the name of shapp read in step file - MODELAPI_EXPORT virtual std::wstring findShapeName(std::shared_ptr theShape) = 0; - - -protected: - /// Default constructor accessible only from Model_Objects - MODELAPI_EXPORT ModelAPI_ResultVolume(); + /// Set displayed flag to the result and all sub results + /// \param theDisplay a boolean value + MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay); + + /// Returns the group identifier of this result + inline static std::string group() + { + static std::string MY_GROUP = "Volumes"; + return MY_GROUP; + } + + /// default color for a result volume + inline static const std::string DEFAULT_COLOR() + { + static const std::string RESULT_VOLUME_COLOR("102,0,204"); + return RESULT_VOLUME_COLOR; + } + + protected: + /// Default constructor accessible only from Model_Objects + MODELAPI_EXPORT ModelAPI_ResultVolume(); }; diff --git a/src/ModelAPI/ModelAPI_Session.cpp b/src/ModelAPI/ModelAPI_Session.cpp index 75e2068b8..a75ae9b43 100644 --- a/src/ModelAPI/ModelAPI_Session.cpp +++ b/src/ModelAPI/ModelAPI_Session.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include