From: nds Date: Tue, 21 Mar 2017 08:01:46 +0000 (+0300) Subject: #2027 Sketcher Trim Feature: 1. preview/selected attributes in trim; 2. avoid includi... X-Git-Tag: V_2.7.0~209 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b707e7178424958f7dc1ed87a0aabd813f671d88;p=modules%2Fshaper.git #2027 Sketcher Trim Feature: 1. preview/selected attributes in trim; 2. avoid including GeomAPI in ModelAPI headers --- diff --git a/CMakeCommon/FindTInspector.cmake b/CMakeCommon/FindTInspector.cmake index b55377623..7ba0468a2 100644 --- a/CMakeCommon/FindTInspector.cmake +++ b/CMakeCommon/FindTInspector.cmake @@ -24,6 +24,12 @@ IF(EXISTS ${TINSPECTOR_ROOT_DIR}) FIND_LIBRARY(TKVInspector TKVInspector "${TINSPECTOR_LIB_DIR}") SET(TKVInspector ${TKVInspector}) + FIND_LIBRARY(DFBrowserAPI DFBrowserAPI "${TINSPECTOR_LIB_DIR}") + SET(DFBrowserAPI ${DFBrowserAPI}) + + FIND_LIBRARY(TKDFTreeModel TKDFTreeModel "${TINSPECTOR_LIB_DIR}") + SET(TKDFTreeModel ${TKDFTreeModel}) + ENDIF(TKTInspector) ENDIF(EXISTS ${TINSPECTOR_ROOT_DIR}) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index f3941ec11..2add72cf8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp index f3dbf0683..de5a25f85 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp @@ -7,6 +7,7 @@ #include "FeaturesPlugin_CompositeBoolean.h" #include +#include #include #include diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp index 26023890b..7bddd8e17 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include diff --git a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp index 4bbfd76e8..3e62ab7d0 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp index 41e0468be..27b1b8591 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp @@ -16,6 +16,7 @@ #include #include +#include #include diff --git a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp index d254eeef7..2c3bd6521 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp index 34e5bd112..74ff736ad 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp @@ -18,6 +18,7 @@ #include #include +#include #include diff --git a/src/GeomAPI/GeomAPI_Trsf.cpp b/src/GeomAPI/GeomAPI_Trsf.cpp index f0df9471f..7246364f1 100644 --- a/src/GeomAPI/GeomAPI_Trsf.cpp +++ b/src/GeomAPI/GeomAPI_Trsf.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #define MY_TRSF implPtr() diff --git a/src/GeomValidators/GeomValidators_DifferentShapes.cpp b/src/GeomValidators/GeomValidators_DifferentShapes.cpp index 01eb0409a..c9c16e663 100644 --- a/src/GeomValidators/GeomValidators_DifferentShapes.cpp +++ b/src/GeomValidators/GeomValidators_DifferentShapes.cpp @@ -11,6 +11,8 @@ #include #include "ModelAPI_Object.h" +#include + bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const diff --git a/src/GeomValidators/GeomValidators_IntersectionSelection.cpp b/src/GeomValidators/GeomValidators_IntersectionSelection.cpp index 7ecbf5f38..5e72a378b 100644 --- a/src/GeomValidators/GeomValidators_IntersectionSelection.cpp +++ b/src/GeomValidators/GeomValidators_IntersectionSelection.cpp @@ -6,6 +6,8 @@ #include "GeomValidators_IntersectionSelection.h" +#include + #include #include diff --git a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp index 86d457a73..62698cd92 100644 --- a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp +++ b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 7af146794..55ccbfc30 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 16e5d73de..caaee41f4 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -10,6 +10,8 @@ #include "Model_Events.h" #include "Model_Data.h" +#include + #include #include #include diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 2d28604bb..cbe96e2b3 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -302,6 +302,12 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr) if (myWasChangedButBlocked.empty() || *(myWasChangedButBlocked.rbegin()) != theAttr) myWasChangedButBlocked.push_back(theAttr); } + } else { + // trim: need to redisplay + if (myObject) { + static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); + ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent); + } } } diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 805327150..d4e7b2d23 100755 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 0cd0fd5d2..216aab493 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index 74e2b22a1..d30575348 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -20,6 +20,8 @@ #include #include +#include + #include #include #include diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 44fcf4f18..924783bb2 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -21,6 +21,8 @@ #include #include #include + +#include #include #include diff --git a/src/ModelAPI/ModelAPI_AttributeSelectionList.h b/src/ModelAPI/ModelAPI_AttributeSelectionList.h index c5fe4c934..cdcff39d5 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelectionList.h +++ b/src/ModelAPI/ModelAPI_AttributeSelectionList.h @@ -10,6 +10,8 @@ #include "ModelAPI_AttributeSelection.h" #include +class GeomAPI_Shape; + /**\class ModelAPI_AttributeSelectionList * \ingroup DataModel * \brief Attribute that contains list of references to the sub-shapes with @@ -25,7 +27,7 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute /// \param theTemporarily if it is true, do not store and name the added in the data framework /// (used to remove immediately, without the following updates) virtual void append(const ResultPtr& theContext, - const GeomShapePtr& theSubShape, + const std::shared_ptr& theSubShape, const bool theTemporarily = false) = 0; /// Adds the new reference to the end of the list by the naming name of the selected shape diff --git a/src/ModelAPI/ModelAPI_Result.h b/src/ModelAPI/ModelAPI_Result.h index 3f30c57c7..2b86eaa4f 100644 --- a/src/ModelAPI/ModelAPI_Result.h +++ b/src/ModelAPI/ModelAPI_Result.h @@ -8,7 +8,7 @@ #define ModelAPI_Result_H_ #include "ModelAPI_Object.h" -#include +class GeomAPI_Shape; class ModelAPI_Feature; diff --git a/src/ModelAPI/ModelAPI_ResultPart.h b/src/ModelAPI/ModelAPI_ResultPart.h index f86754e80..7a7df7ef4 100644 --- a/src/ModelAPI/ModelAPI_ResultPart.h +++ b/src/ModelAPI/ModelAPI_ResultPart.h @@ -8,7 +8,7 @@ #define ModelAPI_ResultPart_H_ #include "ModelAPI_Result.h" -#include +class GeomAPI_Trsf; #include diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 8d65638b9..963a0c31d 100755 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -6,9 +6,11 @@ #include "ModelAPI_Tools.h" #include +#include #include #include #include +#include #include #include #include @@ -90,21 +92,6 @@ std::shared_ptr shape(const ResultPtr& theResult) return theResult->shape(); } -void shapesOfType(const FeaturePtr& theFeature, - const GeomAPI_Shape::ShapeType& theType, - std::set& theShapeResults) -{ - theShapeResults.clear(); - std::list aResults = theFeature->results(); - std::list::const_iterator aRIter = aResults.cbegin(); - for (; aRIter != aResults.cend(); aRIter++) { - ResultPtr aResult = *aRIter; - GeomShapePtr aShape = aResult->shape(); - if (aShape.get() && aShape->shapeType() == theType) - theShapeResults.insert(aResult); - } -} - const char* toString(ModelAPI_ExecState theExecState) { #define TO_STRING(__NAME__) case __NAME__: return #__NAME__; diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index 573ee12a3..1bf2e2a4e 100755 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -9,44 +9,40 @@ #include "ModelAPI.h" -#include -#include -#include -#include -#include -#include +class ModelAPI_CompositeFeature; +class ModelAPI_Document; +class ModelAPI_Feature; +class ModelAPI_Result; +class ModelAPI_ResultParameter; +class ModelAPI_ResultCompSolid; -#include +class GeomAPI_Shape; #include #include #include +#include namespace ModelAPI_Tools { /// Returns shape from the given Result object -MODELAPI_EXPORT std::shared_ptr shape(const ResultPtr& theResult); - -/// Creates a container of shape of the feature results satisfied the given shape type -/// \param theFeature a source feature -/// \param theType shape type -/// \param an output container for result of shapes -MODELAPI_EXPORT void shapesOfType(const FeaturePtr& theFeature, - const GeomAPI_Shape::ShapeType& theType, - std::set& theShapeResults); +MODELAPI_EXPORT std::shared_ptr shape( + const std::shared_ptr& theResult); /*! Returns the feature error generated according to feature error and exec state * \param theFeature a feature * \return error value or empty string */ -MODELAPI_EXPORT std::string getFeatureError(const FeaturePtr& theFeature); +MODELAPI_EXPORT std::string getFeatureError(const std::shared_ptr& theFeature); /*! * Searches for variable with name \param theName in \param theDocument. * If found, set it value in the \param outValue and returns true. * theSearcher must be located later in the history than the found variable. */ -MODELAPI_EXPORT bool findVariable(const DocumentPtr& theDocument, FeaturePtr theSearcher, - const std::string& theName, double& outValue, ResultParameterPtr& theParam); +MODELAPI_EXPORT bool findVariable(const std::shared_ptr& theDocument, + std::shared_ptr theSearcher, + const std::string& theName, double& outValue, + std::shared_ptr& theParam); /*! * Searches for variable with name \param theName in the active document (Part), when @@ -54,9 +50,10 @@ MODELAPI_EXPORT bool findVariable(const DocumentPtr& theDocument, FeaturePtr the * and returns true. If \param theDocument is empty active document is used. * theSearcher must be located later in the history than the found variable. */ -MODELAPI_EXPORT bool findVariable(FeaturePtr theSearcher, const std::string& theName, - double& outValue, ResultParameterPtr& theParam, - const DocumentPtr& theDocument = DocumentPtr()); +MODELAPI_EXPORT bool findVariable(std::shared_ptr theSearcher, + const std::string& theName, + double& outValue, std::shared_ptr& theParam, + const std::shared_ptr& theDocument = std::shared_ptr()); /*! * Searches for Part result that contains the reference to the given document. @@ -65,7 +62,9 @@ MODELAPI_EXPORT bool findVariable(FeaturePtr theSearcher, const std::string& the * \param theSub document that is searched, the resulting feature references to it * \returns null if not found */ -MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub); +MODELAPI_EXPORT std::shared_ptr findPartResult( + const std::shared_ptr& theMain, + const std::shared_ptr& theSub); /*! * Searches for Part the feature that contains in result the reference to the given document. @@ -74,33 +73,39 @@ MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const Docum * \param theSub document that is searched, the resulting feature references to it * \returns null if not found */ -MODELAPI_EXPORT FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub); +MODELAPI_EXPORT std::shared_ptr findPartFeature( + const std::shared_ptr& theMain, + const std::shared_ptr& theSub); /*! * Returns the composite feature - parent of this feature. * \param theFeature the sub-element of composite * \returns null if it is not sub-element of composite */ -MODELAPI_EXPORT CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature); +MODELAPI_EXPORT std::shared_ptr compositeOwner( + const std::shared_ptr& theFeature); /*! * Returns the compsolid result - parent of this result. * \param theSub the sub-element of comp-solid * \returns null if it is not sub-element of composite */ -MODELAPI_EXPORT ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub); +MODELAPI_EXPORT std::shared_ptr compSolidOwner( + const std::shared_ptr& theSub); /*! -* Returns true if the result contains a not empty list of sub results. It processes result compsolid. +* Returns true if the result contains a not empty list of sub results. +* It processes result compsolid. * \param theResult a result object * \returns boolean value */ -MODELAPI_EXPORT bool hasSubResults(const ResultPtr& theResult); +MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr& theResult); /*! * Adds the results of the given feature to theResults list: including disabled and sub-results */ -MODELAPI_EXPORT void allResults(const FeaturePtr& theFeature, std::list& theResults); +MODELAPI_EXPORT void allResults(const std::shared_ptr& theFeature, + std::list >& theResults); /*! Returns true if there are no parts in the document, which are not activated @@ -109,13 +114,13 @@ MODELAPI_EXPORT void allResults(const FeaturePtr& theFeature, std::list& theFeatures, +MODELAPI_EXPORT bool removeFeaturesAndReferences( + const std::set >& theFeatures, const bool theFlushRedisplay = false, const bool theUseComposite = false, const bool theUseRecursion = true); @@ -125,8 +130,9 @@ MODELAPI_EXPORT bool removeFeaturesAndReferences(const std::set& the * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed * \return true if at least one feature is removed */ -MODELAPI_EXPORT bool removeFeatures(const std::set& theFeatures, - const bool theFlushRedisplay); +MODELAPI_EXPORT bool removeFeatures( + const std::set >& theFeatures, + const bool theFlushRedisplay); /*! Build a map of references for the given set of features * \param theFeatures a list of features @@ -136,26 +142,30 @@ MODELAPI_EXPORT bool removeFeatures(const std::set& theFeatures, list are put into the result container. E.g. if theFeatures contains "Sketch_2", map will contain references to this feature also. */ -MODELAPI_EXPORT void findAllReferences(const std::set& theFeatures, - std::map >& theReferences, - const bool theUseComposite = true, - const bool theUseRecursion = true); +MODELAPI_EXPORT void findAllReferences( + const std::set >& theFeatures, + std::map, + std::set > >& theReferences, + const bool theUseComposite = true, + const bool theUseRecursion = true); /*! In the map of references find all features referenced to the source feature * \param theFeatures a list of features to find references * \param theReferences a map of all references to the features * \param theFeaturesRefsTo an out list of referenced features */ -MODELAPI_EXPORT void findRefsToFeatures(const std::set& aFeatures, - const std::map >& aReferences, - std::set& aFeaturesRefsTo); +MODELAPI_EXPORT void findRefsToFeatures( + const std::set >& aFeatures, + const std::map, + std::set > >& aReferences, + std::set >& aFeaturesRefsTo); /*! Finds referenced of the feature to objects and collects concealed results. * \param theFeatures a model feature * \param theResults container for concealed results. It has no duplications */ -MODELAPI_EXPORT void getConcealedResults(const FeaturePtr& theFeature, - std::list >& theResults); +MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr& theFeature, + std::list >& theResults); } #endif diff --git a/src/ModelGeomAlgo/CMakeLists.txt b/src/ModelGeomAlgo/CMakeLists.txt index 3d4a48070..260c76acf 100755 --- a/src/ModelGeomAlgo/CMakeLists.txt +++ b/src/ModelGeomAlgo/CMakeLists.txt @@ -8,10 +8,12 @@ INCLUDE(UnitTest) SET(PROJECT_HEADERS ModelGeomAlgo.h ModelGeomAlgo_Point2D.h + ModelGeomAlgo_Shape.h ) SET(PROJECT_SOURCES ModelGeomAlgo_Point2D.cpp + ModelGeomAlgo_Shape.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp b/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp index 44759de7e..ab1d70119 100755 --- a/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp +++ b/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp @@ -12,6 +12,8 @@ #include #include +#include + #include #include @@ -176,7 +178,7 @@ namespace ModelGeomAlgo_Point2D { GeomShapePtr aFeatureShape; { std::set anEdgeShapes; - ModelAPI_Tools::shapesOfType(theBaseFeature, GeomAPI_Shape::EDGE, anEdgeShapes); + ModelGeomAlgo_Shape::shapesOfType(theBaseFeature, GeomAPI_Shape::EDGE, anEdgeShapes); if (anEdgeShapes.empty()) return; aFeatureShape = (*anEdgeShapes.begin())->shape(); @@ -190,7 +192,7 @@ namespace ModelGeomAlgo_Point2D { continue; if (aFeature.get()) { std::set anEdgeShapes; - ModelAPI_Tools::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes); + ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes); if (anEdgeShapes.empty()) continue; ResultPtr aResult = *anEdgeShapes.begin(); @@ -220,17 +222,11 @@ namespace ModelGeomAlgo_Point2D { if (thePointToAttributeOrObject.find(aProjectedPoint) != thePointToAttributeOrObject.end()) thePointToAttributeOrObject.at(aProjectedPoint).first.push_back(anAttribute); else { - //std::list< std::shared_ptr > anAttributes; - //anAttributes.push_back(anAttribute); - //thePointToAttributeOrObject.insert(aProjectedPoint, anAttributes); - std::list > anAttributes; std::list > anObjects; anAttributes.push_back(anAttribute); thePointToAttributeOrObject[aProjectedPoint] = std::make_pair(anAttributes, anObjects); } - //thePoints.push_back(aProjectedPoint); - //theAttributeToPoint[anAttribute] = aProjectedPoint; } } } diff --git a/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp b/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp new file mode 100644 index 000000000..fb97aec66 --- /dev/null +++ b/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp @@ -0,0 +1,35 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelAPI_Tools.cpp +// Created: 19 Mar 2017 +// Author: Natalia ERMOLAEVA + +#include + +#include "ModelGeomAlgo_Shape.h" + +#include +#include + + +#ifdef WIN32 +#pragma warning(disable : 4996) // for sprintf +#endif + +namespace ModelGeomAlgo_Shape +{ + void shapesOfType(const FeaturePtr& theFeature, + const GeomAPI_Shape::ShapeType& theType, + std::set& theShapeResults) + { + theShapeResults.clear(); + std::list aResults = theFeature->results(); + std::list::const_iterator aRIter = aResults.cbegin(); + for (; aRIter != aResults.cend(); aRIter++) { + ResultPtr aResult = *aRIter; + GeomShapePtr aShape = aResult->shape(); + if (aShape.get() && aShape->shapeType() == theType) + theShapeResults.insert(aResult); + } + } +} // namespace ModelGeomAlgo_Shape diff --git a/src/ModelGeomAlgo/ModelGeomAlgo_Shape.h b/src/ModelGeomAlgo/ModelGeomAlgo_Shape.h new file mode 100644 index 000000000..847b01b3e --- /dev/null +++ b/src/ModelGeomAlgo/ModelGeomAlgo_Shape.h @@ -0,0 +1,30 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelGeomAlgo_Point2D.h +// Created: 20 Jul 2016 +// Author: Natalia ERMOLAEVA + +#ifndef ModelGeomAlgo_Shape_H +#define ModelGeomAlgo_Shape_H + +#include "ModelGeomAlgo.h" +#include "GeomAPI_Shape.h" + +#include + +class ModelAPI_Feature; +class ModelAPI_Result; + +namespace ModelGeomAlgo_Shape { + + /// Searches Shape results of the feature satisfied the given shape type + /// \param theFeature a feature to obtain AttributeRefAttr + /// \param theType shape type + /// \param theShapeResults a list of results + MODELGEOMALGO_EXPORT void shapesOfType( + const std::shared_ptr& theFeature, + const GeomAPI_Shape::ShapeType& theType, + std::set >& theShapeResults); +} + +#endif diff --git a/src/ModuleBase/ModuleBase_ParamIntSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamIntSpinBox.cpp index 5c7343cdf..cdf698b7a 100644 --- a/src/ModuleBase/ModuleBase_ParamIntSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamIntSpinBox.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index 7dd3e3638..c42e163b8 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index d08ccb44d..bdbae8988 100755 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp index ef8fa81fb..b10b335f1 100644 --- a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp +++ b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/src/PartSet/PartSet_ResultSketchPrs.cpp b/src/PartSet/PartSet_ResultSketchPrs.cpp index fc8700134..b539c6ad4 100755 --- a/src/PartSet/PartSet_ResultSketchPrs.cpp +++ b/src/PartSet/PartSet_ResultSketchPrs.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index e41593337..ec18af32f 100755 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include diff --git a/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp b/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp index d93b666ca..f2808b3ad 100644 --- a/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp +++ b/src/PartSet/PartSet_WidgetFeaturePointSelector.cpp @@ -50,7 +50,7 @@ PartSet_WidgetFeaturePointSelector::PartSet_WidgetFeaturePointSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData) -: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData), myBaseSelected(false) +: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData) { } @@ -62,7 +62,8 @@ PartSet_WidgetFeaturePointSelector::~PartSet_WidgetFeaturePointSelector() bool PartSet_WidgetFeaturePointSelector::isValidSelection( const std::shared_ptr& theValue) { - return true; + return ModuleBase_WidgetShapeSelector::isValidSelection(theValue); + //return true; } //******************************************************************** @@ -76,13 +77,11 @@ bool PartSet_WidgetFeaturePointSelector::activateSelectionAndFilters(bool toActi Handle(Graphic3d_HighlightStyle) aSStyle = aContext->SelectionStyle(); if (toActivate) { std::vector aColors; - aColors = Config_PropManager::color("Visualization", "sketch_entity_color"); + aColors = Config_PropManager::color("Visualization", "sketch_entity_color"); aColor = Quantity_Color(aColors[0] / 255., aColors[1] / 255., aColors[2] / 255., Quantity_TOC_RGB); myHighlightColor = aHStyle->Color(); mySelectionColor = aSStyle->Color(); - - aHStyle->SetTransparency(0.5f); } else { aColor = myHighlightColor; @@ -103,8 +102,6 @@ void PartSet_WidgetFeaturePointSelector::activateCustom() { ModuleBase_WidgetShapeSelector::activateCustom(); - myBaseSelected = false; - myWorkshop->module()->activateCustomPrs(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects, true); } @@ -135,7 +132,25 @@ void PartSet_WidgetFeaturePointSelector::mouseReleased(ModuleBase_IViewWindow* t if (theEvent->button() != Qt::LeftButton) return; - myBaseSelected = true; + // set parameters of preview into parameters of selection in the feature + std::shared_ptr aRefSelectedAttr = + std::dynamic_pointer_cast( + feature()->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT())); + std::shared_ptr aRefPreviewAttr = + std::dynamic_pointer_cast( + feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT())); + aRefSelectedAttr->setValue(aRefPreviewAttr->value()); + + std::shared_ptr aPointSelectedAttr = + std::dynamic_pointer_cast( + feature()->data()->attribute(SketchPlugin_Trim::SELECTED_POINT())); + std::shared_ptr aPointPreviewAttr = + std::dynamic_pointer_cast( + feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT())); + aPointSelectedAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y()); + + updateObject(feature()); + emit focusOutWidget(this); // we need to deselect base feature for better visibility of selected feature XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(false); @@ -159,12 +174,12 @@ bool PartSet_WidgetFeaturePointSelector::fillFeature( std::shared_ptr aRef = std::dynamic_pointer_cast( - feature()->data()->attribute(SketchPlugin_Trim::BASE_OBJECT())); + feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT())); aRef->setValue(anObject); std::shared_ptr anAttributePoint = std::dynamic_pointer_cast( - feature()->data()->attribute(SketchPlugin_Trim::ENTITY_POINT())); + feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT())); anAttributePoint->setValue(aX, anY); // redisplay AIS presentation in viewer #ifndef HIGHLIGHT_STAYS_PROBLEM @@ -172,6 +187,8 @@ bool PartSet_WidgetFeaturePointSelector::fillFeature( XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(true); #endif updateObject(feature()); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + aFilled = true; return aFilled; @@ -183,13 +200,6 @@ QList PartSet_WidgetFeaturePointSelector::getAttributeS return QList(); } -//******************************************************************** -void PartSet_WidgetFeaturePointSelector::updateSelectionName() -{ - if (myBaseSelected) - ModuleBase_WidgetShapeSelector::updateSelectionName(); -} - //******************************************************************** bool PartSet_WidgetFeaturePointSelector::setSelection( QList>& theValues, diff --git a/src/PartSet/PartSet_WidgetFeaturePointSelector.h b/src/PartSet/PartSet_WidgetFeaturePointSelector.h index 56c5105bb..96d559d0c 100644 --- a/src/PartSet/PartSet_WidgetFeaturePointSelector.h +++ b/src/PartSet/PartSet_WidgetFeaturePointSelector.h @@ -49,10 +49,10 @@ Q_OBJECT virtual ~PartSet_WidgetFeaturePointSelector(); - /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating, - /// next, the attribute's validating. It trying on the give selection to current attribute by - /// setting the value inside and calling validators. After this, the previous attribute value is - /// restored.The valid/invalid value is cashed. + /// Checks all widget validator if the owner is valid. Firstly it checks custom widget + /// validating, next, the attribute's validating. It trying on the give selection to current + /// attribute by setting the value inside and calling validators. After this, the previous + /// attribute value is restored.The valid/invalid value is cashed. /// \param theValue a selected presentation in the view /// \return a boolean value virtual bool isValidSelection(const std::shared_ptr& theValue); @@ -81,10 +81,6 @@ Q_OBJECT /// \param theEvent a mouse event virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent); - /// Returns values which should be highlighted when the whidget is active - /// \param theValues a list of presentations - //virtual void getHighlighted(QList>& theValues); - /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// The method is called by the current operation to process the operation preselection. @@ -95,7 +91,6 @@ Q_OBJECT const bool theToValidate); /// Fill preselection used in mouseReleased - //virtual void setPreSelection(const std::shared_ptr& thePreSelected); virtual void setPreSelection(const std::shared_ptr& thePreSelected, ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); @@ -105,9 +100,6 @@ protected: /// a shape. If the attribute do not uses the shape, it is empty virtual QList> getAttributeSelection() const; - /// Computes and updates name of selected object in the widget - virtual void updateSelectionName(); - protected: /// The methiod called when widget is activated virtual void activateCustom(); @@ -121,7 +113,6 @@ protected: CompositeFeaturePtr mySketch; Quantity_Color myHighlightColor; Quantity_Color mySelectionColor; - bool myBaseSelected; }; #endif \ No newline at end of file diff --git a/src/PartSet/PartSet_WidgetSubShapeSelector.cpp b/src/PartSet/PartSet_WidgetSubShapeSelector.cpp index b0e41e4f1..24dd2cad0 100755 --- a/src/PartSet/PartSet_WidgetSubShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetSubShapeSelector.cpp @@ -20,6 +20,7 @@ #include #include +#include #include @@ -230,7 +231,7 @@ void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); // edges on feature std::set anEdgeResults; - ModelAPI_Tools::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeResults); + ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeResults); if (!anEdgeResults.empty()) { GeomShapePtr aFeatureShape = (*anEdgeResults.begin())->shape(); diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index d9fff77ce..11c22f0ae 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -490,9 +490,9 @@ std::shared_ptr SketchAPI_Sketch::addTrim( { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Trim::ID()); - fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::BASE_OBJECT())); + fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT())); - AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::ENTITY_POINT()); + AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT()); if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) { AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast(anAttribute); fillAttribute(thePositionPoint, aPointAttr); diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 87ef7b27a..80df2df05 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -78,6 +78,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_FilletVertexValidator); aFactory->registerValidator("SketchPlugin_SplitValidator", new SketchPlugin_SplitValidator); + aFactory->registerValidator("SketchPlugin_TrimValidator", + new SketchPlugin_TrimValidator); aFactory->registerValidator("SketchPlugin_MiddlePointAttr", new SketchPlugin_MiddlePointAttrValidator); aFactory->registerValidator("SketchPlugin_ArcTangentPoint", diff --git a/src/SketchPlugin/SketchPlugin_Trim.cpp b/src/SketchPlugin/SketchPlugin_Trim.cpp index 7373e34af..6e2fab3ed 100644 --- a/src/SketchPlugin/SketchPlugin_Trim.cpp +++ b/src/SketchPlugin/SketchPlugin_Trim.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -23,6 +24,8 @@ #include #include +#include + #include #include #include @@ -64,25 +67,38 @@ SketchPlugin_Trim::SketchPlugin_Trim() void SketchPlugin_Trim::initAttributes() { - data()->addAttribute(SketchPlugin_Trim::BASE_OBJECT(), ModelAPI_AttributeReference::typeId()); - data()->addAttribute(ENTITY_POINT(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(SketchPlugin_Trim::SELECTED_OBJECT(), + ModelAPI_AttributeReference::typeId()); + data()->addAttribute(SELECTED_POINT(), GeomDataAPI_Point2D::typeId()); + + data()->addAttribute(PREVIEW_POINT(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(PREVIEW_OBJECT(), ModelAPI_AttributeReference::typeId()); + + data()->attribute(PREVIEW_POINT())->setIsArgument(false); + data()->attribute(SELECTED_POINT())->setIsArgument(false); + data()->attribute(PREVIEW_OBJECT())->setIsArgument(false); + + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PREVIEW_POINT()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PREVIEW_OBJECT()); } -void SketchPlugin_Trim::findShapePoints(std::shared_ptr& aStartPoint, +void SketchPlugin_Trim::findShapePoints(const std::string& theObjectAttributeId, + const std::string& thePointAttributeId, + std::shared_ptr& aStartPoint, std::shared_ptr& aLastPoint) { AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::BASE_OBJECT())); + data()->attribute(theObjectAttributeId)); ObjectPtr aBaseObject = aBaseObjectAttr->value(); AttributePoint2DPtr aPoint = std::dynamic_pointer_cast( - data()->attribute(ENTITY_POINT())); + data()->attribute(thePointAttributeId)); std::shared_ptr anAttributePnt2d = aPoint->pnt(); std::shared_ptr anAttributePnt = sketch()->to3D(anAttributePnt2d->x(), anAttributePnt2d->y()); if (myCashedShapes.find(aBaseObject) == myCashedShapes.end()) - fillObjectShapes(aBaseObject); + fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints); const std::set& aShapes = myCashedShapes[aBaseObject]; if (!aShapes.empty()) { @@ -116,10 +132,10 @@ std::shared_ptr SketchPlugin_Trim::convertPoint( std::shared_ptr aPoint; AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::BASE_OBJECT())); + data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT())); ObjectPtr aBaseObject = aBaseObjectAttr->value(); if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end()) - return aPoint; + fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints); bool aFound = false; const PointToRefsMap& aRefsMap = myObjectToPoints.at(aBaseObject); @@ -141,7 +157,8 @@ std::shared_ptr SketchPlugin_Trim::convertPoint( } } if (!aFound) { - // returns an end of the shape to define direction of split if feature's attribute participates + // returns an end of the shape to define direction of split if feature's attribute + // participates std::shared_ptr aPlane = sketch()->plane(); aPoint = thePoint->to2D(aPlane); } @@ -160,7 +177,7 @@ void SketchPlugin_Trim::execute() // Check the base objects are initialized. AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::BASE_OBJECT())); + data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT())); if(!aBaseObjectAttr->isInitialized()) { setError("Error: Base object is not initialized."); return; @@ -172,7 +189,7 @@ void SketchPlugin_Trim::execute() /// points of trim std::shared_ptr aStartShapePoint, aLastShapePoint; - findShapePoints(aStartShapePoint, aLastShapePoint); + findShapePoints(SELECTED_OBJECT(), SELECTED_POINT(), aStartShapePoint, aLastShapePoint); std::shared_ptr aStartShapePoint2d = convertPoint(aStartShapePoint); std::shared_ptr aLastShapePoint2d = convertPoint(aLastShapePoint); @@ -200,8 +217,16 @@ void SketchPlugin_Trim::execute() aFurtherCoincidences, aModifiedAttributes); aFeaturesToDelete.insert(aBaseFeature); - // as circle is removed, temporary fill this attribute + // as circle is removed, erase it from dependencies(arguments) of this feature + // otherwise Trim feature will be removed with the circle before + // this operation is finished aBaseObjectAttr->setObject(ResultPtr()); + + AttributeReferencePtr aPreviewObjectAttr = + std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT())); + aPreviewObjectAttr->setObject(ResultPtr()); + } else if (aKind == SketchPlugin_Line::ID()) { trimLine(aStartShapePoint2d, aLastShapePoint2d, @@ -213,6 +238,9 @@ void SketchPlugin_Trim::execute() } // + if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end()) + fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints); + const PointToRefsMap& aRefsMap = myObjectToPoints.at(aBaseObject); std::set::const_iterator anIt = aFurtherCoincidences.begin(), aLast = aFurtherCoincidences.end(); @@ -330,25 +358,63 @@ bool SketchPlugin_Trim::isMacro() const AISObjectPtr SketchPlugin_Trim::getAISObject(AISObjectPtr thePrevious) { AISObjectPtr anAIS = thePrevious; - // feature for trim - AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::BASE_OBJECT())); - ObjectPtr aBaseObject = aBaseObjectAttr->value(); - if (!aBaseObject.get()) + + std::list > aShapes; + GeomShapePtr aPreviewShape = getSubShape(PREVIEW_OBJECT(), PREVIEW_POINT()); + if (aPreviewShape.get()) + aShapes.push_back(aPreviewShape); + GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT()); + if (aSelectedShape.get()) + aShapes.push_back(aSelectedShape); + + if (aShapes.empty()) return AISObjectPtr(); - FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); + + GeomShapePtr aBaseShape = GeomAlgoAPI_CompoundBuilder::compound(aShapes); + if (!aBaseShape.get()) + return AISObjectPtr(); + + if (aBaseShape.get()) { + if (!anAIS) + anAIS = AISObjectPtr(new GeomAPI_AISObject); + anAIS->createShape(aBaseShape); + + std::vector aColor; + aColor = Config_PropManager::color("Visualization", "operation_remove_feature_color"); + double aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH(); + int aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE(); + anAIS->setColor(aColor[0], aColor[1], aColor[2]); + // width when there is not base object should be extened in several points + // in order to see this preview over highlight + anAIS->setWidth(aWidth+4); + anAIS->setLineStyle(aLineStyle); + } + else + anAIS = AISObjectPtr(); + + return anAIS; +} + +GeomShapePtr SketchPlugin_Trim::getSubShape(const std::string& theObjectAttributeId, + const std::string& thePointAttributeId) +{ + GeomShapePtr aBaseShape; + + AttributeReferencePtr anObjectAttr = std::dynamic_pointer_cast( + data()->attribute(theObjectAttributeId)); + ObjectPtr aBaseObject = anObjectAttr->value(); + if (!aBaseObject.get()) + return aBaseShape; // point on feature AttributePoint2DPtr aPoint = std::dynamic_pointer_cast( - data()->attribute(ENTITY_POINT())); + data()->attribute(thePointAttributeId)); std::shared_ptr anAttributePnt2d = aPoint->pnt(); std::shared_ptr anAttributePnt = sketch()->to3D(anAttributePnt2d->x(), anAttributePnt2d->y()); if (myCashedShapes.find(aBaseObject) == myCashedShapes.end()) - fillObjectShapes(aBaseObject); - - GeomShapePtr aBaseShape; + fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints); const std::set& aShapes = myCashedShapes[aBaseObject]; if (!aShapes.empty()) { @@ -360,33 +426,7 @@ AISObjectPtr SketchPlugin_Trim::getAISObject(AISObjectPtr thePrevious) aBaseShape = aShape; } } - - if (aBaseShape.get()) { - if (!anAIS) - anAIS = AISObjectPtr(new GeomAPI_AISObject); - anAIS->createShape(aBaseShape); - - std::shared_ptr anAuxiliaryAttr = - aBaseFeature->data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID()); - - bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value(); - std::vector aColor; - aColor = Config_PropManager::color("Visualization", "operation_remove_feature_color"); - double aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH(); - int aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE(); - if (isConstruction) { - aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH_AUXILIARY(); - aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY(); - } - anAIS->setColor(aColor[0], aColor[1], aColor[2]); - // width is extened in several points in order to see this preview over highlight - anAIS->setWidth(aWidth + 2); - anAIS->setLineStyle(aLineStyle); - } - else - anAIS = AISObjectPtr(); - - return anAIS; + return aBaseShape; } void SketchPlugin_Trim::getFeaturePoints(const FeaturePtr& theFeature, @@ -417,7 +457,7 @@ void SketchPlugin_Trim::getConstraints(std::set& theFeaturesToDelete // Check the base objects are initialized. AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Trim::BASE_OBJECT())); + aData->attribute(SketchPlugin_Trim::SELECTED_OBJECT())); FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); ResultPtr aBaseFeatureResult = getFeatureResult(aBaseFeature); @@ -565,7 +605,7 @@ void SketchPlugin_Trim::trimLine(const std::shared_ptr& theStartS { // Check the base objects are initialized. AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::BASE_OBJECT())); + data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT())); ObjectPtr aBaseObject = aBaseObjectAttr->value(); FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); @@ -614,7 +654,8 @@ void SketchPlugin_Trim::trimLine(const std::shared_ptr& theStartS (aBaseFeature->attribute(aModifiedAttribute))); } else { - // result is two lines: start line point - start shape point, last shape point - last line point + // result is two lines: start line point - start shape point, + // last shape point - last line point // create second line FeaturePtr anNewFeature = createLineFeature(aBaseFeature, aLastShapePoint, aLastFeaturePoint); thePoints.insert(std::dynamic_pointer_cast @@ -646,7 +687,7 @@ void SketchPlugin_Trim::trimArc(const std::shared_ptr& theStartSh { // Check the base objects are initialized. AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::BASE_OBJECT())); + data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT())); ObjectPtr aBaseObject = aBaseObjectAttr->value(); FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); @@ -730,7 +771,7 @@ FeaturePtr SketchPlugin_Trim::trimCircle(const std::shared_ptr& t { // Check the base objects are initialized. AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::BASE_OBJECT())); + data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT())); ObjectPtr aBaseObject = aBaseObjectAttr->value(); FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); @@ -1013,13 +1054,10 @@ std::shared_ptr SketchPlugin_Trim::getFeatureResult( } //******************************************************************** -bool SketchPlugin_Trim::useGraphicIntersection() const -{ - return true; -} - -//******************************************************************** -void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject) +void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject, + ObjectPtr& theSketch, + std::map >& theCashedShapes, + std::map& theObjectToPoints) { PointToRefsMap aPointsInfo; @@ -1034,7 +1072,7 @@ void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject) FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); std::set anEdgeShapes; // edges on feature - ModelAPI_Tools::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes); + ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes); if (!anEdgeShapes.empty()) { GeomShapePtr aFeatureShape = (*anEdgeShapes.begin())->shape(); @@ -1042,8 +1080,8 @@ void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject) ModelGeomAlgo_Point2D::getPointsOfReference(aFeature, SketchPlugin_ConstraintCoincidence::ID(), aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID()); // layed on feature coincidences to divide it on several shapes - SketchPlugin_Sketch* aSketch = sketch(); - std::shared_ptr aData = aSketch->data(); + //SketchPlugin_Sketch* aSketch = sketch(); + std::shared_ptr aData = theSketch->data(); std::shared_ptr aC = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); std::shared_ptr aX = std::dynamic_pointer_cast( @@ -1055,52 +1093,18 @@ void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject) ModelGeomAlgo_Point2D::getPointsInsideShape(aFeatureShape, aRefAttributes, aC->pnt(), aX->dir(), aY, aPointsInfo); - // intersection points - if (useGraphicIntersection()) { - std::list aFeatures; - for (int i = 0; i < aSketch->numberOfSubs(); i++) { - FeaturePtr aFeature = aSketch->subFeature(i); - if (aFeature.get()) - aFeatures.push_back(aFeature); - } - ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPointsInfo); + std::list aFeatures; + CompositeFeaturePtr aSketchComposite = + std::dynamic_pointer_cast(theSketch); + for (int i = 0; i < aSketchComposite->numberOfSubs(); i++) { + FeaturePtr aFeature = aSketchComposite->subFeature(i); + if (aFeature.get()) + aFeatures.push_back(aFeature); } - GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPointsInfo, aShapes); - } - myObjectToPoints[theObject] = aPointsInfo; - myCashedShapes[theObject] = aShapes; -} + ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPointsInfo); -//******************************************************************** -void SketchPlugin_Trim::attributeChanged(const std::string& theID) -{ - //data()->addAttribute(SketchPlugin_Trim::BASE_OBJECT(), ModelAPI_AttributeReference::typeId()); - if (theID == SketchPlugin_Trim::BASE_OBJECT()) { - bool isValidAttribute = false; - // feature for trim - AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::BASE_OBJECT())); - ObjectPtr aBaseObject = aBaseObjectAttr->value(); - if (aBaseObject.get()) { - FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); - // point on feature - AttributePoint2DPtr aPoint = std::dynamic_pointer_cast( - data()->attribute(ENTITY_POINT())); - std::shared_ptr anAttributePnt2d = aPoint->pnt(); - std::shared_ptr anAttributePnt = sketch()->to3D(anAttributePnt2d->x(), - anAttributePnt2d->y()); - - if (myCashedShapes.find(aBaseObject) == myCashedShapes.end()) - fillObjectShapes(aBaseObject); - - const std::set& aShapes = myCashedShapes[aBaseObject]; - isValidAttribute = !aShapes.empty(); - - if (!isValidAttribute) { - bool aWasBlocked = data()->blockSendAttributeUpdated(true); - aBaseObjectAttr->setValue(ObjectPtr()); - data()->blockSendAttributeUpdated(aWasBlocked); - } - } + GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPointsInfo, aShapes); } + theObjectToPoints[theObject] = aPointsInfo; + theCashedShapes[theObject] = aShapes; } diff --git a/src/SketchPlugin/SketchPlugin_Trim.h b/src/SketchPlugin/SketchPlugin_Trim.h index 9f3702f84..6b95dd51b 100644 --- a/src/SketchPlugin/SketchPlugin_Trim.h +++ b/src/SketchPlugin/SketchPlugin_Trim.h @@ -38,17 +38,31 @@ class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentab } /// The value parameter for the constraint - inline static const std::string& BASE_OBJECT() + inline static const std::string& SELECTED_OBJECT() { - static const std::string MY_CONSTRAINT_BASE_OBJECT("BaseObject"); - return MY_CONSTRAINT_BASE_OBJECT; + static const std::string MY_SELECTED_OBJECT("SelectedObject"); + return MY_SELECTED_OBJECT; } /// Start 2D point of the split segment - inline static const std::string& ENTITY_POINT() + inline static const std::string& SELECTED_POINT() { - static const std::string MY_ENTITY_POINT("ConstraintEntityPoint"); - return MY_ENTITY_POINT; + static const std::string MY_SELECTED_POINT("SelectedPoint"); + return MY_SELECTED_POINT; + } + + /// The value parameter for the preview object + inline static const std::string& PREVIEW_OBJECT() + { + static const std::string MY_PREVIEW_OBJECT("PreviewObject"); + return MY_PREVIEW_OBJECT; + } + + /// Start 2D point of the split segment + inline static const std::string& PREVIEW_POINT() + { + static const std::string MY_PREVIEW_POINT("PreviewPoint"); + return MY_PREVIEW_POINT; } /// \brief Creates a new part document if needed @@ -65,10 +79,6 @@ class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentab /// This is necessary to perform execute only by apply the feature SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; } - /// Called on change of any argument-attribute of this object - /// \param theID identifier of changed attribute - SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - /// \brief Use plugin manager for features creation SketchPlugin_Trim(); @@ -78,7 +88,19 @@ class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentab /// Moves the feature : Empty SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {}; + typedef std::map, + std::pair >, + std::list > > > PointToRefsMap; + + static void fillObjectShapes(const ObjectPtr& theObject, + ObjectPtr& theSketch, + std::map >& theCashedShapes, + std::map& theObjectToPoints); + private: + GeomShapePtr getSubShape(const std::string& theObjectAttributeId, + const std::string& thePointAttributeId); + /// Returns geom point attribute of the feature bounds. It processes line or arc. /// For circle feature, the result attributes are null /// \param theFeature a source feature @@ -237,11 +259,9 @@ private: const std::shared_ptr& theFeature); private: - bool useGraphicIntersection() const; - - void fillObjectShapes(const ObjectPtr& theObject); - - void findShapePoints(std::shared_ptr& aStartPoint, + void findShapePoints(const std::string& theObjectAttributeId, + const std::string& thePointAttributeId, + std::shared_ptr& aStartPoint, std::shared_ptr& aLastPoint); std::shared_ptr convertPoint(const std::shared_ptr& thePoint); @@ -249,10 +269,6 @@ private: private: std::map > myCashedShapes; - typedef std::map, - std::pair >, - std::list > > > PointToRefsMap; - std::map myObjectToPoints; }; diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index d42c78360..cb4b746b6 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -16,6 +16,7 @@ #include "SketchPlugin_Line.h" #include "SketchPlugin_Point.h" #include "SketchPlugin_Sketch.h" +#include "SketchPlugin_Trim.h" #include "SketchPlugin_Tools.h" #include "SketcherPrs_Tools.h" @@ -36,6 +37,7 @@ #include #include +#include #include #include @@ -820,7 +822,7 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute, aKind == SketchPlugin_Circle::ID()) { std::set anEdgeShapes; - ModelAPI_Tools::shapesOfType(anAttrFeature, GeomAPI_Shape::EDGE, anEdgeShapes); + ModelGeomAlgo_Shape::shapesOfType(anAttrFeature, GeomAPI_Shape::EDGE, anEdgeShapes); if (anEdgeShapes.empty() || anEdgeShapes.size() > 1 /*there case has not existed yet*/) return aValid; @@ -861,6 +863,63 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute, return aValid; } +bool SketchPlugin_TrimValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + bool aValid = false; + + if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) { + theError = "The attribute with the %1 type is not processed"; + theError.arg(theAttribute->attributeType()); + return aValid; + } + AttributeReferencePtr aBaseObjectAttr = + std::dynamic_pointer_cast(theAttribute); + + std::shared_ptr aTrimFeature = + std::dynamic_pointer_cast(theAttribute->owner()); + + ObjectPtr aBaseObject = aBaseObjectAttr->value(); + if (!aBaseObject) { + AttributePtr aPreviewAttr = aTrimFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()); + aBaseObjectAttr = std::dynamic_pointer_cast(aPreviewAttr); + aBaseObject = aBaseObjectAttr->value(); + + //return aValid; + } + + FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject); + if (!aBaseFeature) + return aValid; + + std::string aKind = aBaseFeature->getKind(); + if (aKind != SketchPlugin_Line::ID() && + aKind != SketchPlugin_Arc::ID() && + aKind != SketchPlugin_Circle::ID()) + return aValid; + + // point on feature + AttributePoint2DPtr aPoint = std::dynamic_pointer_cast( + aTrimFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT())); + + SketchPlugin_Sketch* aSketch = aTrimFeature->sketch(); + + std::shared_ptr anAttributePnt2d = aPoint->pnt(); + std::shared_ptr anAttributePnt = aSketch->to3D(anAttributePnt2d->x(), + anAttributePnt2d->y()); + + std::map > aCashedShapes; + std::map, + std::pair >, + std::list > > > > anObjectToPoints; + SketchPlugin_Trim::fillObjectShapes(aBaseObject, aSketch->data()->owner(), + aCashedShapes, anObjectToPoints); + const std::set& aShapes = aCashedShapes[aBaseObject]; + + return aShapes.size() > 1; +} + bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index 70120d614..aaae2d957 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -239,6 +239,27 @@ class SketchPlugin_SplitValidator : public ModelAPI_AttributeValidator Events_InfoMessage& theError) const; }; +/**\class SketchPlugin_TrimValidator + * \ingroup Validators + * \brief Validator for the entity of the following type: + * - Linear segment with point(s) coinident to this line or intersected it + * - Arc with point(s) coincident to the arc or intersected it + * - Circle with at least 2 split-points on this circle or intersected it + * + * Checks that there are coincident point on selected feature. + */ +class SketchPlugin_TrimValidator : public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + //! \param theError error message + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const; +}; + /**\class SketchPlugin_IntersectionValidator * \ingroup Validators * \brief Validator for the attribute to be intersected with the sketch plane. diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index ab023e2fa..44f52eefb 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -86,7 +86,7 @@ + enable_value="enable_by_preferences" reference_attribute="ArcCenterRef" /> @@ -153,13 +153,13 @@ tooltip="Trim selected segment arc or circle on intersection points nearest to the graphic selection" icon="icons/Sketch/trim.png"> - + diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index e16cccf83..dd9f98f3c 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index fa48ac096..bbf1f0420 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1389,7 +1389,10 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) #endif aParameters.Append(MyVCallBack); + MyTCommunicator->registerPlugin("SMBrowser"); // custom plugin to view ModelAPI + MyTCommunicator->init(aParameters); + MyTCommunicator->Activate("SMBrowser"); // to have button in TInspector MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model MyTCommunicator->Activate("TKDFBrowser"); }