Salome HOME
#2027 Sketcher Trim Feature: 1. preview/selected attributes in trim; 2. avoid includi...
authornds <nds@opencascade.com>
Tue, 21 Mar 2017 08:01:46 +0000 (11:01 +0300)
committernds <nds@opencascade.com>
Tue, 21 Mar 2017 08:02:18 +0000 (11:02 +0300)
46 files changed:
CMakeCommon/FindTInspector.cmake
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp
src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp
src/FeaturesPlugin/FeaturesPlugin_Recover.cpp
src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp
src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp
src/FeaturesPlugin/FeaturesPlugin_Translation.cpp
src/GeomAPI/GeomAPI_Trsf.cpp
src/GeomValidators/GeomValidators_DifferentShapes.cpp
src/GeomValidators/GeomValidators_IntersectionSelection.cpp
src/InitializationPlugin/InitializationPlugin_EvalListener.cpp
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelectionList.cpp
src/Model/Model_Data.cpp
src/Model/Model_Document.cpp
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultPart.cpp
src/Model/Model_Session.cpp
src/ModelAPI/ModelAPI_AttributeSelectionList.h
src/ModelAPI/ModelAPI_Result.h
src/ModelAPI/ModelAPI_ResultPart.h
src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Tools.h
src/ModelGeomAlgo/CMakeLists.txt
src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp
src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp [new file with mode: 0644]
src/ModelGeomAlgo/ModelGeomAlgo_Shape.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_ParamIntSpinBox.cpp
src/ModuleBase/ModuleBase_ParamSpinBox.cpp
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/ParametersPlugin/ParametersPlugin_EvalListener.cpp
src/PartSet/PartSet_ResultSketchPrs.cpp
src/PartSet/PartSet_Validators.cpp
src/PartSet/PartSet_WidgetFeaturePointSelector.cpp
src/PartSet/PartSet_WidgetFeaturePointSelector.h
src/PartSet/PartSet_WidgetSubShapeSelector.cpp
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Trim.cpp
src/SketchPlugin/SketchPlugin_Trim.h
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_Selection.cpp
src/XGUI/XGUI_Workshop.cpp

index b553776237a723494a3d46fa6e97a1ad406d9793..7ba0468a23f8fd2e9a003ed6220a155b887e5001 100644 (file)
@@ -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})
index f3941ec119ccd981fffc79b2dd5907f6e1cf786f..2add72cf8504b66fd4a61eff070a4af77f0a7b35 100644 (file)
@@ -10,6 +10,7 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Session.h>
index f3dbf0683f8ddf50d20bef8e1d21c56a4022f1f9..de5a25f859071ac85ae8afbad5a5dee41da75238 100644 (file)
@@ -7,6 +7,7 @@
 #include "FeaturesPlugin_CompositeBoolean.h"
 
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_Tools.h>
 
 #include <GeomAlgoAPI_Boolean.h>
index 26023890ba26deff27198ee0ebaf1e614adfcb6f..7bddd8e176f83cfe7458ae27c14bfc110dcfcb2a 100644 (file)
@@ -11,6 +11,7 @@
 #include <GeomAPI_Ax1.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Lin.h>
+#include <GeomAPI_Trsf.h>
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeInteger.h>
index 4bbfd76e858d294d47999b3f45cff366337897a5..3e62ab7d064447cb76a512a02c4e66b78b792b36 100644 (file)
@@ -14,6 +14,7 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Tools.h>
 #include <GeomAlgoAPI_Copy.h>
 
index 41e0468bee760c58dfddb50d989a01d5db5d995c..27b1b859161cfc7f921d12b39b9a49bad5d2c2c2 100755 (executable)
@@ -16,6 +16,7 @@
 
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Lin.h>
+#include <GeomAPI_Trsf.h>
 
 #include <FeaturesPlugin_Tools.h>
 
index d254eeef70bc3e9ff461c135abc20d7a2a1b06d0..2c3bd6521cd85c24a0cd5864debab0733dd86f89 100644 (file)
@@ -12,6 +12,7 @@
 #include <GeomAPI_Face.h>
 #include <GeomAPI_Lin.h>
 #include <GeomAPI_Pln.h>
+#include <GeomAPI_Trsf.h>
 
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
index 34e5bd1122b2e1a642e6cfdfc82a0e07c7cb171a..74ff736adc6f907ac7e0221fd70feae58756d755 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Lin.h>
+#include <GeomAPI_Trsf.h>
 
 #include <GeomAlgoAPI_PointBuilder.h>
 
index f0df9471f0ecd3238bbfbf5ffcfed2345b502934..7246364f13031cf51b8f097f38c69c3be94be06e 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <gp_Ax1.hxx>
 #include <gp_Ax2.hxx>
+#include <gp_GTrsf.hxx>
 #include <gp_Trsf.hxx>
 
 #define MY_TRSF implPtr<gp_Trsf>()
index 01eb0409a75857c9c14d2d6614ebc9d804a80a5d..c9c16e663664611a04362fa14bcd0f1a3b949b04 100644 (file)
@@ -11,6 +11,8 @@
 #include <ModelAPI_AttributeSelection.h>
 #include "ModelAPI_Object.h"
 
+#include <GeomAPI_Shape.h>
+
 bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute,
                                       const std::list<std::string>& theArguments,
                                       Events_InfoMessage& theError) const
index 7ecbf5f3876d67e136e604caf4076174cedeb992..5e72a378bf87965f770c7f9d5b34003494bccbe2 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "GeomValidators_IntersectionSelection.h"
 
+#include <GeomAPI_Shape.h>
+
 #include <Events_InfoMessage.h>
 
 #include <ModelAPI_AttributeInteger.h>
index 86d457a7327545cbbc2b8217898f1d1f6c827245..62698cd9277912a1a4b4365bc8fba9d880d523e5 100644 (file)
@@ -21,6 +21,7 @@
 #include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Events.h>
+#include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Tools.h>
 
index 7af146794ad52f652bdbc4af3d557bcb55ab22e5..55ccbfc3065fd6e71a07e37e36039b8198964389 100644 (file)
@@ -15,6 +15,7 @@
 #include <Model_ResultConstruction.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_CompositeFeature.h>
index 16e5d73dea22784bc3ebfadeb43c651c15cdb1d7..caaee41f407425e0767de254bfb905c8e4c3f496 100644 (file)
@@ -10,6 +10,8 @@
 #include "Model_Events.h"
 #include "Model_Data.h"
 
+#include <GeomAPI_Shape.h>
+
 #include <TDF_AttributeIterator.hxx>
 #include <TDF_ChildIterator.hxx>
 #include <TDF_RelocationTable.hxx>
index 2d28604bb0b2cf75fcf9d413484fac9bd7e80275..cbe96e2b3c043caf58214590311b078b170ec851 100644 (file)
@@ -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);
+    }
   }
 }
 
index 8053271501061fbd29be22294447dda0dd1f9c26..d4e7b2d23a2bf5bdd88e30bd4fb5a62acf31ebc3 100755 (executable)
@@ -16,6 +16,7 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <Events_Loop.h>
 #include <Events_InfoMessage.h>
 
index 0cd0fd5d2a472092f02532c07451c2bb6349b5cb..216aab493f212dc73adad31d62856091a34a980f 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <Model_ResultBody.h>
 #include <Model_BodyBuilder.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_Tools.h>
 #include <Config_PropManager.h>
 #include <ModelAPI_Events.h>
index 74e2b22a19b74419e14c219b339ebe9bcf86744b..d3057534885e8e2b932c72a92b7451e862b12622 100644 (file)
@@ -20,6 +20,8 @@
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
 
+#include <GeomAPI_Trsf.h>
+
 #include <TNaming_Tool.hxx>
 #include <TNaming_NamedShape.hxx>
 #include <TDataStd_Name.hxx>
index 44fcf4f18ac1086e0ca1d1b7357814c88cb09aa6..924783bb25e1955dd2ce3dbe4fda71cd65b2e054 100644 (file)
@@ -21,6 +21,8 @@
 #include <Config_ValidatorMessage.h>
 #include <Config_ModuleReader.h>
 #include <Config_ValidatorReader.h>
+
+#include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_Tools.h>
 
index c5fe4c9349c007dd198181777c11c846187825ee..cdcff39d545969b2e71cf32248d5e5fec186e637 100644 (file)
@@ -10,6 +10,8 @@
 #include "ModelAPI_AttributeSelection.h"
 #include <ModelAPI_Result.h>
 
+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<GeomAPI_Shape>& theSubShape,
                       const bool theTemporarily = false) = 0;
 
   /// Adds the new reference to the end of the list by the naming name of the selected shape
index 3f30c57c7ced69f322ed942666723156a8bdaa82..2b86eaa4f08fc8e237d162be93d6e37bd0560a61 100644 (file)
@@ -8,7 +8,7 @@
 #define ModelAPI_Result_H_
 
 #include "ModelAPI_Object.h"
-#include <GeomAPI_Shape.h>
+class GeomAPI_Shape;
 
 class ModelAPI_Feature;
 
index f86754e8059d780aa095e37603142af771b8f14c..7a7df7ef4b17093656c105df66da64fd3b390cd7 100644 (file)
@@ -8,7 +8,7 @@
 #define ModelAPI_ResultPart_H_
 
 #include "ModelAPI_Result.h"
-#include <GeomAPI_Trsf.h>
+class GeomAPI_Trsf;
 
 #include <string>
 
index 8d65638b98da517120e959f7d42b725aaf8e1a76..963a0c31d78dd5a1cde2e8910946e8ebc0033da8 100755 (executable)
@@ -6,9 +6,11 @@
 
 #include "ModelAPI_Tools.h"
 #include <ModelAPI_Session.h>
+#include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_AttributeDocRef.h>
@@ -90,21 +92,6 @@ std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
   return theResult->shape();
 }
 
-void shapesOfType(const FeaturePtr& theFeature,
-                  const GeomAPI_Shape::ShapeType& theType,
-                  std::set<ResultPtr>& theShapeResults)
-{
-  theShapeResults.clear();
-  std::list<ResultPtr> aResults = theFeature->results();
-  std::list<ResultPtr>::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__;
index 573ee12a3849096d4a3023aff69fc3819e0c9d92..1bf2e2a4e235122e37685d2084afa7bb3c6c3dfd 100755 (executable)
@@ -9,44 +9,40 @@
 
 #include "ModelAPI.h"
 
-#include <ModelAPI_CompositeFeature.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_Result.h>
-#include <ModelAPI_ResultParameter.h>
-#include <ModelAPI_ResultCompSolid.h>
+class ModelAPI_CompositeFeature;
+class ModelAPI_Document;
+class ModelAPI_Feature;
+class ModelAPI_Result;
+class ModelAPI_ResultParameter;
+class ModelAPI_ResultCompSolid;
 
-#include <GeomAPI_Shape.h>
+class GeomAPI_Shape;
 
 #include <vector>
 #include <map>
 #include <set>
+#include <list>
 
 namespace ModelAPI_Tools {
 /// Returns shape from the given Result object
-MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> 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<ResultPtr>& theShapeResults);
+MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(
+                                   const std::shared_ptr<ModelAPI_Result>& 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<ModelAPI_Feature>& 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<ModelAPI_Document>& theDocument,
+                                  std::shared_ptr<ModelAPI_Feature> theSearcher,
+                                  const std::string& theName, double& outValue,
+                                  std::shared_ptr<ModelAPI_ResultParameter>& 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<ModelAPI_Feature> theSearcher,
+  const std::string& theName,
+  double& outValue, std::shared_ptr<ModelAPI_ResultParameter>& theParam,
+  const std::shared_ptr<ModelAPI_Document>& theDocument = std::shared_ptr<ModelAPI_Document>());
 
 /*!
  * 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<ModelAPI_Result> findPartResult(
+                                              const std::shared_ptr<ModelAPI_Document>& theMain,
+                                              const std::shared_ptr<ModelAPI_Document>& 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<ModelAPI_Feature> findPartFeature(
+                                           const std::shared_ptr<ModelAPI_Document>& theMain,
+                                           const std::shared_ptr<ModelAPI_Document>& 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<ModelAPI_CompositeFeature> compositeOwner(
+                                        const std::shared_ptr<ModelAPI_Feature>& 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<ModelAPI_ResultCompSolid> compSolidOwner(
+                                            const std::shared_ptr<ModelAPI_Result>& 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<ModelAPI_Result>& 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<ResultPtr>& theResults);
+MODELAPI_EXPORT void allResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                std::list<std::shared_ptr<ModelAPI_Result> >& 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<ResultPt
  */
 MODELAPI_EXPORT bool allDocumentsActivated(std::string& theNotActivatedNames);
 
-
 /*! Removes features from the document
 * \param theFeatures a list of features to be removed
 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
 * \return true if at least one feature is removed
 */
-MODELAPI_EXPORT bool removeFeaturesAndReferences(const std::set<FeaturePtr>& theFeatures,
+MODELAPI_EXPORT bool removeFeaturesAndReferences(
+                       const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
                                                  const bool theFlushRedisplay = false,
                                                  const bool theUseComposite = false,
                                                  const bool theUseRecursion = true);
@@ -125,8 +130,9 @@ MODELAPI_EXPORT bool removeFeaturesAndReferences(const std::set<FeaturePtr>& 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<FeaturePtr>& theFeatures,
-                                    const bool theFlushRedisplay);
+MODELAPI_EXPORT bool removeFeatures(
+                            const std::set<std::shared_ptr<ModelAPI_Feature> >& 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<FeaturePtr>& 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<FeaturePtr>& theFeatures,
-                                       std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
-                                       const bool theUseComposite = true,
-                                       const bool theUseRecursion = true);
+MODELAPI_EXPORT void findAllReferences(
+  const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
+  std::map<std::shared_ptr<ModelAPI_Feature>,
+  std::set<std::shared_ptr<ModelAPI_Feature> > >& 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<FeaturePtr>& aFeatures,
-                                const std::map<FeaturePtr, std::set<FeaturePtr> >& aReferences,
-                                std::set<FeaturePtr>& aFeaturesRefsTo);
+MODELAPI_EXPORT void findRefsToFeatures(
+  const std::set<std::shared_ptr<ModelAPI_Feature> >& aFeatures,
+  const std::map<std::shared_ptr<ModelAPI_Feature>,
+                 std::set<std::shared_ptr<ModelAPI_Feature> > >& aReferences,
+  std::set<std::shared_ptr<ModelAPI_Feature> >& 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<std::shared_ptr<ModelAPI_Result> >& theResults);
+MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                   std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
 }
 
 #endif
index 3d4a48070416ac13b771192a419bb80903b2910f..260c76acf74f9a33669359a43dacf0f540ae15b3 100755 (executable)
@@ -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
index 44759de7e2c3de97e820cc3bb351b8b68cb89fad..ab1d7011933b550ad6a21196800674c4c9f4b701 100755 (executable)
@@ -12,6 +12,8 @@
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Tools.h>
 
+#include <ModelGeomAlgo_Shape.h>
+
 #include <GeomAPI_ShapeIterator.h>
 
 #include <GeomAlgoAPI_ShapeTools.h>
@@ -176,7 +178,7 @@ namespace ModelGeomAlgo_Point2D {
     GeomShapePtr aFeatureShape;
     {
       std::set<ResultPtr> 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<ResultPtr> 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<GeomDataAPI_Point2D> > anAttributes;
-          //anAttributes.push_back(anAttribute);
-          //thePointToAttributeOrObject.insert(aProjectedPoint, anAttributes);
-
           std::list<std::shared_ptr<GeomDataAPI_Point2D> > anAttributes;
           std::list<std::shared_ptr<ModelAPI_Object> > 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 (file)
index 0000000..fb97aec
--- /dev/null
@@ -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 <GeomAPI_Shape.h>
+
+#include "ModelGeomAlgo_Shape.h"
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
+
+
+#ifdef WIN32
+#pragma warning(disable : 4996) // for sprintf
+#endif
+
+namespace ModelGeomAlgo_Shape
+{
+  void shapesOfType(const FeaturePtr& theFeature,
+                    const GeomAPI_Shape::ShapeType& theType,
+                    std::set<ResultPtr>& theShapeResults)
+  {
+    theShapeResults.clear();
+    std::list<ResultPtr> aResults = theFeature->results();
+    std::list<ResultPtr>::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 (file)
index 0000000..847b01b
--- /dev/null
@@ -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 <set>
+
+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<ModelAPI_Feature>& theFeature,
+                              const GeomAPI_Shape::ShapeType& theType,
+                              std::set<std::shared_ptr<ModelAPI_Result> >& theShapeResults);
+}
+
+#endif
index 5c7343cdf4909fde2b67d30c55cd07e167642db7..cdf698b7af061cae5d199d0d3a82098495cd93cb 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Tools.h>
index 7dd3e36385c7551ec1a70d349e63abf6282cbc01..c42e163b84f8c9331a28347fc890ee8f5b4067fc 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Tools.h>
index d08ccb44dfa7f6d09443c529ce2bb28014ef1569..bdbae89880150f89b0319874da495b755e2aa5c2 100755 (executable)
@@ -10,6 +10,7 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <GeomAPI_PlanarEdges.h>
 
 #include <Events_InfoMessage.h>
index ef8fa81fb4307999b8086eec468719996af2cc19..b10b335f1ca5f0411f1907ba5ef3dfe1bd72abad 100644 (file)
@@ -20,6 +20,7 @@
 #include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Events.h>
+#include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Tools.h>
 
index fc8700134024d597d5fd5ad4e3552b709a792c9b..b539c6ad47d1a07146495df2a0dd525cf175aca6 100755 (executable)
@@ -11,6 +11,7 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <GeomAPI_PlanarEdges.h>
 
 #include <Events_InfoMessage.h>
index e415933371b447a04b8bd58e0ba4fb38cd5b57fd..ec18af32f5c84dc765f22f7302d21032084ab2bb 100755 (executable)
@@ -27,6 +27,7 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Tools.h>
 
index d93b666ca483dbdd038b84938b5e40b1a89302b6..f2808b3ad2f929397e103f76106c99bd8ee8cc1a 100644 (file)
@@ -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<ModuleBase_ViewerPrs>& 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<int> 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<ModelAPI_AttributeReference> aRefSelectedAttr =
+                          std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
+                          feature()->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
+  std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
+                          std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
+                          feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
+  aRefSelectedAttr->setValue(aRefPreviewAttr->value());
+
+  std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
+                          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                          feature()->data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
+  std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
+                          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                          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<ModelAPI_AttributeReference> aRef =
                           std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
-                          feature()->data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
+                          feature()->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
   aRef->setValue(anObject);
 
   std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
                   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                  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<ModuleBase_ViewerPrsPtr> PartSet_WidgetFeaturePointSelector::getAttributeS
   return QList<ModuleBase_ViewerPrsPtr>();
 }
 
-//********************************************************************
-void PartSet_WidgetFeaturePointSelector::updateSelectionName()
-{
-  if (myBaseSelected)
-    ModuleBase_WidgetShapeSelector::updateSelectionName();
-}
-
 //********************************************************************
 bool PartSet_WidgetFeaturePointSelector::setSelection(
                                           QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
index 56c5105bbf0783e2617b18004b2c815b8096c743..96d559d0c6f4455d5cf9b325ea507aca1c071174 100644 (file)
@@ -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<ModuleBase_ViewerPrs>& 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<std::shared_ptr<ModuleBase_ViewerPrs>>& 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<ModuleBase_ViewerPrs>& thePreSelected);
   virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& 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<std::shared_ptr<ModuleBase_ViewerPrs>> 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
index b0e41e4f12abdd87875542e32bb014df8ab0210e..24dd2cad09e5bbcf18986b35d5794239c50abad0 100755 (executable)
@@ -20,6 +20,7 @@
 
 #include <GeomAlgoAPI_ShapeTools.h>
 #include <ModelGeomAlgo_Point2D.h>
+#include <ModelGeomAlgo_Shape.h>
 
 #include <ModelGeomAlgo_Point2D.h>
 
@@ -230,7 +231,7 @@ void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject
   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
   // edges on feature
   std::set<ResultPtr> 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();
 
index d9fff77cebdb054398ca78d6a3ba6589f84605ea..11c22f0ae8764b55ca27984a83c510e72e76e24d 100644 (file)
@@ -490,9 +490,9 @@ std::shared_ptr<ModelHighAPI_Interface> SketchAPI_Sketch::addTrim(
 {
   std::shared_ptr<ModelAPI_Feature> 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<GeomDataAPI_Point2D>(anAttribute);
     fillAttribute(thePositionPoint, aPointAttr);
index 87ef7b27a0dbf1e1e7148928fde3c77ef57adf85..80df2df05e9bcd9561e1f79b3ad895fec25c934c 100644 (file)
@@ -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",
index 7373e34af0a530b7e28edda53149fe46d0e671e0..6e2fab3ed4e30e25458860da790153f507735716 100644 (file)
@@ -12,6 +12,7 @@
 #include <GeomAPI_XY.h>
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
 
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeString.h>
@@ -23,6 +24,8 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_AttributeDouble.h>
 
+#include <ModelGeomAlgo_Shape.h>
+
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_ConstraintMiddle.h>
 #include <SketchPlugin_Circle.h>
@@ -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<GeomAPI_Pnt>& aStartPoint,
+void SketchPlugin_Trim::findShapePoints(const std::string& theObjectAttributeId,
+                                        const std::string& thePointAttributeId,
+                                        std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
                                         std::shared_ptr<GeomAPI_Pnt>& aLastPoint)
 {
   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
-                                            data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
+                                            data()->attribute(theObjectAttributeId));
   ObjectPtr aBaseObject = aBaseObjectAttr->value();
 
   AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                                                            data()->attribute(ENTITY_POINT()));
+                                              data()->attribute(thePointAttributeId));
   std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
   std::shared_ptr<GeomAPI_Pnt> 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<GeomShapePtr>& aShapes = myCashedShapes[aBaseObject];
   if (!aShapes.empty()) {
@@ -116,10 +132,10 @@ std::shared_ptr<GeomAPI_Pnt2d> SketchPlugin_Trim::convertPoint(
   std::shared_ptr<GeomAPI_Pnt2d> aPoint;
 
   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
-                                            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<GeomAPI_Pnt2d> 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<GeomAPI_Pln> 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<ModelAPI_AttributeReference>(
-                                            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<GeomAPI_Pnt> aStartShapePoint, aLastShapePoint;
-  findShapePoints(aStartShapePoint, aLastShapePoint);
+  findShapePoints(SELECTED_OBJECT(), SELECTED_POINT(), aStartShapePoint, aLastShapePoint);
   std::shared_ptr<GeomAPI_Pnt2d> aStartShapePoint2d = convertPoint(aStartShapePoint);
 
   std::shared_ptr<GeomAPI_Pnt2d> 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<ModelAPI_AttributeReference>(
+                     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<AttributePoint2DPtr>::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<ModelAPI_AttributeReference>(
-                                           data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
-  ObjectPtr aBaseObject = aBaseObjectAttr->value();
-  if (!aBaseObject.get())
+
+  std::list<std::shared_ptr<GeomAPI_Shape> > 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<int> 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<ModelAPI_AttributeReference>(
+                                                       data()->attribute(theObjectAttributeId));
+  ObjectPtr aBaseObject = anObjectAttr->value();
+  if (!aBaseObject.get())
+    return aBaseShape;
 
   // point on feature
   AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                                           data()->attribute(ENTITY_POINT()));
+                                           data()->attribute(thePointAttributeId));
   std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
   std::shared_ptr<GeomAPI_Pnt> 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<GeomShapePtr>& 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<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
-            aBaseFeature->data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
-
-    bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
-    std::vector<int> 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<FeaturePtr>& theFeaturesToDelete
 
   // Check the base objects are initialized.
   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
-                                            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<GeomAPI_Pnt2d>& theStartS
 {
   // Check the base objects are initialized.
   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
-                                            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<GeomAPI_Pnt2d>& 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<GeomDataAPI_Point2D>
@@ -646,7 +687,7 @@ void SketchPlugin_Trim::trimArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartSh
 {
   // Check the base objects are initialized.
   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
-                                            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<GeomAPI_Pnt2d>& t
 {
   // Check the base objects are initialized.
   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
-                                            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<ModelAPI_Result> 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<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
+                std::map<ObjectPtr, PointToRefsMap>& theObjectToPoints)
 {
   PointToRefsMap aPointsInfo;
 
@@ -1034,7 +1072,7 @@ void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject)
   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
   std::set<ResultPtr> 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<ModelAPI_Data> aData = aSketch->data();
+    //SketchPlugin_Sketch* aSketch = sketch();
+    std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
     std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
         aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
     std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
@@ -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<FeaturePtr> 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<FeaturePtr> aFeatures;
+    CompositeFeaturePtr aSketchComposite =
+                         std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(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<ModelAPI_AttributeReference>(
-                                             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<GeomDataAPI_Point2D>(
-                                               data()->attribute(ENTITY_POINT()));
-      std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
-      std::shared_ptr<GeomAPI_Pnt> anAttributePnt = sketch()->to3D(anAttributePnt2d->x(),
-                                                                   anAttributePnt2d->y());
-
-      if (myCashedShapes.find(aBaseObject) == myCashedShapes.end())
-        fillObjectShapes(aBaseObject);
-
-      const std::set<GeomShapePtr>& 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;
 }
index 9f3702f84be8e4314f8a5e99c17fbf837fe45265..6b95dd51bf3c2202cbe0adc27d063bfb8a43ec4f 100644 (file)
@@ -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::shared_ptr<GeomAPI_Pnt>,
+                   std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
+                             std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
+
+  static void fillObjectShapes(const ObjectPtr& theObject,
+                   ObjectPtr& theSketch,
+                   std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
+                   std::map<ObjectPtr, PointToRefsMap>& 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<ModelAPI_Feature>& theFeature);
 
 private:
-  bool useGraphicIntersection() const;
-
-  void fillObjectShapes(const ObjectPtr& theObject);
-
-  void findShapePoints(std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
+  void findShapePoints(const std::string& theObjectAttributeId,
+                       const std::string& thePointAttributeId,
+                       std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
                        std::shared_ptr<GeomAPI_Pnt>& aLastPoint);
 
   std::shared_ptr<GeomAPI_Pnt2d> convertPoint(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
@@ -249,10 +269,6 @@ private:
 private:
   std::map<ObjectPtr, std::set<GeomShapePtr> > myCashedShapes;
 
-  typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
-                   std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
-                             std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
-
   std::map<ObjectPtr, PointToRefsMap> myObjectToPoints;
 };
 
index d42c783606ae58dc8d45bc5f5255c60d55d4c5a0..cb4b746b6de81389b3a75f4d5afef7170952ebf1 100755 (executable)
@@ -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 <ModelAPI_ResultConstruction.h>
 
 #include <ModelGeomAlgo_Point2D.h>
+#include <ModelGeomAlgo_Shape.h>
 
 #include <GeomAPI_Circ.h>
 #include <GeomAPI_Lin.h>
@@ -820,7 +822,7 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
       aKind == SketchPlugin_Circle::ID()) {
 
     std::set<ResultPtr> 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<std::string>& 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<ModelAPI_AttributeReference>(theAttribute);
+
+  std::shared_ptr<SketchPlugin_Feature> aTrimFeature =
+                 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
+
+  ObjectPtr aBaseObject = aBaseObjectAttr->value();
+  if (!aBaseObject) {
+    AttributePtr aPreviewAttr = aTrimFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT());
+    aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(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<GeomDataAPI_Point2D>(
+                       aTrimFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
+
+  SketchPlugin_Sketch* aSketch = aTrimFeature->sketch();
+
+  std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
+  std::shared_ptr<GeomAPI_Pnt> anAttributePnt = aSketch->to3D(anAttributePnt2d->x(),
+                                                              anAttributePnt2d->y());
+
+  std::map<ObjectPtr, std::set<GeomShapePtr> > aCashedShapes;
+  std::map<ObjectPtr, std::map<std::shared_ptr<GeomAPI_Pnt>,
+           std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
+                     std::list<std::shared_ptr<ModelAPI_Object> > > > > anObjectToPoints;
+  SketchPlugin_Trim::fillObjectShapes(aBaseObject, aSketch->data()->owner(),
+                                      aCashedShapes, anObjectToPoints);
+  const std::set<GeomShapePtr>& aShapes = aCashedShapes[aBaseObject];
+
+  return aShapes.size() > 1;
+}
+
 bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
                                                const std::list<std::string>& theArguments,
                                                Events_InfoMessage& theError) const
index 70120d614a640331a6f65fc1800d725591c2d710..aaae2d95783e2bade6ab4bc715b58b6ab4979e03 100644 (file)
@@ -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<std::string>& theArguments,
+                       Events_InfoMessage& theError) const;
+};
+
 /**\class SketchPlugin_IntersectionValidator
  * \ingroup Validators
  * \brief Validator for the attribute to be intersected with the sketch plane.
index ab023e2fa487a18ec9b418c331deca0c85aca68b..44f52eefb12c14240b4194801bb66f704fbc6ccd 100644 (file)
@@ -86,7 +86,7 @@
         <toolbox id="ArcType">
           <box id="CenterStartEnd" title="Center and two points" icon="icons/Sketch/arc_base_32x32.png">
             <sketch-2dpoint_selector id="ArcCenter" accept_expressions="0" title="Center" tooltip="Center of a circle"
-                                     enable_value="enable_by_preferences" />
+                                     enable_value="enable_by_preferences" reference_attribute="ArcCenterRef" />
             <!--reference_attribute="ArcCenterRef" />-->
             <sketch-2dpoint_selector id="ArcStartPoint" accept_expressions="0" title="Start point" tooltip="Start point"
                                      enable_value="enable_by_preferences"/>
                tooltip="Trim selected segment arc or circle on intersection points nearest to the graphic selection"
                icon="icons/Sketch/trim.png">
         <sketch_feature_point_selector
-            id="BaseObject"
+            id="SelectedObject"
             label="Split feature"
             tooltip="Select feature for split"
             shape_types="edge"
             use_external="false"
             use_graphic_intersection="true">
-          <!--<validator id="SketchPlugin_SplitValidator" parameters="use_graphic_intersection"/> -->
+          <validator id="SketchPlugin_TrimValidator"/>
         </sketch_feature_point_selector>
         <validator id="PartSet_SplitSelection"/>
       </feature>
index e16cccf831651b9cf03b2a8702180d17c5a4bb71..dd9f98f3c6a340fe3b8f340e9bb0dc48d9eee7ba 100644 (file)
@@ -16,6 +16,7 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultConstruction.h>
 
 #include <AIS_InteractiveContext.hxx>
index fa48ac096d22facd30d443615e2233274e4ae810..bbf1f04206b50f0e873058fff27b4dc921b5325c 100755 (executable)
@@ -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");
       }