]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom.git into BR_PYTHON_PLUGIN
authorSergey BELASH <belash.sergey@opencascade.com>
Wed, 29 Oct 2014 16:13:17 +0000 (19:13 +0300)
committerSergey BELASH <belash.sergey@opencascade.com>
Wed, 29 Oct 2014 16:13:17 +0000 (19:13 +0300)
Conflicts:
linux_env.sh
src/FeaturesPlugin/CMakeLists.txt
src/ModelAPI/ModelAPI.i

222 files changed:
build_Salome740_deb.bat
env_Salome.bat
linux_env.sh
salomeRun.bat
salome_run.sh
src/Config/Config_FeatureReader.cpp
src/Config/Config_Keywords.h
src/Config/Config_Prop.cpp
src/Config/Config_Prop.h
src/Config/Config_PropManager.cpp
src/Config/Config_PropManager.h
src/ConstructionPlugin/Test/TestPointName.py
src/ConstructionPlugin/plugin-Construction.xml
src/ExchangePlugin/CMakeLists.txt
src/ExchangePlugin/ExchangePlugin_ImportFeature.h
src/ExchangePlugin/ExchangePlugin_Plugin.cpp
src/ExchangePlugin/ExchangePlugin_Validators.cpp
src/ExchangePlugin/ExchangePlugin_Validators.h
src/ExchangePlugin/plugin-Exchange.xml
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.h
src/FeaturesPlugin/FeaturesPlugin_Group.cpp [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_Group.h [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/boolean_widget.xml
src/FeaturesPlugin/extrusion_widget.xml
src/FeaturesPlugin/group_widget.xml [new file with mode: 0644]
src/FeaturesPlugin/plugin-Features.xml
src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/GeomAPI/GeomAPI_DataMapOfShapeShape.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_DataMapOfShapeShape.h [new file with mode: 0644]
src/GeomAPI/GeomAPI_PlanarEdges.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_PlanarEdges.h [new file with mode: 0644]
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.h [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.h
src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.h
src/GeomValidators/GeomValidators_Positive.h
src/Model/CMakeLists.txt
src/Model/Model_AttributeRefList.cpp
src/Model/Model_AttributeRefList.h
src/Model/Model_AttributeReference.cpp
src/Model/Model_AttributeReference.h
src/Model/Model_AttributeSelection.cpp [new file with mode: 0644]
src/Model/Model_AttributeSelection.h [new file with mode: 0644]
src/Model/Model_AttributeSelectionList.cpp [new file with mode: 0644]
src/Model/Model_AttributeSelectionList.h [new file with mode: 0644]
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/Model/Model_ResultConstruction.cpp
src/Model/Model_ResultPart.cpp
src/Model/Model_Session.cpp
src/Model/Model_Update.cpp
src/Model/Model_Validator.cpp
src/Model/Model_Validator.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_Attribute.h
src/ModelAPI/ModelAPI_AttributeBoolean.h
src/ModelAPI/ModelAPI_AttributeDocRef.h
src/ModelAPI/ModelAPI_AttributeRefAttr.h
src/ModelAPI/ModelAPI_AttributeRefList.h
src/ModelAPI/ModelAPI_AttributeReference.h
src/ModelAPI/ModelAPI_AttributeSelection.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_AttributeSelectionList.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_AttributeValidator.h
src/ModelAPI/ModelAPI_CompositeFeature.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Data.h
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Feature.h
src/ModelAPI/ModelAPI_Object.h
src/ModelAPI/ModelAPI_Result.h
src/ModelAPI/ModelAPI_ResultBody.h
src/ModelAPI/ModelAPI_Session.cpp
src/ModelAPI/ModelAPI_Validator.h
src/ModelAPI/Test/TestUndoRedo.py
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_Definitions.h
src/ModuleBase/ModuleBase_IModule.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_IOperation.cpp [deleted file]
src/ModuleBase/ModuleBase_IOperation.h [deleted file]
src/ModuleBase/ModuleBase_IPropertyPanel.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_ISelection.h
src/ModuleBase/ModuleBase_IViewer.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_IWorkshop.h
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/ModuleBase/ModuleBase_ResultPrs.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_ResultPrs.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_Tools.h
src/ModuleBase/ModuleBase_ViewerFilters.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_ViewerFilters.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetBoolValue.cpp
src/ModuleBase/ModuleBase_WidgetChoice.cpp
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/ModuleBase/ModuleBase_WidgetEditor.cpp
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h
src/ModuleBase/ModuleBase_WidgetFeature.cpp
src/ModuleBase/ModuleBase_WidgetFileSelector.cpp
src/ModuleBase/ModuleBase_WidgetFileSelector.h
src/ModuleBase/ModuleBase_WidgetLineEdit.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetLineEdit.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetMultiSelector.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetPoint2D.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/NewGeom/CMakeLists.txt
src/NewGeom/NewGeom_DataModel.cpp
src/NewGeom/NewGeom_Module.cpp
src/NewGeom/NewGeom_Module.h
src/NewGeom/NewGeom_SalomeViewer.cpp
src/NewGeom/NewGeom_SalomeViewer.h
src/NewGeom/resources/SalomeApp.xml
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Listener.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationFeatureBase.cpp
src/PartSet/PartSet_OperationFeatureBase.h
src/PartSet/PartSet_OperationFeatureCreate.cpp
src/PartSet/PartSet_OperationFeatureCreate.h
src/PartSet/PartSet_OperationFeatureEdit.cpp
src/PartSet/PartSet_OperationFeatureEdit.h
src/PartSet/PartSet_OperationFeatureEditMulti.cpp
src/PartSet/PartSet_OperationFeatureEditMulti.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_OperationSketchBase.cpp
src/PartSet/PartSet_OperationSketchBase.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_Validators.cpp
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/fixed.png [new file with mode: 0644]
src/PartSet/icons/shape_group.png [new file with mode: 0644]
src/PartSetPlugin/PartSetPlugin_Duplicate.cpp
src/PartSetPlugin/PartSetPlugin_Part.cpp
src/PartSetPlugin/PartSetPlugin_Remove.cpp
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Arc.h
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Circle.h
src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h
src/SketchPlugin/SketchPlugin_ConstraintDistance.h
src/SketchPlugin/SketchPlugin_ConstraintLength.h
src/SketchPlugin/SketchPlugin_ConstraintParallel.h
src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h
src/SketchPlugin/SketchPlugin_ConstraintRadius.h
src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintRigid.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Feature.cpp
src/SketchPlugin/SketchPlugin_Feature.h
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Line.h
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Point.cpp
src/SketchPlugin/SketchPlugin_Point.h
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/Test/TestConstraintConcidence.py
src/SketchPlugin/Test/TestConstraintDistance.py
src/SketchPlugin/Test/TestConstraintLength.py
src/SketchPlugin/Test/TestConstraintParallel.py
src/SketchPlugin/Test/TestConstraintPerpendicular.py
src/SketchPlugin/Test/TestConstraintRadius.py
src/SketchPlugin/Test/TestSketchArcCircle.py
src/SketchPlugin/Test/TestSketchPointLine.py
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_ConstraintGroup.cpp
src/SketchSolver/SketchSolver_ConstraintGroup.h
src/SketchSolver/SketchSolver_ConstraintManager.cpp
src/SketchSolver/SketchSolver_ConstraintManager.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_Command.cpp
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_ModuleConnector.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h
src/XGUI/XGUI_Preferences.cpp
src/XGUI/XGUI_Preferences.h
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_PropertyPanel.h
src/XGUI/XGUI_RubberBand.cpp
src/XGUI/XGUI_SalomeConnector.h
src/XGUI/XGUI_SalomeViewer.h [deleted file]
src/XGUI/XGUI_Selection.cpp
src/XGUI/XGUI_Selection.h
src/XGUI/XGUI_ViewWindow.cpp
src/XGUI/XGUI_Viewer.cpp
src/XGUI/XGUI_ViewerProxy.cpp
src/XGUI/XGUI_ViewerProxy.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 130599b4faf20c3c5eadb20bff17ef0c308b2c42..77a58f1ed5f8af67b747262ac88a461dfb0d84db 100644 (file)
@@ -14,6 +14,6 @@ call %SRC_DIR%\env_Salome.bat d
 mkdir %ROOT_DIR%\build
 cd %ROOT_DIR%\build
 
-cmake %SRC_DIR% -G "Visual Studio 10" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
+cmake %SRC_DIR% -G "Visual Studio 10" -DPYTHON_EXECUTABLE=%PYTHONHOME%\python_d.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
 
 start "" %MSVC_EXE% NewGEOM.sln
index 9c4291781a7cbb94c423c41e36b77b7a59abb45e..98d24b244d4e0ef6de974f96f2d881e4989535aa 100644 (file)
@@ -20,8 +20,8 @@ if "%SALOME_ROOT_DIR%" == "" (
 
 if "%SOLVESPACE_ROOT_DIR%" == "" (
   SET SOLVESPACE_ROOT_DIR=%ROOT_DIR%\products\solvespace-2.0
-  SET PATH=%SOLVESPACE_ROOT_DIR%\lib;"%PATH%"
 )
+SET PATH=%SOLVESPACE_ROOT_DIR%\lib;%PATH%
 
 cd %SALOME_ROOT_DIR%\WORK
 call set_env.bat %1
index becdc6db68f19fd2b113d7cb19a84b4576338315..7992a8794b3c47d58e37485238fd146fe3aa90c7 100644 (file)
@@ -35,9 +35,10 @@ export PATH=${CASROOT}:${PATH}
 ##
 
 #------ NewGEOM ------
-export NEW_GEOM_ROOT_DIR=${ROOT_DIR}/install
-export PATH=${NEW_GEOM_ROOT_DIR}/bin:${NEW_GEOM_ROOT_DIR}/plugins:${PATH}
-export PYTHONPATH=${NEW_GEOM_ROOT_DIR}/swig:${NEW_GEOM_ROOT_DIR}/plugins:${PYTHONPATH}
-export LD_LIBRARY_PATH=${NEW_GEOM_ROOT_DIR}/bin:${NEW_GEOM_ROOT_DIR}/swig:${NEW_GEOM_ROOT_DIR}/plugins:${LD_LIBRARY_PATH}
-export NEW_GEOM_CONFIG_FILE=${NEW_GEOM_ROOT_DIR}/plugins
-export NewGeomResources=${NEW_GEOM_ROOT_DIR}/resources
+export NEWGEOM_ROOT_DIR=${ROOT_DIR}/install
+export PATH=${NEWGEOM_ROOT_DIR}/bin:${NEWGEOM_ROOT_DIR}/plugins:${PATH}
+export PYTHONPATH=${NEWGEOM_ROOT_DIR}/swig:${NEW_GEOM_ROOT_DIR}/plugins:${PYTHONPATH}
+export LD_LIBRARY_PATH=${NEWGEOM_ROOT_DIR}/bin:${NEWGEOM_ROOT_DIR}/swig:${NEWGEOM_ROOT_DIR}/plugins:${LD_LIBRARY_PATH}
+export NEW_GEOM_CONFIG_FILE=${NEWGEOM_ROOT_DIR}/plugins
+export NewGeomResources=${NEWGEOM_ROOT_DIR}/resources
+
index a2fa7d3dd0f78fb47a8a02135df7c9568af768db..e7d3de66c417e0dd14896004313a1a431f69fb8a 100644 (file)
@@ -2,4 +2,7 @@
 
 call env_Salome.bat
 
-SuitApp.exe LightApp --modules=NewGeom
+@SET NewGEOM_ROOT_DIR=%ROOT_DIR%\install
+@SET SalomeAppConfig=%ROOT_DIR%\install\share\salome\resources\newgeom;%GUI_ROOT_DIR%\share\salome\resources\gui
+
+start %PYTHONBIN% "%KERNEL_ROOT_DIR%\bin\salome\envSalome.py" "%PYTHONBIN%" "%KERNEL_ROOT_DIR%\bin\salome\runSalome.py" %*
index 5ef39f4abd64642495e48aeb6b3f9b67ed30985c..78609177af1cff3586a7f2959390aced63849001 100755 (executable)
@@ -7,6 +7,7 @@ source ${ROOT_DIR}/sources/linux_env.sh
 
 # Correcting path which defined with error
 export LD_LIBRARY_PATH=${KERNEL_ROOT_DIR}/lib/salome:${LD_LIBRARY_PATH}
-export LightAppConfig=${ROOT_DIR}/install/share/salome/resources/newgeom:${GUI_ROOT_DIR}/share/salome/resources/gui
+export SalomeAppConfig=${ROOT_DIR}/install/share/salome/resources/newgeom:${GUI_ROOT_DIR}/share/salome/resources/gui
 
-SUITApp LightApp --modules=NewGeom
\ No newline at end of file
+${PYTHONBIN} "${KERNEL_ROOT_DIR}/bin/salome/envSalome.py"
+${PYTHONBIN} "${KERNEL_ROOT_DIR}/bin/salome/runSalome.py"
index 1f7a65b2dcbc366f278e94c9c37b4d09da2d57ae..5c4ffba8e2f0650a41d6995b9b223073ace77022 100644 (file)
@@ -92,7 +92,7 @@ void Config_FeatureReader::fillFeature(xmlNodePtr theNode,
 
 bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode)
 {
-  std::string prop = getProperty(theNode, FEATURE_INTERNAL);
+  std::string prop = getProperty(theNode, ATTRIBUTE_INTERNAL);
   std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
   if (prop.empty() || prop == "false" || prop == "0") {
     return false;
index 8f0fda2e19da13441d7b79493c0f884ab2d82a62..46338306b780427c9477f28978e747a0769b3621 100644 (file)
@@ -20,6 +20,8 @@ const static char* NODE_VALIDATOR = "validator";
 //Widgets
 const static char* WDG_DOUBLEVALUE = "doublevalue";
 const static char* WDG_BOOLVALUE = "boolvalue";
+const static char* WDG_STRINGVALUE = "stringvalue";
+const static char* WDG_MULTISELECTOR = "multi_selector";
 //Widget containers
 const static char* WDG_INFO = "label";
 const static char* WDG_GROUP = "groupbox";
@@ -48,13 +50,16 @@ const static char* FEATURE_ICON = "icon";
 const static char* FEATURE_TEXT = "title";
 const static char* FEATURE_KEYSEQUENCE = "keysequence";
 const static char* FEATURE_NESTED = "nested";
-const static char* FEATURE_INTERNAL = "internal";
-const static char* FEATURE_OBLIGATORY = "obligatory";
+
+const static char* ATTRIBUTE_INTERNAL = "internal";
+const static char* ATTRIBUTE_OBLIGATORY = "obligatory";
+const static char* ATTRIBUTE_CONCEALMENT = "concealment";
 // TODO: Rename
 const static char* PREVIOUS_FEATURE_PARAM = "previous_feature_param";
 const static char* ANY_WDG_TOOLTIP = FEATURE_TOOLTIP;
 const static char* ANY_WDG_ICON = FEATURE_ICON;
 const static char* ANY_WDG_LABEL = "label";
+const static char* ANY_WDG_DEFAULT = "default";
 
 const static char* SOURCE_FILE = "path";
 const static char* VALIDATOR_PARAMETERS = "parameters";
@@ -65,7 +70,6 @@ const static char* INFO_WDG_TOOLTIP = FEATURE_TOOLTIP;
 const static char* DOUBLE_WDG_MIN = "min";
 const static char* DOUBLE_WDG_MAX = "max";
 const static char* DOUBLE_WDG_STEP = "step";
-const static char* DOUBLE_WDG_DEFAULT = "default";
 const static char* DOUBLE_WDG_DEFAULT_COMPUTED = "computed";
 
 //toolbox/switch properties
index 7904021b62b22ec9bf520ecf554f51e3bea16900..6de7627b04eb94c056b0ed18b42c098900eebc82 100644 (file)
@@ -16,3 +16,10 @@ void Config_Prop::setValue(const std::string& theValue)
       new Events_Message(aChangedEvent, this)));
   }
 }
+
+void Config_Prop::setDefaultValue(const std::string& theValue)
+{
+  if (theValue != myDefaultValue) {
+    myDefaultValue = theValue;
+  }
+}
index f4ea0138b802d6173fbd213ae8998b83aa8c4036..4430bade8b68c4c6f655c2201a37c23f640e57b0 100644 (file)
@@ -45,16 +45,17 @@ class Config_Prop
    * \param theSection - name of section (domain of using) of the property.
    * \param theName - name (title) of the value.
    * \param theType - type of the value.
-   * \param theValue - initial value of the property.
+   * \param theDefaultValue - default value of the property. This is an initial property value
    */
   Config_Prop(const std::string& theSection, const std::string& theName,
-              const std::string& theTitle, PropType theType, const std::string& theValue)
+              const std::string& theTitle, PropType theType, const std::string& theDefaultValue)
   {
     mySection = theSection;
     myName = theName;
     myTitle = theTitle;
     myType = theType;
-    myValue = theValue;
+    myValue = theDefaultValue;
+    myDefaultValue = theDefaultValue;
   }
 
   std::string section() const
@@ -90,6 +91,13 @@ class Config_Prop
   }
 
   CONFIG_EXPORT void setValue(const std::string& theValue);
+  
+  std::string defaultValue() const
+  {
+    return myDefaultValue;
+  }
+
+  CONFIG_EXPORT void setDefaultValue(const std::string& theValue);
 
   bool operator==(const Config_Prop* theProp) const
   {
@@ -102,6 +110,7 @@ class Config_Prop
   std::string myTitle;
   PropType myType;
   std::string myValue;
+  std::string myDefaultValue;
 };
 
 typedef std::list<Config_Prop*> Config_Properties;
index c296cc864772f6b0c66a95cc8bd7b8d07f47898d..e6f800c27f649ba7c91b23f5c4ac701ff5a79e59 100644 (file)
@@ -10,22 +10,29 @@ double stringToDouble(const std::string& theDouble);
 
 Config_Properties Config_PropManager::myProps;
 
-bool Config_PropManager::registerProp(const std::string& theSection, const std::string& theName,
-                                      const std::string& theTitle, Config_Prop::PropType theType,
-                                      const std::string& theValue)
+Config_Prop* Config_PropManager::registerProp(const std::string& theSection, const std::string& theName,
+                                              const std::string& theTitle, Config_Prop::PropType theType,
+                                              const std::string& theDefaultValue)
 {
   Config_Prop* aProp = findProp(theSection, theName);
+
   if (aProp) {
+    if (aProp->value() == "") {
+      aProp->setValue(theDefaultValue);
+    }
+    if (aProp->defaultValue() == "") {
+      aProp->setDefaultValue(theDefaultValue);
+    }
     if (aProp->type() == Config_Prop::Disabled) {
       aProp->setType(theType);
       aProp->setTitle(theTitle);
-      return true;
     }
-    return false;
   }
-  aProp = new Config_Prop(theSection, theName, theTitle, theType, theValue);
-  myProps.push_back(aProp);
-  return true;
+  else {
+    aProp = new Config_Prop(theSection, theName, theTitle, theType, theDefaultValue);
+    myProps.push_back(aProp);
+  }
+  return aProp;
 }
 
 Config_Prop* Config_PropManager::findProp(const std::string& theSection, const std::string& theName)
index 496cddd6dce8e9017b095168dca77639bb39fdec..444312ebd501fb9cbb77f60785007803c6d34a9c 100644 (file)
@@ -23,11 +23,11 @@ class Config_PropManager
    * \param theSection - name of section (domain of using) of the property.
    * \param theName - name (title) of the value.
    * \param theType - type of the value.
-   * \param theValue - initial value of the property
+   * \param theDefValue - default and initial value of the property
    * Returns True if the property succesfully registered
    */
-  CONFIG_EXPORT static bool registerProp(const std::string& theSection, const std::string& theName,
-    const std::string& theTitle, Config_Prop::PropType theType, const std::string& theValue);
+  CONFIG_EXPORT static Config_Prop* registerProp(const std::string& theSection, const std::string& theName,
+    const std::string& theTitle, Config_Prop::PropType theType, const std::string& theDefValue = "");
 
   CONFIG_EXPORT static Config_Prop* findProp(
     const std::string& theSection, const std::string& theName);
index 740bd52df948bef566b46c4c73af4f5cfc80a296..df76871f2d02cf6e0488d9e9df9c8fbbdea7a3f8 100644 (file)
@@ -6,10 +6,11 @@ aDoc = aSession.moduleDocument()
 aSession.startOperation()
 aFeature = aDoc.addFeature("Point")
 aFeatureData = aFeature.data()
+assert(aFeatureData is not None)
 aFeatureData.real("x").setValue(0.)
 aFeatureData.real("y").setValue(0.)
 aFeatureData.real("z").setValue(0.)
-aFeatureName = aFeatureData.name()
+aFeatureName = aFeature.name()
 aFeature.execute()
 aSession.finishOperation()
 
index 381a3e656f587e26e70adc2ccce395ff44fc1d49..217afb33e3865245144c31679a79a535bf2b32cb 100644 (file)
@@ -1,14 +1,27 @@
 <plugin>
   <workbench id="Construction">
     <group id="Basic">
-      <feature id="Point" title="Point" tooltip="Create a new point" icon=":icons/point.png">
-        <!-- validator id="test" parameters="x,y,z"/ -->
-        <source path="point_widget.xml"/>
+      <feature
+        id="Point"
+        title="Point"
+        tooltip="Create a new point"
+        icon=":icons/point.png">
+        <source path="point_widget.xml" />
       </feature>
-      <feature id="Axis" title="Axis" tooltip="Create a new axis" icon=":icons/axis.png" keysequence="" internal="true">
-        <!-- validator id="inside" parameters="a,b"/ --> 
-      </feature>
-      <feature id="Plane" title="Plane" tooltip="Create a new plane" icon=":icons/plane.png" keysequence="" internal="true"/>
+      <feature
+        id="Axis"
+        title="Axis"
+        tooltip="Create a new axis"
+        icon=":icons/axis.png"
+        keysequence=""
+        internal="true" />
+      <feature
+        id="Plane"
+        title="Plane"
+        tooltip="Create a new plane"
+        icon=":icons/plane.png"
+        keysequence=""
+        internal="true" />
     </group>
-</workbench>  
-</plugin>
+  </workbench>
+</plugin>
\ No newline at end of file
index ad3f24fdf9f15be9edb5ddef92e407c031a1a9a7..8200a6d93799cf1ffb92664fd0ce207de1224fce 100644 (file)
@@ -4,6 +4,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
                     ${PROJECT_SOURCE_DIR}/src/Config
                     ${PROJECT_SOURCE_DIR}/src/ModelAPI
                     ${PROJECT_SOURCE_DIR}/src/GeomAPI
+                    ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
                     ${CAS_INCLUDE_DIRS}
 ) 
 
index 3745d16607caaa0f0b9c7565538c6c4cf276921b..f5747807267792edae667eea97e399c0c32cc6b6 100644 (file)
@@ -57,7 +57,7 @@ class ExchangePlugin_ImportFeature : public ModelAPI_Feature
 
   EXCHANGEPLUGIN_EXPORT virtual bool isInHistory()
   {
-    return false;
+    return true;
   }
 
  protected:
index 3a4abd00bed00e7b23cb2079aaa74e37721acb6f..b37a0690623525edb7e7be443c9c5fa0c98c4ce6 100644 (file)
@@ -4,8 +4,10 @@
 
 #include <ExchangePlugin_Plugin.h>
 #include <ExchangePlugin_ImportFeature.h>
+#include <ExchangePlugin_Validators.h>
 
 #include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
 
 #include <boost/smart_ptr/shared_ptr.hpp>
 
@@ -17,7 +19,11 @@ static ExchangePlugin_Plugin* MY_EXCHANGE_INSTANCE = new ExchangePlugin_Plugin()
 ExchangePlugin_Plugin::ExchangePlugin_Plugin()
 {
   // register this plugin
-  ModelAPI_Session::get()->registerPlugin(this);
+  SessionPtr aSession = ModelAPI_Session::get();
+  aSession->registerPlugin(this);
+  ModelAPI_ValidatorsFactory* aFactory = aSession->validators();
+  aFactory->registerValidator("ExchangePlugin_ImportFormat",
+                              new ExchangePlugin_ImportFormatValidator);
 }
 
 FeaturePtr ExchangePlugin_Plugin::createFeature(string theFeatureID)
index f179e889bc0f7b632c7670555959636f208ab67f..7954c540be2e8a9c71230e78021b915c7b35a603 100644 (file)
@@ -6,16 +6,74 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_AttributeString.h>
 
 #include <list>
 #include <string>
+#include <algorithm>
 
+bool ExchangePlugin_ImportFormatValidator::parseFormats(const std::list<std::string>& theArguments,
+                                                        std::list<std::string>& outFormats)
+{
+  std::list<std::string>::const_iterator it = theArguments.begin();
+  bool result = true;
+  for (; it != theArguments.end(); ++it) {
+    std::string anArg = *it;
+    int aSepPos = anArg.find(":");
+    if (aSepPos == std::string::npos) {
+      result = false;
+      continue;
+    }
+    std::string aFormat = anArg.substr(0, aSepPos);
+    std::transform(aFormat.begin(), aFormat.end(), aFormat.begin(), toupper);
+    outFormats.push_back(aFormat);
+  }
+  return result;
+}
+
+bool ExchangePlugin_ImportFormatValidator::parsePlugins(const std::list<std::string>& theArguments,
+                                                        std::list<std::string>& outPlugins)
+{
+  std::list<std::string>::const_iterator it = theArguments.begin();
+  bool result = true;
+  for (; it != theArguments.end(); ++it) {
+    std::string anArg = *it;
+    int aSepPos = anArg.find(":");
+    if (aSepPos == std::string::npos) {
+      result = false;
+      continue;
+    }
+    outPlugins.push_back(anArg.substr(aSepPos + 1));
+  }
+  return result;
+}
 
-bool ExchangePlugin_ImportFormatValidator::isValid(
-  const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
+bool ExchangePlugin_ImportFormatValidator::isValid(const AttributePtr& theAttribute,
+                                                   const std::list<std::string>& theArguments) const
 {
   SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  if (theAttribute->isInitialized()) {
+    const AttributeStringPtr aStrAttr =
+        boost::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
+    if(!aStrAttr)
+      return false;
+    std::string aFileName = aStrAttr->value();
+    if (!aFileName.empty()) {
+      std::list<std::string> aFormats;
+      ExchangePlugin_ImportFormatValidator::parseFormats(theArguments, aFormats);
+      std::list<std::string>::const_iterator itFormats = aFormats.begin();
+      size_t aFileNameLen = aFileName.length();
+      std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper);
+      // Is file name ends with the format
+      for (; itFormats != aFormats.end(); ++itFormats) {
+        size_t aFormatBeginPos = aFileNameLen - (*itFormats).length();
+        if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) {
+          return true;
+        }
+      }
+    }
+  }
   return false;
 }
 
index 21d72765b0bce158c26a991448a79145a6151844..f390f57586309cfdf9353bd2d041688ec3956479 100644 (file)
 
 class ExchangePlugin_ImportFormatValidator : public ModelAPI_AttributeValidator
 {
+  /*
+   * Parses input arguments "BREP:BREPImport", "STEP:STEPImport"
+   * into list of file formats "BREP","STEP"
+   * and list of corresponding plugins: "BREPImport", "STEPImport"
+   */
+  static bool parseFormats(const std::list<std::string>& theArguments,
+                             std::list<std::string>& outFormats);
+  static bool parsePlugins(const std::list<std::string>& theArguments,
+                           std::list<std::string>& outPlugins);
  public:
-  virtual bool isValid(
-    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments) const;
+
+
 
 };
 
index a21500e42ef53bc20f61cbbf745696a2f66f54a5..7e1c7f1178f8e667e6037b9cf8f06c2a4ca03075 100644 (file)
@@ -1,20 +1,14 @@
 <plugin>
   <workbench id="Features" document="Part">
     <group id="Exchange">
-      <feature
-        id="Import"
-        title="Import"
-        tooltip="Import shape"
-        icon=":icons/import.png">
+      <feature id="Import" title="Import" tooltip="Import shape" icon=":icons/import.png">
         <file_selector
           id="import_file_selector"
           title="Import file"
-          path=""
-          formats="BREP,STEP" />
-        <!-- TODO: pass formats as validator 
-        <validator id="Format" parameters="BREP:BREPImport,STEP:STEPImport" /> 
-        -->
+          path="">
+          <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP:STEPImport" />
+        </file_selector>
       </feature>
     </group>
   </workbench>
-</plugin>
+</plugin>
\ No newline at end of file
index cfdbb28189202f52cd9b687ddf9a4aa66ddb9f14..a0886cbb16364a482cb4e6d544dab887deaa9362 100644 (file)
@@ -4,33 +4,36 @@ SET(PROJECT_HEADERS
     FeaturesPlugin.h
     FeaturesPlugin_Plugin.h
     FeaturesPlugin_Extrusion.h
-    FeaturesPlugin_Boolean.h
+       FeaturesPlugin_Boolean.h
+       FeaturesPlugin_Group.h
 )
 
 SET(PROJECT_SOURCES
     FeaturesPlugin_Plugin.cpp
     FeaturesPlugin_Extrusion.cpp
     FeaturesPlugin_Boolean.cpp
+    FeaturesPlugin_Group.cpp
 )
 
 SET(XML_RESOURCES
   plugin-Features.xml
   extrusion_widget.xml
   boolean_widget.xml
+  group_widget.xml
 )
 
 INCLUDE_DIRECTORIES(
   ../ModelAPI
   ../GeomAPI
   ../GeomAlgoAPI
+  ../Events
 )
 
 SET(PROJECT_LIBRARIES
+    Events
     ModelAPI 
     GeomAPI 
     GeomAlgoAPI
-    ${CAS_KERNEL}
-    ${CAS_SHAPE}
 )
 
 ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
index 295fb1c9de489e55cd14f0df7190b7c341e05625..eeafb1db61e0e7557ff59706166146f75c41b219 100644 (file)
@@ -9,12 +9,20 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeBoolean.h>
-
+#include <Events_Error.h>
 #include <GeomAlgoAPI_Extrusion.h>
 
 using namespace std;
+#define _LATERAL_TAG 1
+#define _FIRST_TAG 2
+#define _LAST_TAG 3
+#define EDGE 6
+#ifdef _DEBUG
+#include <iostream>
+#include <ostream>
+#endif
 
 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
 {
@@ -22,37 +30,108 @@ FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
 
 void FeaturesPlugin_Extrusion::initAttributes()
 {
-  data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeReference::type());
+  data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::type());
   data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
   data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
 }
 
 void FeaturesPlugin_Extrusion::execute()
 {
-  boost::shared_ptr<ModelAPI_AttributeReference> aFaceRef = boost::dynamic_pointer_cast<
-      ModelAPI_AttributeReference>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
+  boost::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = boost::dynamic_pointer_cast<
+    ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
   if (!aFaceRef)
     return;
-  boost::shared_ptr<GeomAPI_Shape> aFace;
-  boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = boost::dynamic_pointer_cast<
-      ModelAPI_ResultConstruction>(aFaceRef->value());
-  if (aConstr) {
-    aFace = aConstr->shape();
-  }
-  if (!aFace) {
-    // Check for body
-    boost::shared_ptr<ModelAPI_ResultBody> aBody = boost::dynamic_pointer_cast<
-        ModelAPI_ResultBody>(aFaceRef->value());
-    if (aBody) 
-      aFace = aBody->shape();
+
+  boost::shared_ptr<GeomAPI_Shape> aFace = 
+    boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
+  if (!aFace)
+    return;
+
+  boost::shared_ptr<GeomAPI_Shape> aContext;
+  ResultPtr aContextRes = aFaceRef->context();
+  if (aContextRes) {
+    if (aContextRes->groupName() == ModelAPI_ResultBody::group())
+      aContext = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
+    else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
+      aContext = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
   }
-  if (!aFace) 
+  if (!aContext) {
+    std::string aContextError = "The selection context is bad";
+    Events_Error::send(aContextError, this);
     return;
+  }
 
   double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
   if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
     aSize = -aSize;
-  boost::shared_ptr<ModelAPI_ResultBody> aResult = document()->createBody(data());
-  aResult->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize));
-  setResult(aResult);
+
+  boost::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
+  GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
+  if(!aFeature.isDone()) {
+    std::string aFeatureError = "Extrusion algorithm failed";  
+    Events_Error::send(aFeatureError, this);
+    return;
+  }
+
+  // Check if shape is valid
+  if (aFeature.shape()->isNull()) {
+    std::string aShapeError = "Resulting shape is Null";     
+    Events_Error::send(aShapeError, this);
+#ifdef _DEBUG
+    std::cerr << aShapeError << std::endl;
+#endif
+    return;
+  }
+  if(!aFeature.isValid()) {
+    std::string aFeatureError = "Warning: resulting shape is not valid";  
+    Events_Error::send(aFeatureError, this);
+    return;
+  }  
+  //LoadNamingDS
+  LoadNamingDS(aFeature, aResultBody, aFace, aContext);
+
+  setResult(aResultBody);
+}
+
+//============================================================================
+void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, 
+  boost::shared_ptr<ModelAPI_ResultBody> theResultBody, 
+  boost::shared_ptr<GeomAPI_Shape> theBasis,
+  boost::shared_ptr<GeomAPI_Shape> theContext)
+{  
+
+
+  //load result
+  if(theBasis->isEqual(theContext))
+    theResultBody->store(theFeature.shape());
+  else
+    theResultBody->storeGenerated(theContext, theFeature.shape()); 
+
+  GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
+  theFeature.mapOfShapes(*aSubShapes);
+
+    //Insert lateral face : Face from Edge
+  theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theFeature.shape(), EDGE,_LATERAL_TAG, *aSubShapes);
+
+  //Insert bottom face
+  boost::shared_ptr<GeomAPI_Shape> aBottomFace = theFeature.firstShape();  
+  if (!aBottomFace->isNull()) {
+       if (aSubShapes->isBound(aBottomFace)) {  
+               aBottomFace = aSubShapes->find(aBottomFace);            
+    }    
+    theResultBody->generated(aBottomFace, _FIRST_TAG);
+  }
+
+
+
+  //Insert top face
+  boost::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
+  if (!aTopFace->isNull()) {
+    if (aSubShapes->isBound(aTopFace)) {        
+      aTopFace = aSubShapes->find(aTopFace);   
+    }
+    theResultBody->generated(aTopFace, _LAST_TAG);
+  }
+
+  
 }
index 13a8c226e9ea2bc48ae7d6d936b6290fe656218e..c6c500fe211a9caaab4ddbd2f1b6852f9a81db32 100644 (file)
@@ -7,7 +7,9 @@
 
 #include "FeaturesPlugin.h"
 #include <ModelAPI_Feature.h>
-
+#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_Extrusion.h>
+#include <GeomAPI_Shape.h>
 class FeaturesPlugin_Extrusion : public ModelAPI_Feature
 {
  public:
@@ -51,6 +53,11 @@ class FeaturesPlugin_Extrusion : public ModelAPI_Feature
 
   /// Use plugin manager for features creation
   FeaturesPlugin_Extrusion();
+
+  /// Load Naming data structure of the feature to the document
+  void LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
+                       boost::shared_ptr<GeomAPI_Shape> theBasis,
+                       boost::shared_ptr<GeomAPI_Shape> theContext);
 };
 
 #endif
diff --git a/src/FeaturesPlugin/FeaturesPlugin_Group.cpp b/src/FeaturesPlugin/FeaturesPlugin_Group.cpp
new file mode 100644 (file)
index 0000000..dad22db
--- /dev/null
@@ -0,0 +1,34 @@
+// File:        FeaturesPlugin_Group.cpp
+// Created:     08 Oct 2014
+// Author:      Sergey BELASH
+
+#include "FeaturesPlugin_Group.h"
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
+
+using namespace std;
+
+FeaturesPlugin_Group::FeaturesPlugin_Group()
+{
+}
+
+void FeaturesPlugin_Group::initAttributes()
+{
+  //data()->addAttribute(FeaturesPlugin_Group::NAME_ID(), ModelAPI_AttributeString::type());
+  data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::type());
+}
+
+void FeaturesPlugin_Group::execute()
+{
+  //AttributeStringPtr aNameAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeString>(
+  //    data()->attribute(FeaturesPlugin_Group::NAME_ID()));
+  //if (!aNameAttr)
+  //  return;
+  //std::string aName = aNameAttr->value();
+  //data()->setName(aName);
+}
diff --git a/src/FeaturesPlugin/FeaturesPlugin_Group.h b/src/FeaturesPlugin/FeaturesPlugin_Group.h
new file mode 100644 (file)
index 0000000..23078ae
--- /dev/null
@@ -0,0 +1,52 @@
+// File:        FeaturesPlugin_Group.h
+// Created:     08 Oct 2014
+// Author:      Sergey BELASH
+
+#ifndef FEATURESPLUGIN_GROUP_H_
+#define FEATURESPLUGIN_GROUP_H_
+
+#include "FeaturesPlugin.h"
+#include <ModelAPI_Feature.h>
+#include <GeomAPI_Shape.h>
+
+class FeaturesPlugin_Group : public ModelAPI_Feature
+{
+ public:
+  /// Extrusion kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_GROUP_ID("Group");
+    return MY_GROUP_ID;
+  }
+  /// attribute name of group name
+  //inline static const std::string& NAME_ID()
+  //{
+  //  static const std::string MY_GROUP_NAME_ID("group_name");
+  //  return MY_GROUP_NAME_ID;
+  //}
+  /// attribute name of selected entities list
+  inline static const std::string& LIST_ID()
+  {
+    static const std::string MY_GROUP_LIST_ID("group_list");
+    return MY_GROUP_LIST_ID;
+  }
+
+  /// Returns the kind of a feature
+  FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = FeaturesPlugin_Group::ID();
+    return MY_KIND;
+  }
+
+  /// Creates a new part document if needed
+  FEATURESPLUGIN_EXPORT virtual void execute();
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Use plugin manager for features creation
+  FeaturesPlugin_Group();
+
+};
+
+#endif
index c43cd7a52691901535b4d528675dbf96e2827bb5..32c95813f68f1258d2f7b434e4226bacaefbeaa4 100644 (file)
@@ -1,9 +1,14 @@
-#include "FeaturesPlugin_Plugin.h"
-#include "FeaturesPlugin_Extrusion.h"
-#include "FeaturesPlugin_Boolean.h"
+#include <FeaturesPlugin_Plugin.h>
+
+#include <FeaturesPlugin_Boolean.h>
+#include <FeaturesPlugin_Extrusion.h>
+#include <FeaturesPlugin_Group.h>
 
 #include <ModelAPI_Session.h>
-#include <ModelAPI_Document.h>
+
+#include <string>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
 
 using namespace std;
 
@@ -20,9 +25,10 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(string theFeatureID)
 {
   if (theFeatureID == FeaturesPlugin_Extrusion::ID()) {
     return FeaturePtr(new FeaturesPlugin_Extrusion);
-  } else
-  if (theFeatureID == FeaturesPlugin_Boolean::ID()) {
+  } else if (theFeatureID == FeaturesPlugin_Boolean::ID()) {
     return FeaturePtr(new FeaturesPlugin_Boolean);
+  } else if (theFeatureID == FeaturesPlugin_Group::ID()) {
+    return FeaturePtr(new FeaturesPlugin_Group);
   }
   // feature of such kind is not found
   return FeaturePtr();
index cdf8e195ef0b7b990725039730beec66023b5361..af4822c2c848784f950bbf54d3726034ccd4ccda 100644 (file)
@@ -4,12 +4,14 @@
     icon=":icons/cut_shape.png" 
     tooltip="Select an object to cut"
     shape_types="solid shell"
+    concealment="true"
   />
   <shape_selector id="tool_object" 
     label="Tool object" 
     icon=":icons/cut_tool.png" 
     tooltip="Select a tool"
     shape_types="solid"
+    concealment="true"
   />
   <choice id="bool_type" 
     label="Type" 
index 698905a7fd4a7f9f588c6f043518fbe679eceed5..c7c5f4bdd90bebae461edbd3873fae7ace5471a5 100644 (file)
@@ -5,8 +5,9 @@
     tooltip="Select a face for extrusion"
     activate="true"
     shape_types="face"
+    use_subshapes="true"
   />
-  <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
+  <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="1" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
     <validator id="GeomValidators_Positive"/>
   </doublevalue>
   <boolvalue id="extrusion_reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
diff --git a/src/FeaturesPlugin/group_widget.xml b/src/FeaturesPlugin/group_widget.xml
new file mode 100644 (file)
index 0000000..d4288b6
--- /dev/null
@@ -0,0 +1,5 @@
+<source>
+  <multi_selector id="group_list" 
+    tooltip="List of selected objects" 
+    type_choice="Vertices Edges Faces Solids" /> 
+</source>
\ No newline at end of file
index 1088f2425bd73836b5fdec61c81b5b91d69363a3..749941fcab783ebcd4276b2d6a8bbaf92716d729 100644 (file)
@@ -8,5 +8,13 @@
           <source path="boolean_widget.xml"/>
       </feature>
     </group>
+    <group id="Collections">
+      <feature id="Group"
+        title="Group"
+        tooltip="Create a new named collection of geometry entities"
+        icon=":icons/shape_group.png">
+        <source path="group_widget.xml"/>
+      </feature>
+    </group>
   </workbench>  
 </plugin>
index e5cad12b1a677fb3172fe5ec2dc3978b0d2ada86..2718fa98007c81bd5db0b61caf66488bbcedebf1 100644 (file)
@@ -19,9 +19,11 @@ SET(PROJECT_HEADERS
     GeomAPI_Pln.h
     GeomAPI_Shape.h
     GeomAPI_Edge.h
+    GeomAPI_PlanarEdges.h
     GeomAPI_AISObject.h
     GeomAPI_IPresentable.h
     GeomAPI_Curve.h 
+    GeomAPI_DataMapOfShapeShape.h
 )
 
 SET(PROJECT_SOURCES
@@ -39,8 +41,10 @@ SET(PROJECT_SOURCES
     GeomAPI_Pln.cpp
     GeomAPI_Shape.cpp
     GeomAPI_Edge.cpp
+    GeomAPI_PlanarEdges.cpp
     GeomAPI_AISObject.cpp
     GeomAPI_Curve.cpp
+    GeomAPI_DataMapOfShapeShape.cpp
 )
 
 SET(PROJECT_LIBRARIES
@@ -48,6 +52,7 @@ SET(PROJECT_LIBRARIES
     ${CAS_MODELER} 
     ${CAS_VIEWER}
     ${CAS_SHAPE}
+    ${CAS_TKTopAlgo}
 )
 
 ADD_DEFINITIONS(-DGEOMAPI_EXPORTS ${CAS_DEFINITIONS})
index 22863757e8a855bdd25058438d88c99c827d74f4..de00d5a436b33a88144ec9e07bca6a0b11ce77f5 100644 (file)
@@ -22,6 +22,7 @@
 #include <AIS_PerpendicularRelation.hxx>
 #include <AIS_RadiusDimension.hxx>
 #include <AIS_Shape.hxx>
+#include <AIS_FixRelation.hxx>
 
 const double tolerance = 1e-7;
 
@@ -219,6 +220,30 @@ void GeomAPI_AISObject::createPerpendicular(boost::shared_ptr<GeomAPI_Shape> the
   }
 }
 
+
+void GeomAPI_AISObject::createFixed(boost::shared_ptr<GeomAPI_Shape> theShape,
+                                    boost::shared_ptr<GeomAPI_Pln> thePlane)
+{
+  Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl<gp_Pln>());
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (anAIS.IsNull()) {
+    Handle(AIS_FixRelation) aFixPrs = 
+      new AIS_FixRelation(theShape->impl<TopoDS_Shape>(), aPlane);
+
+    setImpl(new Handle(AIS_InteractiveObject)(aFixPrs));
+  } else {
+    Handle(AIS_PerpendicularRelation) aFixPrs = 
+      Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
+    if (!aFixPrs.IsNull()) {
+      aFixPrs->SetFirstShape(theShape->impl<TopoDS_Shape>());
+      aFixPrs->SetPlane(aPlane);
+      aFixPrs->Redisplay(Standard_True);
+    }
+  }
+}
+
+
+
 void GeomAPI_AISObject::setColor(const int& theColor)
 {
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
index 574d39f137c26ed6688c73c77f830cc077eea80e..0c8034d0dd8038875e1baefb3053c96bf7c03bb3 100644 (file)
@@ -77,6 +77,13 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface
                            boost::shared_ptr<GeomAPI_Shape> theLine2,
                            boost::shared_ptr<GeomAPI_Pln> thePlane);
 
+  /** \brief Creates AIS_FixedRelation object for an object
+   *  \param[in] theShape       the object
+   *  \param[in] thePlane       the plane which contains the lines
+   */
+  void createFixed(boost::shared_ptr<GeomAPI_Shape> theShape,
+                   boost::shared_ptr<GeomAPI_Pln> thePlane);
+
   /** \brief Assigns the color for the shape
    *  \param[in] theColor index of the color
    */
diff --git a/src/GeomAPI/GeomAPI_DataMapOfShapeShape.cpp b/src/GeomAPI/GeomAPI_DataMapOfShapeShape.cpp
new file mode 100644 (file)
index 0000000..56002d3
--- /dev/null
@@ -0,0 +1,62 @@
+// File:        GeomAPI_DataMapOfShapeShape.cpp
+// Created:     28 Oct 2014
+// Author:      Sergey Zaritchny
+
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <TopTools_DataMapOfShapeShape.hxx>
+#include <TopoDS_Shape.hxx>
+using namespace std;
+
+
+GeomAPI_DataMapOfShapeShape::GeomAPI_DataMapOfShapeShape()
+       :GeomAPI_Interface((void *)new TopTools_DataMapOfShapeShape){}
+
+/// Clear 
+void GeomAPI_DataMapOfShapeShape::clear()
+{
+  implPtr<TopTools_DataMapOfShapeShape>()->Clear();
+}
+
+/// Adds the Key <K> to  the Map <me>  with  the  Item. Returns True  if the Key  was not already in the map
+bool GeomAPI_DataMapOfShapeShape::bind (boost::shared_ptr<GeomAPI_Shape> theKey, boost::shared_ptr<GeomAPI_Shape> theItem)
+{
+  bool flag(false);
+  if(implPtr<TopTools_DataMapOfShapeShape>()->Bind(theKey->impl<TopoDS_Shape>(), theItem->impl<TopoDS_Shape>()))
+       flag = true;
+  return flag;
+}
+
+/// Returns true if theKey is stored  in the map.
+bool GeomAPI_DataMapOfShapeShape::isBound (boost::shared_ptr<GeomAPI_Shape> theKey)
+{
+  bool flag(false);
+  if(impl<TopTools_DataMapOfShapeShape>().IsBound(theKey->impl<TopoDS_Shape>()))
+    flag = true;
+  return flag;
+}
+
+/// Returns  the Item stored  with the Key in the Map. To be checked before with isBound()
+const boost::shared_ptr<GeomAPI_Shape> GeomAPI_DataMapOfShapeShape::find(boost::shared_ptr<GeomAPI_Shape> theKey)
+{
+  boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());  
+  aShape->setImpl(new TopoDS_Shape(impl<TopTools_DataMapOfShapeShape>().Find(theKey->impl<TopoDS_Shape>())));
+  return aShape;
+}  
+  
+/// Removes the Key from the  map. Returns true if the Key was in the Map
+bool GeomAPI_DataMapOfShapeShape::unBind(boost::shared_ptr<GeomAPI_Shape> theKey)
+{
+  bool flag(false);
+  if(implPtr<TopTools_DataMapOfShapeShape>()->UnBind(theKey->impl<TopoDS_Shape>()))
+       flag = true;
+  return flag;
+}
+
+ GeomAPI_DataMapOfShapeShape::~GeomAPI_DataMapOfShapeShape()
+ {
+  if (myImpl) {
+       implPtr<TopTools_DataMapOfShapeShape>()->Clear();
+    //delete myImpl;
+  }
+ }
\ No newline at end of file
diff --git a/src/GeomAPI/GeomAPI_DataMapOfShapeShape.h b/src/GeomAPI/GeomAPI_DataMapOfShapeShape.h
new file mode 100644 (file)
index 0000000..20b6390
--- /dev/null
@@ -0,0 +1,45 @@
+// File:        GeomAPI_DataMapOfShapeShape.h
+// Created:     28 Oct 2014
+// Author:      Sergey Zaritchny
+
+#ifndef GeomAPI_DataMapOfShapeShape_H_
+#define GeomAPI_DataMapOfShapeShape_H_
+
+#include <boost/shared_ptr.hpp>
+#include <GeomAPI_Interface.h>
+
+class GeomAPI_Pnt;
+class GeomAPI_Dir;
+
+/**\class GeomAPI_DataMapOfShapeShape
+ * \ingroup DataModel
+ * \brief DataMap of Shape - Shape defined by TopoDS_Shapes
+ */
+
+class GEOMAPI_EXPORT GeomAPI_DataMapOfShapeShape : public GeomAPI_Interface
+{
+ public:
+  /// Creation of plane by the point and normal
+  GeomAPI_DataMapOfShapeShape();
+
+  /// Clear 
+  void clear();
+
+  /// Adds the Key <K> to  the Map <me>  with  the  Item. Returns True  if the Key  was not already in the map
+  bool bind (boost::shared_ptr<GeomAPI_Shape> theKey, boost::shared_ptr<GeomAPI_Shape> theItem);
+
+  /// Returns true if theKey is stored  in the map.
+  bool isBound (boost::shared_ptr<GeomAPI_Shape> theKey);
+
+  /// Returns  the Item stored  with the Key in the Map.
+  const boost::shared_ptr<GeomAPI_Shape> find(boost::shared_ptr<GeomAPI_Shape> theKey);  
+  
+  /// Removes the Key from the  map. Returns true if the Key was in the Map
+  bool unBind(boost::shared_ptr<GeomAPI_Shape> theKey);
+
+  /// Destructor
+  ~GeomAPI_DataMapOfShapeShape();
+};
+
+#endif
+
diff --git a/src/GeomAPI/GeomAPI_PlanarEdges.cpp b/src/GeomAPI/GeomAPI_PlanarEdges.cpp
new file mode 100644 (file)
index 0000000..f12d622
--- /dev/null
@@ -0,0 +1,50 @@
+// File:        GeomAPI_PlanarEdges.cpp
+// Created:     06 Oct 2014
+// Author:      Sergey BELASH
+
+#include <GeomAPI_Interface.h>
+#include <GeomAPI_PlanarEdges.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
+#include <BRep_Builder.hxx>
+#include <BRepTools_WireExplorer.hxx>
+#include <TopExp_Explorer.hxx>
+
+#include <list>
+
+GeomAPI_PlanarEdges::GeomAPI_PlanarEdges() : GeomAPI_Shape()
+{
+  TopoDS_Compound aBigWireImpl;
+  BRep_Builder aBuilder;
+  aBuilder.MakeCompound(aBigWireImpl);
+  this->setImpl(new TopoDS_Shape(aBigWireImpl));
+}
+
+void GeomAPI_PlanarEdges::addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge)
+{
+  const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
+  if (anEdge.ShapeType() != TopAbs_EDGE)
+    return;
+  TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+  BRep_Builder aBuilder;
+  aBuilder.Add(aWire, anEdge);
+}
+
+std::list<boost::shared_ptr<GeomAPI_Shape> > GeomAPI_PlanarEdges::getEdges()
+{
+  TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+  //BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape));
+  TopExp_Explorer aWireExp(aShape, TopAbs_EDGE);
+  std::list<boost::shared_ptr<GeomAPI_Shape> > aResult;
+  for (; aWireExp.More(); aWireExp.Next()) {
+    boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
+    anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
+    aResult.push_back(anEdge);
+  }
+  return aResult;
+}
diff --git a/src/GeomAPI/GeomAPI_PlanarEdges.h b/src/GeomAPI/GeomAPI_PlanarEdges.h
new file mode 100644 (file)
index 0000000..af84226
--- /dev/null
@@ -0,0 +1,70 @@
+// File:        GeomAPI_PlanarEdges.hxx
+// Created:     24 Jul 2014
+// Author:      Artem ZHIDKOV
+
+#ifndef GEOMAPI_WIRE_H_
+#define GEOMAPI_WIRE_H_
+
+#include "GeomAPI.h"
+#include "GeomAPI_Edge.h"
+#include "GeomAPI_Pnt.h"
+#include "GeomAPI_Dir.h"
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <list>
+
+/**\class GeomAPI_PlanarEdges
+ * \ingroup DataModel
+ * \brief Interface to the edge object
+ */
+
+class GeomAPI_PlanarEdges : public GeomAPI_Shape
+{
+ public:
+  /// Creation of empty (null) shape
+  GEOMAPI_EXPORT GeomAPI_PlanarEdges();
+
+  GEOMAPI_EXPORT virtual bool isVertex() const
+  {
+    return false;
+  }
+
+  /// Returns whether the shape is an edge
+  GEOMAPI_EXPORT virtual bool isEdge() const
+  {
+    return false;
+  }
+
+  GEOMAPI_EXPORT void addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge);
+  GEOMAPI_EXPORT std::list<boost::shared_ptr<GeomAPI_Shape> > getEdges();
+
+  /// Returns True if the wire is defined in a plane
+  GEOMAPI_EXPORT bool hasPlane() const { return myOrigin && myNorm && myDirX && myDirY; }
+
+  /// Set/Get origin point
+  GEOMAPI_EXPORT void setOrigin(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin) 
+  { myOrigin = theOrigin; }
+  GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Pnt> origin() const { return myOrigin; }
+
+  /// Set/Get X direction vector
+  GEOMAPI_EXPORT void setDirX(const boost::shared_ptr<GeomAPI_Dir>& theDirX) { myDirX = theDirX; }
+  GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> dirX() const { return myDirX; }
+
+  /// Set/Get Y direction vector
+  GEOMAPI_EXPORT void setDirY(const boost::shared_ptr<GeomAPI_Dir>& theDirY) { myDirY = theDirY; }
+  GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> dirY() const { return myDirY; }
+
+  /// Set/Get Normal direction vector
+  GEOMAPI_EXPORT void setNorm(const boost::shared_ptr<GeomAPI_Dir>& theNorm) { myNorm = theNorm; }
+  GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> norm() const { return myNorm; }
+
+private:
+  boost::shared_ptr<GeomAPI_Pnt> myOrigin;
+  boost::shared_ptr<GeomAPI_Dir> myDirX;
+  boost::shared_ptr<GeomAPI_Dir> myDirY;
+  boost::shared_ptr<GeomAPI_Dir> myNorm;
+};
+
+#endif
+
index e51d30ca6bc6c75ecc79b3563163af554fb76c79..0e5bcb010afce528fa68654ab66f867f918af232 100644 (file)
@@ -13,11 +13,21 @@ GeomAPI_Shape::GeomAPI_Shape()
 {
 }
 
-bool GeomAPI_Shape::isNull()
+bool GeomAPI_Shape::isNull() const
 {
   return MY_SHAPE->IsNull() == Standard_True;
 }
 
+bool GeomAPI_Shape::isEqual(const boost::shared_ptr<GeomAPI_Shape> theShape) const
+{
+  if (isNull())
+    return theShape->isNull();
+  if (theShape->isNull())
+    return false;
+
+  return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
+}
+
 bool GeomAPI_Shape::isVertex() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
index c2e3507b4cf94dffd0cef99587443da47b136ec4..03f75d7453da0e4c85e475bb7e1595a2f6d44b0e 100644 (file)
@@ -6,6 +6,8 @@
 #define GeomAPI_Shape_H_
 
 #include <GeomAPI_Interface.h>
+#include <boost/shared_ptr.hpp>
+#include <list>
 
 /**\class GeomAPI_Shape
  * \ingroup DataModel
@@ -17,7 +19,10 @@ class GEOMAPI_EXPORT GeomAPI_Shape : public GeomAPI_Interface
   /// Creation of empty (null) shape
   GeomAPI_Shape();
 
-  bool isNull();
+  bool isNull() const;
+
+  /// Returns whether the shapes are equal
+  virtual bool isEqual(const boost::shared_ptr<GeomAPI_Shape> theShape) const;
 
   /// Returns whether the shape is a vertex
   virtual bool isVertex() const;
@@ -27,5 +32,10 @@ class GEOMAPI_EXPORT GeomAPI_Shape : public GeomAPI_Interface
 
 };
 
-#endif
+//! Pointer on list of shapes
+typedef std::list<boost::shared_ptr<GeomAPI_Shape> > ListOfShape;
 
+//! Pointer on attribute object
+typedef boost::shared_ptr<GeomAPI_Shape> GeomShapePtr;
+
+#endif
index 05e91eb61f219862c278b69f91a60c1779763eb9..5656a0ad8a5e0227eaa10d12050708099e3a7f12 100644 (file)
@@ -12,6 +12,8 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_SketchBuilder.h
     GeomAlgoAPI_Extrusion.h
     GeomAlgoAPI_Boolean.h
+    GeomAlgoAPI_MakeShape.h
+    GeomAlgoAPI_DFLoader.h
 )
 
 SET(PROJECT_SOURCES
@@ -22,14 +24,18 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_SketchBuilder.cpp
     GeomAlgoAPI_Extrusion.cpp
     GeomAlgoAPI_Boolean.cpp
+    GeomAlgoAPI_MakeShape.cpp
+    GeomAlgoAPI_DFLoader.cpp
 )
 
 SET(PROJECT_LIBRARIES
-    GeomAPI 
+    GeomAPI
+    ModelAPI 
     ${CAS_TKBool} 
     ${CAS_TKBO} 
     ${CAS_TKPrim}
     ${CAS_SHAPE}
+    ${CAS_TKTopAlgo}
 )
 
 ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
@@ -42,6 +48,7 @@ SET_SOURCE_FILES_PROPERTIES(GeomAlgoAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow")
 
 INCLUDE_DIRECTORIES(
   ../GeomAPI
+  ../ModelAPI
   ${CAS_INCLUDE_DIRS}
 )
 
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp
new file mode 100644 (file)
index 0000000..89fb023
--- /dev/null
@@ -0,0 +1,27 @@
+// File:        GeomAlgoAPI_DFLoader.cpp
+// Created:     23 October 2014
+// Author:      Sergey Zaritchny
+
+#include <GeomAlgoAPI_DFLoader.h>
+#include <TopoDS_Iterator.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+//=======================================================================
+//function : refineResult
+//purpose  :
+//=======================================================================
+const TopoDS_Shape GeomAlgoAPI_DFLoader::refineResult(const  TopoDS_Shape& theResult)
+{
+  TopoDS_Shape aResult;
+  if (theResult.ShapeType() == TopAbs_COMPOUND) {
+    Standard_Integer nbSubResults = 0;
+    TopoDS_Iterator itr(theResult);
+    for (; itr.More(); itr.Next()) nbSubResults++;
+    if (nbSubResults == 1) {
+      itr.Initialize(theResult);
+      if (itr.More()) aResult = itr.Value();
+    }
+  }
+  return aResult;
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.h b/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.h
new file mode 100644 (file)
index 0000000..766e0c7
--- /dev/null
@@ -0,0 +1,21 @@
+// File:        GeomAlgoAPI_DFLoader.h
+// Created:     23 October 2014
+// Author:      Sergey Zaritchny
+
+#ifndef GeomAlgoAPI_DFLoader_H_
+#define GeomAlgoAPI_DFLoader_H_
+#include <GeomAlgoAPI.h>
+#include <TopoDS_Shape.hxx>
+
+/**\class GeomAlgoAPI_DFLoader
+ * \ingroup DataAlgo
+ * \brief Defines several static methods useful for Data Framework filling
+ */
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_DFLoader 
+{
+ public:
+  /// Refine result
+  static const TopoDS_Shape refineResult(const TopoDS_Shape& theShape);
+};
+
+#endif
\ No newline at end of file
index a236fc8bb00135cd62e014ec1236d88b2e83b9c2..6955ee89a96e993929a0865ef9d6147cff0cad5f 100644 (file)
 // Author:      Artem ZHIDKOV
 
 #include <GeomAlgoAPI_Extrusion.h>
-
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAlgoAPI_MakeShape.h>
 #include <gp_Pln.hxx>
-
 #include <BRepPrimAPI_MakePrism.hxx>
+#include <BRepBuilderAPI_MakeShape.hxx>
 #include <Geom_Plane.hxx>
 #include <Geom_Surface.hxx>
 #include <TopExp_Explorer.hxx>
-#include <BRep_Builder.hxx>
-
+#include <BRepCheck_Analyzer.hxx>
+#include <GProp_GProps.hxx>
+#include <BRepGProp.hxx>
+#include <TopoDS.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <Precision.hxx>
+#include <TDF_TagSource.hxx>
+#include <boost/shared_ptr.hpp>
+#include <BRepPrimAPI_MakePrism.hxx>
+#include <TopoDS_Shape.hxx>
+
 const double tolerance = Precision::Angular();
+// Constructor
+GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion(
+  boost::shared_ptr<GeomAPI_Shape> theBasis, double theSize)
+: mySize(theSize), myDone(false), myShape(new GeomAPI_Shape()),
+  myFirst(new GeomAPI_Shape()), myLast(new GeomAPI_Shape())
+{
+  build(theBasis);
+}
 
-boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Extrusion::makeExtrusion(
-    boost::shared_ptr<GeomAPI_Shape> theShape, boost::shared_ptr<GeomAPI_Dir> theDir,
-    double theSize)
+//============================================================================
+void GeomAlgoAPI_Extrusion::build(const boost::shared_ptr<GeomAPI_Shape>& theBasis)
 {
-  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
-  gp_Vec aDir(theDir->impl<gp_Dir>().XYZ() * theSize);
+  bool isFirstNorm = true;
+  gp_Dir aShapeNormal;
+
+  TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
+  Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(
+    BRep_Tool::Surface(aBasis));
+  if (aPlane.IsNull())  // non-planar shapes is not supported for extrusion yet
+    return;
 
-  TopoDS_Shape aPrism = BRepPrimAPI_MakePrism(aShape, aDir);
-  if (aPrism.IsNull())
-    return boost::shared_ptr<GeomAPI_Shape>();
+  const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();  
+  gp_Vec aVec(aNormal);
+  aVec = aVec * mySize;
 
-  boost::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
-  aResult->setImpl(new TopoDS_Shape(aPrism));
-  return aResult;
+  BRepPrimAPI_MakePrism* aBuilder = new BRepPrimAPI_MakePrism(aBasis, aVec);
+  if(aBuilder) {
+    setImpl(aBuilder);
+    myDone = aBuilder->IsDone() == Standard_True;
+    if (myDone) {
+      BRepCheck_Analyzer aChecker(aBuilder->Shape());
+      myDone = aChecker.IsValid() == Standard_True;
+    }
+    if(myDone) {
+      TopoDS_Shape aResult;
+      if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND) 
+        aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape());
+      else
+        aResult = aBuilder->Shape();
+       
+       for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
+          boost::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
+       aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
+          myMap.bind(aCurrentShape, aCurrentShape);
+       }   
+      myShape->setImpl(new TopoDS_Shape(aResult));
+      myFirst->setImpl(new TopoDS_Shape(aBuilder->FirstShape()));
+      myLast->setImpl(new TopoDS_Shape(aBuilder-> LastShape()));
+         myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
+    }
+  }    
 }
 
-boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Extrusion::makeExtrusion(
-    boost::shared_ptr<GeomAPI_Shape> theShape, double theSize)
+//============================================================================
+const bool GeomAlgoAPI_Extrusion::isDone() const
+{return myDone;}
+
+//============================================================================
+const bool GeomAlgoAPI_Extrusion::isValid() const
 {
-  bool isFirstNorm = true;
-  gp_Dir aShapeNormal;
+  return myDone;
+}
 
-  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
-  TopExp_Explorer aFaceExp(aShape, TopAbs_FACE);
-  TopoDS_Compound aFaces; // use only faces from the shape: make compound for this
-  BRep_Builder aBuilder;
-  aBuilder.MakeCompound(aFaces);
-  for (; aFaceExp.More(); aFaceExp.Next()) {
-    const TopoDS_Face& aFace = (const TopoDS_Face&) aFaceExp.Current();
-    Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aFace));
-    if (aPlane.IsNull())  // non-planar shapes is not supported for extrusion yet
-      continue;
+//============================================================================
+const bool GeomAlgoAPI_Extrusion::hasVolume() const
+{
+  bool hasVolume(false);
+  if(isValid()) {
+    const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
+    GProp_GProps aGProp;
+    BRepGProp::VolumeProperties(aRShape, aGProp);
+    if(aGProp.Mass() > Precision::Confusion()) 
+      hasVolume = true;        
+  }
+  return hasVolume;
+}
+
+//============================================================================
+const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::shape () const 
+{return myShape;}
 
-    const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
-    if (isFirstNorm) {
-      aShapeNormal = aNormal;
-      isFirstNorm = false;
-    } else if (!aShapeNormal.IsEqual(aNormal, tolerance))  // non-planar shapes is not supported for extrusion yet
-      return boost::shared_ptr<GeomAPI_Shape>();
-    aBuilder.Add(aFaces, aFace);
+//============================================================================
+/*void GeomAlgoAPI_Extrusion::generated(
+  const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+{
+  theHistory.clear();
+  if(myDone) {
+    const TopTools_ListOfShape& aList = implPtr<BRepPrimAPI_MakePrism>()
+      ->Generated(theShape->impl<TopoDS_Shape>());
+    TopTools_ListIteratorOfListOfShape it(aList);
+    for(;it.More();it.Next()) {
+      boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+      aShape->setImpl(&(it.Value()));
+      theHistory.push_back(aShape);
+    }
   }
-  if (aFaces.IsNull())
-    return boost::shared_ptr<GeomAPI_Shape>();
+}
+*/
+//============================================================================
+const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::firstShape()
+{
+  return myFirst;
+}
 
-  boost::shared_ptr<GeomAPI_Dir> aDir(
-      new GeomAPI_Dir(aShapeNormal.X(), aShapeNormal.Y(), aShapeNormal.Z()));
+//============================================================================
+const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::lastShape()
+{
+  return myLast;
+}
 
-  boost::shared_ptr<GeomAPI_Shape> aFacesShape(new (GeomAPI_Shape));
-  aFacesShape->setImpl(new TopoDS_Shape(aFaces));
-  return GeomAlgoAPI_Extrusion::makeExtrusion(aFacesShape, aDir, theSize);
+//============================================================================
+void GeomAlgoAPI_Extrusion::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
+{
+  theMap = myMap;
+}
+
+//============================================================================
+GeomAlgoAPI_MakeShape * GeomAlgoAPI_Extrusion::makeShape() const
+{
+  return myMkShape;
 }
+
+//============================================================================
+GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion()
+{
+  if (myImpl) {    
+       myMap.clear();
+       //delete myImpl;
+  }
+}
\ No newline at end of file
index 31b3d4406378d519d1f7b78d4c79c3c83c3c66d9..7a033a6aeb61c1095994bfa7553a5f9f88557350 100644 (file)
@@ -1,6 +1,6 @@
 // File:        GeomAlgoAPI_Extrusion.h
-// Created:     06 Jun 2014
-// Author:      Artem ZHIDKOV
+// Created:     22 October 2014
+// Author:      Sergey Zaritchny
 
 #ifndef GeomAlgoAPI_Extrusion_H_
 #define GeomAlgoAPI_Extrusion_H_
@@ -8,33 +8,70 @@
 #include <GeomAlgoAPI.h>
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_Dir.h>
+#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAPI_DataMapOfShapeShape.h>
 #include <boost/shared_ptr.hpp>
-
 /**\class GeomAlgoAPI_Extrusion
  * \ingroup DataAlgo
  * \brief Allows to create the prism based on a given face and a direction
  */
 
-class GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion
+class GeomAlgoAPI_Extrusion : public GeomAPI_Interface//GeomAlgoAPI_MakeShape
 {
  public:
-  /* \brief Creates extrusion for the given shape
-   * \param[in] theShape face or wire to be extruded
-   * \param[in] theDir   direction of extrusion
-   * \param[in] theSize  the length of extrusion (if the value is less than 0, the extrusion in opposite direction)
-   * \return a solid or a face which is obtained from specified one
-   */
-  static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<GeomAPI_Shape> theShape,
-                                                        boost::shared_ptr<GeomAPI_Dir> theDir,
-                                                        double theSize);
 
   /* \brief Creates extrusion for the given shape along the normal for this shape
    * \param[in] theShape face or wire to be extruded
    * \param[in] theSize  the length of extrusion (if the value is less than 0, the extrusion in opposite normal)
    * \return a solid or a face which is obtained from specified one
-   */
-  static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<GeomAPI_Shape> theShape,
-                                                        double theSize);
+  
+  static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<ModelAPI_ResultBody> theResult,
+                                                                                                               boost::shared_ptr<GeomAPI_Shape> theBasis,
+                                                                                                               boost::shared_ptr<GeomAPI_Shape> theContext,
+                                                        double theSize); */
+  /// Constructor
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion (boost::shared_ptr<GeomAPI_Shape> theBasis, double theSize);
+
+  /// Returns True if algorithm succeed
+  GEOMALGOAPI_EXPORT const bool isDone() const;
+
+  ///  Returns True if resulting shape is valid
+  GEOMALGOAPI_EXPORT const bool isValid() const;
+
+  /// Returns True if resulting shape has volume
+  GEOMALGOAPI_EXPORT const bool hasVolume() const;
+
+  /// Returns result of the Extrusion algorithm which may be a Solid or a Face
+  GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& shape () const;
+
+  /// Returns list of shapes generated from theShape
+ // GEOMALGOAPI_EXPORT void generated(const boost::shared_ptr<GeomAPI_Shape> theShape,
+                                   // ListOfShape& theHistory);
+
+  /// Returns the first shape 
+  GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& firstShape();
+
+  /// returns last shape
+  GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& lastShape();      
+  /// Returns map of sub-shapes of the result
+  GEOMALGOAPI_EXPORT void  mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const;
+
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape* makeShape () const;
+
+  GEOMALGOAPI_EXPORT  ~GeomAlgoAPI_Extrusion();
+private:
+  /// builds resulting shape
+  void build(const boost::shared_ptr<GeomAPI_Shape>& theBasis);
+
+  double mySize;
+  bool myDone;
+  boost::shared_ptr<GeomAPI_Shape> myShape;
+  boost::shared_ptr<GeomAPI_Shape> myFirst;
+  boost::shared_ptr<GeomAPI_Shape> myLast;
+  GeomAPI_DataMapOfShapeShape myMap;
+  GeomAlgoAPI_MakeShape * myMkShape;
 };
 
 #endif
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp
new file mode 100644 (file)
index 0000000..70cfad9
--- /dev/null
@@ -0,0 +1,69 @@
+// File:        GeomAlgoAPI_MakeShape.cpp
+// Created:     20 Oct 2014
+// Author:      Sergey ZARITCHNY
+
+#include <GeomAlgoAPI_MakeShape.h>
+#include <BRepBuilderAPI_MakeShape.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape)
+  : GeomAPI_Interface(theMkShape),myShape(new GeomAPI_Shape())
+{
+  myShape->setImpl((void *)&implPtr<BRepBuilderAPI_MakeShape>()->Shape());
+}
+
+GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
+  : GeomAPI_Interface(),myShape(new GeomAPI_Shape())
+{}
+void GeomAlgoAPI_MakeShape::init(void* theMkShape)
+{
+  setImpl((void *)implPtr<BRepBuilderAPI_MakeShape>());
+}
+
+const boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
+{
+  return myShape;
+}
+
+/// Returns the  list   of shapes generated   from the shape <theShape>
+void GeomAlgoAPI_MakeShape::generated(
+  const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+{
+  BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+  if(aBuilder) {
+    const TopTools_ListOfShape& aList =  aBuilder->Generated(theShape->impl<TopoDS_Shape>());
+    TopTools_ListIteratorOfListOfShape it(aList);
+    for(;it.More();it.Next()) {
+      boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+      aShape->setImpl(new TopoDS_Shape(it.Value()));
+      theHistory.push_back(aShape);
+    }
+  }
+}
+
+/// Returns the  list   of shapes modified   from the shape <theShape>
+void GeomAlgoAPI_MakeShape::modified(
+  const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+{
+  BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+  if(aBuilder) {
+    const TopTools_ListOfShape& aList =  aBuilder->Modified(theShape->impl<TopoDS_Shape>());
+    TopTools_ListIteratorOfListOfShape it(aList);
+    for(;it.More();it.Next()) {
+      boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+      aShape->setImpl(new TopoDS_Shape(it.Value()));
+      theHistory.push_back(aShape);
+    }
+  }
+}
+
+/// Returns whether the shape is an edge
+bool GeomAlgoAPI_MakeShape::isDeleted(const boost::shared_ptr<GeomAPI_Shape> theShape)
+{
+  bool isDeleted(false);
+  BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+  if(aBuilder) {
+    isDeleted = aBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
+  }
+  return isDeleted;
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h
new file mode 100644 (file)
index 0000000..4fa0ef0
--- /dev/null
@@ -0,0 +1,43 @@
+// File:        GeomAlgoAPI_MakeShape.h
+// Created:     17 Oct 2014
+// Author:      Sergey ZARITCHNY
+#ifndef GeomAlgoAPI_MakeShape_H_
+#define GeomAlgoAPI_MakeShape_H_
+
+#include <GeomAPI_Shape.h>
+#include <boost/shared_ptr.hpp>
+#include <GeomAlgoAPI.h>
+//#include <BRepBuilderAPI_MakeShape.hxx>
+/**\class GeomAlgoAPI_MakeShape
+ * \ingroup DataModel
+ * \Interface to the root class of all topological shapes constructions
+ */
+class GeomAlgoAPI_MakeShape : public GeomAPI_Interface
+{
+ public:
+   /// Constructor
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape();
+
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape(void* theBuilder);
+
+  /// Returns a shape built by the shape construction algorithm
+  GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>  shape() const;
+
+  /// Returns the  list   of shapes generated   from the shape <theShape>
+  GEOMALGOAPI_EXPORT virtual void generated(
+    const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory);
+
+  /// Returns the  list   of shapes modified   from the shape <theShape>
+  GEOMALGOAPI_EXPORT virtual void modified(
+    const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory);
+
+  /// Returns whether the shape is an edge
+  GEOMALGOAPI_EXPORT virtual bool isDeleted(const boost::shared_ptr<GeomAPI_Shape> theShape);
+
+  GEOMALGOAPI_EXPORT void init(void* theMkShape);
+
+  protected:
+       boost::shared_ptr<GeomAPI_Shape> myShape;
+};
+
+#endif
index 20c3211ee1e402dd44cdbeeb20663c3d66e79874..ddd6d397712e5bcf3aa29e2ae2b38616ad4a71e3 100644 (file)
@@ -3,6 +3,7 @@
 // Author:      Artem ZHIDKOV
 
 #include <GeomAlgoAPI_SketchBuilder.h>
+#include <GeomAPI_PlanarEdges.h>
 
 #include <set>
 
@@ -370,6 +371,23 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
     fixIntersections(theResultFaces);
 }
 
+void GeomAlgoAPI_SketchBuilder::createFaces(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+                                            const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+                                            const boost::shared_ptr<GeomAPI_Dir>& theDirY,
+                                            const boost::shared_ptr<GeomAPI_Dir>& theNorm,
+                                            const boost::shared_ptr<GeomAPI_Shape>& theWire,
+                                            std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces)
+{
+  boost::shared_ptr<GeomAPI_PlanarEdges> aWire = boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(theWire);
+  if(!aWire)
+    return;
+  // Filter wires, return only faces.
+  std::list<boost::shared_ptr<GeomAPI_Shape> > aFilteredWires;
+  createFaces(theOrigin, theDirX, theDirY, theNorm,
+              aWire->getEdges(), theResultFaces, aFilteredWires);
+}
+
+
 void GeomAlgoAPI_SketchBuilder::fixIntersections(
     std::list<boost::shared_ptr<GeomAPI_Shape> >& theFaces)
 {
index 22eafe77ef05252485c8b63d52b0f5d6c8f68cbd..86505f82dbb8fd94299b51d443113656e7b9278d 100644 (file)
@@ -42,6 +42,25 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_SketchBuilder
                           std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces,
                           std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultWires);
 
+  /** \brief Creates list of faces and unclosed wires on basis of the features of the sketch
+   *  \param[in]  theOrigin      origin point of the sketch
+   *  \param[in]  theDirX        x-direction of the sketch
+   *  \param[in]  theDirY        y-direction of the sketch
+   *  \param[in]  theNorm        normal of the sketch
+   *  \param[in]  theWire        a wire which contains all edges
+   *  \param[out] theResultFaces faces based on closed wires
+   *
+   *  The algorithm searches all loops of edges surrounding lesser squares.
+   *  It finds the vertex with minimal coordinates along X axis (theDirX) and then
+   *  goes through the edges passing the surrounding area on the left.
+   */
+  static void createFaces(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+                          const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+                          const boost::shared_ptr<GeomAPI_Dir>& theDirY,
+                          const boost::shared_ptr<GeomAPI_Dir>& theNorm,
+                          const boost::shared_ptr<GeomAPI_Shape>& theWire,
+                          std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces);
+
   /** \brief Searches intersections between the faces in the list 
    *         and make holes in the faces to avoid intersections
    *  \param[in,out] theFaces list of faces to proccess
index f526999f61c943c72b897c5dd629f78796c443d9..fcc741e3b30a18ab3d620107aa6992b54bf74c76 100644 (file)
@@ -19,8 +19,8 @@ public:
   //! returns true if attribute is valid
   //! \param theAttribute the checked attribute
   //! \param theArguments arguments of the attribute
-  GEOMVALIDATORS_EXPORT virtual bool isValid(
-    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
+  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments) const;
 
 };
 
index 69a821ac3a90d8184c9cee3d21c3490ea9f4fbfe..1656a618f50738db0746fba46fc4ff0b86b23908 100644 (file)
@@ -14,6 +14,8 @@ SET(PROJECT_HEADERS
     Model_AttributeBoolean.h
     Model_AttributeString.h
     Model_AttributeInteger.h
+    Model_AttributeSelection.h
+    Model_AttributeSelectionList.h
     Model_Events.h
     Model_Update.h
     Model_Validator.h
@@ -36,6 +38,8 @@ SET(PROJECT_SOURCES
     Model_AttributeBoolean.cpp
     Model_AttributeString.cpp
     Model_AttributeInteger.cpp
+    Model_AttributeSelection.cpp
+    Model_AttributeSelectionList.cpp
     Model_Events.cpp
     Model_Update.cpp
     Model_Validator.cpp
@@ -51,6 +55,7 @@ SET(PROJECT_LIBRARIES
     Config 
     GeomData
     GeomAPI
+    GeomAlgoAPI
     ${CAS_OCAF}
     ${CAS_TKCAF}
     ${CAS_SHAPE}
@@ -60,7 +65,7 @@ SET(PROJECT_LIBRARIES
 
 
 ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
-ADD_LIBRARY(Model MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
 TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES})
 
 INCLUDE_DIRECTORIES(
@@ -69,6 +74,7 @@ INCLUDE_DIRECTORIES(
   ../Config
   ../GeomData
   ../GeomDataAPI
+  ../GeomAlgoAPI
   ../GeomAPI
   ${CAS_INCLUDE_DIRS}
 )
index 3d3af3467a634402939bdce3243832fce39e4701..014592f0d3eebd58a02679f862777e510745c69c 100644 (file)
@@ -26,7 +26,7 @@ void Model_AttributeRefList::remove(ObjectPtr theObject)
   owner()->data()->sendAttributeUpdated(this);
 }
 
-int Model_AttributeRefList::size()
+int Model_AttributeRefList::size() const
 {
   return myRef->Extent();
 }
@@ -46,6 +46,21 @@ list<ObjectPtr> Model_AttributeRefList::list()
   return aResult;
 }
 
+ObjectPtr Model_AttributeRefList::object(const int theIndex) const
+{
+  boost::shared_ptr<Model_Document> aDoc = boost::dynamic_pointer_cast<Model_Document>(
+      owner()->document());
+  if (aDoc) {
+    const TDF_LabelList& aList = myRef->List();
+    int anIndex = 0;
+    for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next(), anIndex++) {
+      if (anIndex == theIndex)
+        return aDoc->object(aLIter.Value());
+    }
+  }
+  return ObjectPtr();
+}
+
 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
 {
   myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
index d784769e6c52b6619e5d9bb9be8bdecd9f4d90cf..2b0edac1fc99c7a2f4ab30f1109f29e2c140b668 100644 (file)
@@ -27,11 +27,14 @@ class Model_AttributeRefList : public ModelAPI_AttributeRefList
   MODEL_EXPORT virtual void remove(ObjectPtr theObject);
 
   /// Returns number of features in the list
-  MODEL_EXPORT virtual int size();
+  MODEL_EXPORT virtual int size() const;
 
   /// Returns the list of features
   MODEL_EXPORT virtual std::list<ObjectPtr> list();
 
+  /// Returns the list of features
+  MODEL_EXPORT virtual ObjectPtr object(const int theIndex) const;
+
  protected:
   /// Objects are created for features automatically
   MODEL_EXPORT Model_AttributeRefList(TDF_Label& theLabel);
index 134516972b2a2eecfacab366f3bb46f9204d5a8c..3781fb2a2c4157a37b8a9b605b596e85ec4a3179 100644 (file)
@@ -20,9 +20,7 @@ void Model_AttributeReference::setValue(ObjectPtr theObject)
 
     boost::shared_ptr<Model_Document> aDoc =
       boost::dynamic_pointer_cast<Model_Document>(owner()->document());
-    if (aDoc) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get()));
     myRef->Set(aData->label().Father());  // references to the feature label
-    boost::shared_dynamic_cast<Model_Document>(owner()->document())->objectIsReferenced(theObject);
 
     owner()->data()->sendAttributeUpdated(this);
   }
@@ -51,7 +49,6 @@ Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
     if (owner()) {
       boost::shared_ptr<Model_Document> aDoc =
         boost::dynamic_pointer_cast<Model_Document>(owner()->document());
-      if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get()));
     }
   }
 }
@@ -62,7 +59,6 @@ void Model_AttributeReference::setObject(const boost::shared_ptr<ModelAPI_Object
     ModelAPI_AttributeReference::setObject(theObject);
     boost::shared_ptr<Model_Document> aDoc =
       boost::dynamic_pointer_cast<Model_Document>(owner()->document());
-    if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get()));
   }
 }
 
@@ -71,5 +67,4 @@ Model_AttributeReference::~Model_AttributeReference()
   boost::shared_ptr<Model_Document> aDoc =
     boost::dynamic_pointer_cast<Model_Document>(owner()->document());
   TDF_Label aLab = myRef->Get();
-  if (aDoc && !aLab.IsNull()) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get()));
 }
index d9993f99a6049a57a0beb97ee7a3ca7b5e84c08a..b41891bdb9ac7b451c9b30d25167a9e0ac4c4be1 100644 (file)
@@ -35,6 +35,7 @@ protected:
   MODEL_EXPORT Model_AttributeReference(TDF_Label& theLabel);
 
   friend class Model_Data;
+  friend class Model_AttributeSelection;
 };
 
 #endif
diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp
new file mode 100644 (file)
index 0000000..f502aee
--- /dev/null
@@ -0,0 +1,259 @@
+// File:        Model_AttributeSelection.h
+// Created:     2 Oct 2014
+// Author:      Mikhail PONIKAROV
+
+#include "Model_AttributeSelection.h"
+#include "Model_Application.h"
+#include "Model_Events.h"
+#include "Model_Data.h"
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_CompositeFeature.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAlgoAPI_SketchBuilder.h>
+#include <Events_Error.h>
+
+#include <TNaming_Selector.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TNaming_Tool.hxx>
+#include <TNaming_Builder.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TDataStd_IntPackedMap.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TDF_LabelMap.hxx>
+#include <BRep_Tool.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+#include <TColStd_MapOfTransient.hxx>
+
+using namespace std;
+
+void Model_AttributeSelection::setValue(const ResultPtr& theContext,
+  const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+  const boost::shared_ptr<GeomAPI_Shape>& anOldShape = value();
+  bool isOldShape = 
+    (theSubShape == anOldShape || (theSubShape && anOldShape && theSubShape->isEqual(anOldShape)));
+  if (isOldShape) return; // shape is the same, so context is also unchanged
+  // update the referenced object if needed
+  bool isOldContext = theContext == myRef.value();
+  if (!isOldContext)
+    myRef.setValue(theContext);
+
+  if (theContext->groupName() == ModelAPI_ResultBody::group())
+    selectBody(theContext, theSubShape);
+  else if (theContext->groupName() == ModelAPI_ResultConstruction::group())
+    selectConstruction(theContext, theSubShape);
+
+  myIsInitialized = true;
+  owner()->data()->sendAttributeUpdated(this);
+}
+
+boost::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::value()
+{
+  boost::shared_ptr<GeomAPI_Shape> aResult;
+  if (myIsInitialized) {
+    Handle(TNaming_NamedShape) aSelection;
+    if (selectionLabel().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
+      TopoDS_Shape aSelShape = aSelection->Get();
+      aResult = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
+      aResult->setImpl(new TopoDS_Shape(aSelShape));
+    }
+  }
+  return aResult;
+}
+
+Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel)
+  : myRef(theLabel)
+{
+  myIsInitialized = myRef.isInitialized();
+}
+
+ResultPtr Model_AttributeSelection::context() {
+  return boost::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
+}
+
+
+void Model_AttributeSelection::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
+{
+  ModelAPI_AttributeSelection::setObject(theObject);
+  myRef.setObject(theObject);
+}
+
+bool Model_AttributeSelection::update()
+{
+  ResultPtr aContext = context();
+  if (!aContext) return false;
+  if (aContext->groupName() == ModelAPI_ResultBody::group()) {
+    // body: just a named shape, use selection mechanism from OCCT
+    TNaming_Selector aSelector(selectionLabel());
+    TDF_LabelMap aScope; // empty means the whole document
+    return aSelector.Solve(aScope) == Standard_True;
+   
+  } else if (aContext->groupName() == ModelAPI_ResultConstruction::group()) {
+    // construction: identification by the results indexes, recompute faces and
+    // take the face that more close by the indexes
+    boost::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(
+      boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext)->shape());
+    if (aWirePtr && aWirePtr->hasPlane()) {
+        // If this is a wire with plane defined thin it is a sketch-like object
+      std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
+      GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
+        aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, aFaces);
+      if (aFaces.empty()) // no faces, update can not work correctly
+        return false;
+      // if there is no edges indexes, any face can be used: take the first
+      boost::shared_ptr<Model_Data> aData = 
+        boost::dynamic_pointer_cast<Model_Data>(owner()->data());
+      TDF_Label aLab = aData->label();
+      Handle(TDataStd_IntPackedMap) aSubIds;
+      boost::shared_ptr<GeomAPI_Shape> aNewSelected;
+      if (!aLab.FindAttribute(TDataStd_IntPackedMap::GetID(), aSubIds) || aSubIds->Extent() == 0) {
+        aNewSelected = *(aFaces.begin());
+      } else { // searching for most looks-like initial face by the indexes
+        // prepare edges of the current resut for the fast searching
+        TColStd_MapOfTransient allCurves;
+        FeaturePtr aContextFeature = owner()->document()->feature(aContext);
+        CompositeFeaturePtr aComposite = 
+          boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
+        if (!aComposite) // must be composite at least for the current implementation
+          return false;
+        const int aSubNum = aComposite->numberOfSubs();
+        for(int a = 0; a < aSubNum; a++) {
+          if (aSubIds->Contains(aComposite->subFeatureId(a))) {
+            FeaturePtr aSub = aComposite->subFeature(a);
+            const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
+            std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResults.cbegin();
+            for(; aRes != aResults.cend(); aRes++) {
+              ResultConstructionPtr aConstr = 
+                boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
+              if (aConstr->shape() && aConstr->shape()->isEdge()) {
+                const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
+                TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
+                if (!anEdge.IsNull()) {
+                  Standard_Real aFirst, aLast;
+                  Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+                  allCurves.Add(aCurve);
+                }
+              }
+            }
+          }
+        }
+        // iterate new result faces and searching for these edges
+        std::list<boost::shared_ptr<GeomAPI_Shape> >::iterator aFacesIter = aFaces.begin();
+        double aBestFound = 0; // best percentage of found edges
+        for(; aFacesIter != aFaces.end(); aFacesIter++) {
+          int aFound = 0, aNotFound = 0;
+          TopExp_Explorer anEdgesExp((*aFacesIter)->impl<TopoDS_Shape>(), TopAbs_EDGE);
+          for(; anEdgesExp.More(); anEdgesExp.Next()) {
+            TopoDS_Edge anEdge = TopoDS::Edge(anEdgesExp.Current());
+            if (!anEdge.IsNull()) {
+              Standard_Real aFirst, aLast;
+              Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+              if (allCurves.Contains(aCurve)) {
+                aFound++;
+              } else {
+                aNotFound++;
+              }
+            }
+          }
+          if (aFound + aNotFound != 0) {
+            double aPercentage = double(aFound) / double(aFound + aNotFound);
+            if (aPercentage > aBestFound) {
+              aBestFound = aPercentage;
+              aNewSelected = *aFacesIter;
+            }
+          }
+        }
+      }
+      if (aNewSelected) { // store this new selection
+        selectConstruction(aContext, aNewSelected);
+        return true;
+      }
+    }
+  }
+  return false; // unknown case
+}
+
+
+void Model_AttributeSelection::selectBody(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+  // perform the selection
+  TNaming_Selector aSel(selectionLabel());
+  TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : TopoDS_Shape();
+  TopoDS_Shape aContext;
+
+  ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
+  if (aBody)
+    aContext = aBody->shape()->impl<TopoDS_Shape>();
+  else {
+    ResultConstructionPtr aConstr = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myRef.value());
+    if (aConstr) {
+      aContext = aConstr->shape()->impl<TopoDS_Shape>();
+    } else {
+      Events_Error::send("A result with shape is expected");
+      return;
+    }
+  }
+  aSel.Select(aNewShape, aContext);
+}
+
+void Model_AttributeSelection::selectConstruction(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+  FeaturePtr aContextFeature = owner()->document()->feature(theContext);
+  CompositeFeaturePtr aComposite = 
+    boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
+  if (!aComposite || aComposite->numberOfSubs() == 0) {
+    return; // saving of context is enough: result construction contains exactly the needed shape
+  }
+  boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(owner()->data());
+  TDF_Label aLab = aData->label();
+  // identify the reuslts of sub-object of the composite by edges
+  const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
+  TColStd_MapOfTransient allCurves;
+  for(TopExp_Explorer anEdgeExp(aSubShape, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next()) {
+    TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExp.Current());
+    Standard_Real aFirst, aLast;
+    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+    allCurves.Add(aCurve);
+  }
+  // iterate and store the result ids of sub-elements
+  Handle(TDataStd_IntPackedMap) aRefs = TDataStd_IntPackedMap::Set(aLab);
+  const int aSubNum = aComposite->numberOfSubs();
+  for(int a = 0; a < aSubNum; a++) {
+    FeaturePtr aSub = aComposite->subFeature(a);
+    const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
+    std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResults.cbegin();
+    // there may be many shapes (circle and center): register if at least one is in selection
+    for(; aRes != aResults.cend(); aRes++) {
+      ResultConstructionPtr aConstr = 
+        boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
+      if (aConstr->shape() && aConstr->shape()->isEdge()) {
+        const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
+        TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
+        if (!anEdge.IsNull()) {
+          Standard_Real aFirst, aLast;
+          Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+          if (allCurves.Contains(aCurve)) {
+            boost::shared_ptr<Model_Data> aSubData = boost::dynamic_pointer_cast<Model_Data>(aSub->data());
+            TDF_Label aSubLab = aSubData->label();
+            aRefs->Add(aComposite->subFeatureId(a));
+          }
+        }
+      }
+    }
+  }
+  // store the selected as primitive
+  TNaming_Builder aBuilder(selectionLabel());
+  aBuilder.Generated(aSubShape);
+}
+
+TDF_Label Model_AttributeSelection::selectionLabel()
+{
+  return myRef.myRef->Label().FindChild(1);
+}
diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h
new file mode 100644 (file)
index 0000000..1508476
--- /dev/null
@@ -0,0 +1,58 @@
+// File:        Model_AttributeSelection.h
+// Created:     8 May 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef Model_AttributeSelection_H_
+#define Model_AttributeSelection_H_
+
+#include "Model.h"
+#include "Model_AttributeReference.h"
+#include <ModelAPI_AttributeSelection.h>
+
+/**\class Model_AttributeSelection
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
+ */
+
+class Model_AttributeSelection : public ModelAPI_AttributeSelection
+{
+  Model_AttributeReference myRef;  ///< The reference functionality reusage
+public:
+  /// Defines the result and its selected sub-shape
+  MODEL_EXPORT virtual void setValue(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+
+  /// Returns the selected subshape
+  MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> value();
+
+  /// Returns the context of the selection (the whole shape owner)
+  MODEL_EXPORT virtual ResultPtr context();
+
+  /// Sets the feature object
+  MODEL_EXPORT virtual void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject);
+
+  /// Updates the underlied selection due to the changes in the referenced objects
+  /// \returns false if update is failed
+  MODEL_EXPORT virtual bool update();
+
+protected:
+  /// Objects are created for features automatically
+  MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
+    /// Performs the selection for the body result (TNaming Selection)
+
+  /// Performs the selection for the body result (TNaming selection)
+  virtual void selectBody(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+  /// Performs the selection for the construction result (selection by index)
+  virtual void selectConstruction(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+
+  /// Returns the label where TNaming_Selection results are stored
+  /// Note: there must be no attributes stored at the same label because Selector clears this lab
+  TDF_Label selectionLabel();
+
+  friend class Model_Data;
+  friend class Model_AttributeSelectionList;
+};
+
+#endif
diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp
new file mode 100644 (file)
index 0000000..a955101
--- /dev/null
@@ -0,0 +1,82 @@
+// File:        Model_AttributeSelectionList.h
+// Created:     22 Oct 2014
+// Author:      Mikhail PONIKAROV
+
+#include "Model_AttributeSelectionList.h"
+#include "Model_AttributeSelection.h"
+#include "Model_Application.h"
+#include "Model_Events.h"
+#include "Model_Data.h"
+
+#include <TDF_ChildIterator.hxx>
+
+using namespace std;
+
+void Model_AttributeSelectionList::append(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+  int aNewTag = mySize->Get() + 1;
+  TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
+
+  boost::shared_ptr<Model_AttributeSelection> aNewAttr = 
+    boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
+  if (owner()) {
+    aNewAttr->setObject(owner());
+  }
+  mySubs.push_back(aNewAttr);
+  mySize->Set(aNewTag);
+  aNewAttr->setValue(theContext, theSubShape);
+  owner()->data()->sendAttributeUpdated(this);
+}
+
+int Model_AttributeSelectionList::size()
+{
+  return mySize->Get();
+}
+
+boost::shared_ptr<ModelAPI_AttributeSelection> 
+  Model_AttributeSelectionList::value(const int theIndex)
+{
+  return mySubs[theIndex];
+}
+
+void Model_AttributeSelectionList::clear()
+{
+  if (!mySubs.empty()) {
+    mySize->Set(0);
+    mySubs.clear();
+    TDF_ChildIterator aSubIter(mySize->Label());
+    for(; aSubIter.More(); aSubIter.Next()) {
+      aSubIter.Value().ForgetAllAttributes(Standard_True);
+    }
+    owner()->data()->sendAttributeUpdated(this);
+  }
+}
+
+Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
+{
+  myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
+  if (!myIsInitialized) {
+    mySize = TDataStd_Integer::Set(theLabel, 0);
+  } else { // recollect mySubs
+    int aNum = mySize->Get();
+    TDF_ChildIterator aSubIter(theLabel);
+    for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) {
+      TDF_Label aChildLab = aSubIter.Value();
+      boost::shared_ptr<Model_AttributeSelection> aNewAttr = 
+        boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aChildLab));
+      if (owner())
+        aNewAttr->setObject(owner());
+      mySubs.push_back(aNewAttr);
+    }
+  }
+}
+
+void Model_AttributeSelectionList::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
+{
+  ModelAPI_AttributeSelectionList::setObject(theObject);
+  std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter = mySubs.begin();
+  for(; aSubIter != mySubs.end(); aSubIter++) {
+    (*aSubIter)->setObject(theObject);
+  }
+}
diff --git a/src/Model/Model_AttributeSelectionList.h b/src/Model/Model_AttributeSelectionList.h
new file mode 100644 (file)
index 0000000..103b213
--- /dev/null
@@ -0,0 +1,49 @@
+// File:        Model_AttributeSelectionList.h
+// Created:     22 Oct 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef Model_AttributeSelectionList_H_
+#define Model_AttributeSelectionList_H_
+
+#include "Model.h"
+#include "Model_AttributeSelection.h"
+#include <ModelAPI_AttributeSelectionList.h>
+#include <TDataStd_Integer.hxx>
+#include <vector>
+
+/**\class Model_AttributeSelectionList
+ * \ingroup DataModel
+ * \brief Attribute that contains list of references to the sub-shapes with
+ * possibility to manage them.
+ */
+
+class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
+{
+  Handle(TDataStd_Integer) mySize;  ///< Contains size of this list
+  std::vector<boost::shared_ptr<Model_AttributeSelection> > mySubs; /// the selection attributes
+public:
+  /// Adds the new reference to the end of the list
+  MODEL_EXPORT virtual void append(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+
+  /// Returns the number ofselection attributes in the list
+  MODEL_EXPORT virtual int size();
+
+  /// Returns the attribute selection by the index (zero based)
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
+
+  /// Returns all attributes
+  MODEL_EXPORT virtual void clear();
+
+  /// Sets the feature object
+  MODEL_EXPORT virtual void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject);
+
+protected:
+  /// Objects are created for features automatically
+  MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
+    /// Performs the selection for the body result (TNaming Selection)
+
+  friend class Model_Data;
+};
+
+#endif
index 495bd04bc539c6ffdf1102dc2449e3e5102d1017..a3a1177410a933b240cda98348d735da7eff1481 100644 (file)
 #include <Model_AttributeRefList.h>
 #include <Model_AttributeBoolean.h>
 #include <Model_AttributeString.h>
+#include <Model_AttributeSelection.h>
+#include <Model_AttributeSelectionList.h>
 #include <Model_Events.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
 
 #include <GeomData_Point.h>
 #include <GeomData_Point2D.h>
@@ -73,6 +77,10 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt
     anAttr = new Model_AttributeString(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeReference::type()) {
     anAttr = new Model_AttributeReference(anAttrLab);
+  } else if (theAttrType == ModelAPI_AttributeSelection::type()) {
+    anAttr = new Model_AttributeSelection(anAttrLab);
+  } else if (theAttrType == ModelAPI_AttributeSelectionList::type()) {
+    anAttr = new Model_AttributeSelectionList(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeRefAttr::type()) {
     anAttr = new Model_AttributeRefAttr(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeRefList::type()) {
@@ -94,7 +102,8 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt
 
 boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::document(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
+    myAttrs.find(theID);
   if (aFound == myAttrs.end()) {
     // TODO: generate error on unknown attribute request and/or add mechanism for customization
     return boost::shared_ptr<ModelAPI_AttributeDocRef>();
@@ -109,7 +118,8 @@ boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::document(const std::stri
 
 boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
+    myAttrs.find(theID);
   if (aFound == myAttrs.end()) {
     // TODO: generate error on unknown attribute request and/or add mechanism for customization
     return boost::shared_ptr<ModelAPI_AttributeDouble>();
@@ -124,7 +134,8 @@ boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const std::string&
 
 boost::shared_ptr<ModelAPI_AttributeInteger> Model_Data::integer(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
+    myAttrs.find(theID);
   if (aFound == myAttrs.end()) {
     // TODO: generate error on unknown attribute request and/or add mechanism for customization
     return boost::shared_ptr<ModelAPI_AttributeInteger>();
@@ -139,7 +150,8 @@ boost::shared_ptr<ModelAPI_AttributeInteger> Model_Data::integer(const std::stri
 
 boost::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
+    myAttrs.find(theID);
   if (aFound == myAttrs.end()) {
     // TODO: generate error on unknown attribute request and/or add mechanism for customization
     return boost::shared_ptr<ModelAPI_AttributeBoolean>();
@@ -154,7 +166,8 @@ boost::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::stri
 
 boost::shared_ptr<ModelAPI_AttributeString> Model_Data::string(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
+    myAttrs.find(theID);
   if (aFound == myAttrs.end()) {
     // TODO: generate error on unknown attribute request and/or add mechanism for customization
     return boost::shared_ptr<ModelAPI_AttributeString>();
@@ -170,7 +183,8 @@ boost::shared_ptr<ModelAPI_AttributeString> Model_Data::string(const std::string
 
 boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
+    myAttrs.find(theID);
   if (aFound == myAttrs.end()) {
     // TODO: generate error on unknown attribute request and/or add mechanism for customization
     return boost::shared_ptr<ModelAPI_AttributeReference>();
@@ -183,9 +197,43 @@ boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const std::
   return aRes;
 }
 
+boost::shared_ptr<ModelAPI_AttributeSelection> Model_Data::selection(const std::string& theID)
+{
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
+    myAttrs.find(theID);
+  if (aFound == myAttrs.end()) {
+    // TODO: generate error on unknown attribute request and/or add mechanism for customization
+    return boost::shared_ptr<ModelAPI_AttributeSelection>();
+  }
+  boost::shared_ptr<ModelAPI_AttributeSelection> aRes = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aFound->second);
+  if (!aRes) {
+    // TODO: generate error on invalid attribute type request
+  }
+  return aRes;
+}
+
+boost::shared_ptr<ModelAPI_AttributeSelectionList> 
+  Model_Data::selectionList(const std::string& theID)
+{
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
+    myAttrs.find(theID);
+  if (aFound == myAttrs.end()) {
+    // TODO: generate error on unknown attribute request and/or add mechanism for customization
+    return boost::shared_ptr<ModelAPI_AttributeSelectionList>();
+  }
+  boost::shared_ptr<ModelAPI_AttributeSelectionList> aRes = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aFound->second);
+  if (!aRes) {
+    // TODO: generate error on invalid attribute type request
+  }
+  return aRes;
+}
+
 boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
+    myAttrs.find(theID);
   if (aFound == myAttrs.end()) {
     // TODO: generate error on unknown attribute request and/or add mechanism for customization
     return boost::shared_ptr<ModelAPI_AttributeRefAttr>();
@@ -200,7 +248,8 @@ boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const std::stri
 
 boost::shared_ptr<ModelAPI_AttributeRefList> Model_Data::reflist(const std::string& theID)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
+    myAttrs.find(theID);
   if (aFound == myAttrs.end()) {
     // TODO: generate error on unknown attribute request and/or add mechanism for customization
     return boost::shared_ptr<ModelAPI_AttributeRefList>();
@@ -223,7 +272,8 @@ boost::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& t
 
 const std::string& Model_Data::id(const boost::shared_ptr<ModelAPI_Attribute>& theAttr)
 {
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = 
+    myAttrs.begin();
   for (; anAttr != myAttrs.end(); anAttr++) {
     if (anAttr->second == theAttr)
       return anAttr->first;
@@ -303,39 +353,67 @@ bool Model_Data::mustBeUpdated()
   return myLab.IsAttribute(kMustBeUpdatedGUID) == Standard_True;
 }
 
-bool Model_Data::referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+int Model_Data::featureId() const
+{
+  return myLab.Father().Tag(); // tag of the feature label
+}
+
+void Model_Data::eraseBackReferences()
 {
-  // collect results of this feature first to check references quickly in the cycle
-  std::set<ObjectPtr> aFeatureObjs;
-  aFeatureObjs.insert(theFeature);
-  std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter =
-    theFeature->results().cbegin();
-  for(; aRIter != theFeature->results().cend(); aRIter++) {
-    if (*aRIter)
-      aFeatureObjs.insert(*aRIter);
+  myRefsToMe.clear();
+  boost::shared_ptr<ModelAPI_Result> aRes = 
+    boost::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+  if (aRes)
+    aRes->setIsConcealed(false);
+}
+
+void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID)
+{
+  myRefsToMe.insert(theFeature->data()->attribute(theAttrID));
+  if (ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) {
+    boost::shared_ptr<ModelAPI_Result> aRes = 
+      boost::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+    if (aRes) {
+      aRes->setIsConcealed(true);
+    }
   }
+}
 
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter = 
-    myAttrs.begin();
-  for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
-    if (anAttrsIter->second->attributeType() == ModelAPI_AttributeRefAttr::type()) {
-      boost::shared_ptr<ModelAPI_AttributeRefAttr> aRefAttr = 
-        boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttrsIter->second);
-      if (aRefAttr && aRefAttr->isObject()) { // check referenced object
-        if (aFeatureObjs.find(aRefAttr->object()) != aFeatureObjs.end())
-          return true;
-      } else { // check object of referenced attribute
-        boost::shared_ptr<ModelAPI_Attribute> anAttr = aRefAttr->attr();
-        if (anAttr && aFeatureObjs.find(anAttr->owner()) != aFeatureObjs.end())
-          return true;
-      }
-    } else if (anAttrsIter->second->attributeType() == ModelAPI_AttributeReference::type()) {
-      boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
-        boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(anAttrsIter->second);
-      if (aFeatureObjs.find(aRef->value()) != aFeatureObjs.end()) {
-        return true;
+void Model_Data::referencesToObjects(
+  std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs)
+{
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
+  std::list<ObjectPtr> aReferenced; // not inside of cycle to avoid excess memory menagement
+  for(; anAttr != myAttrs.end(); anAttr++) {
+    std::string aType = anAttr->second->attributeType();
+    if (aType == ModelAPI_AttributeReference::type()) { // reference to object
+      boost::shared_ptr<ModelAPI_AttributeReference> aRef = boost::dynamic_pointer_cast<
+          ModelAPI_AttributeReference>(anAttr->second);
+      aReferenced.push_back(aRef->value());
+      theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+    } else if (aType == ModelAPI_AttributeRefAttr::type()) { // reference to attribute or object
+      boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = boost::dynamic_pointer_cast<
+          ModelAPI_AttributeRefAttr>(anAttr->second);
+      aReferenced.push_back(aRef->isObject() ? aRef->object() : aRef->attr()->owner());
+    } else if (aType == ModelAPI_AttributeRefList::type()) { // list of references
+      aReferenced = boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttr->second)->list();
+    } else if (aType == ModelAPI_AttributeSelection::type()) { // selection attribute
+      boost::shared_ptr<ModelAPI_AttributeSelection> aRef = boost::dynamic_pointer_cast<
+          ModelAPI_AttributeSelection>(anAttr->second);
+      aReferenced.push_back(aRef->context());
+      theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+    } else if (aType == ModelAPI_AttributeSelectionList::type()) { // list of selection attributes
+      boost::shared_ptr<ModelAPI_AttributeSelectionList> aRef = boost::dynamic_pointer_cast<
+          ModelAPI_AttributeSelectionList>(anAttr->second);
+      for(int a = aRef->size() - 1; a >= 0; a--) {
+        aReferenced.push_back(aRef->value(a)->context());
       }
+    } else
+      continue; // nothing to do, not reference
+
+    if (!aReferenced.empty()) {
+      theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+      aReferenced.clear();
     }
   }
-  return false;
 }
index 559fc12adb3444e4a31cc8e30fca673dd00db810..cb7158b75de28390da8316551c2dd3bfcfc26e1a 100644 (file)
@@ -26,6 +26,7 @@
 #include <map>
 #include <list>
 #include <string>
+#include <set>
 
 class ModelAPI_Attribute;
 
@@ -44,6 +45,9 @@ class Model_Data : public ModelAPI_Data
   /// needed here to emit signal that object changed on change of the attribute
   ObjectPtr myObject;
 
+  /// List of attributes referenced to owner (updated only during the transaction change)
+  std::set<AttributePtr> myRefsToMe;
+
   Model_Data();
 
   /// Returns label of this feature
@@ -53,9 +57,11 @@ class Model_Data : public ModelAPI_Data
   }
 
   friend class Model_Document;
+  friend class Model_Update;
   friend class Model_AttributeReference;
   friend class Model_AttributeRefAttr;
   friend class Model_AttributeRefList;
+  friend class Model_AttributeSelection;
 
  public:
   /// Returns the name of the feature visible by the user in the object browser
@@ -72,6 +78,12 @@ class Model_Data : public ModelAPI_Data
   /// Returns the attribute that contains reference to a feature
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeReference>
     reference(const std::string& theID);
+  /// Returns the attribute that contains selection to a shape
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection>
+    selection(const std::string& theID);
+  /// Returns the attribute that contains selection to a shape
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelectionList> 
+    selectionList(const std::string& theID);
   /// Returns the attribute that contains reference to an attribute of a feature
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
     refattr(const std::string& theID);
@@ -137,8 +149,19 @@ class Model_Data : public ModelAPI_Data
   /// Returns true if feature must be updated (re-executed) on rebuild
   MODEL_EXPORT virtual bool mustBeUpdated();
 
-  /// Returns true if this data attributes are referenced to the given feature or its results
-  MODEL_EXPORT virtual bool referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature);
+  /// Returns the identifier of feature-owner, unique in this document
+  MODEL_EXPORT virtual int featureId() const;
+
+private:
+  // removes all information about back references
+  void eraseBackReferences();
+  // adds a back reference (with identifier which attribute references to this object
+  void addBackReference(FeaturePtr theFeature, std::string theAttrID);
+  // returns all objects referenced to this
+  const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
+  // returns all references by attributes of this data
+  // \param the returned list of pairs: id of referenced attribute and list of referenced objects
+  void referencesToObjects(std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);
 };
 
 #endif
index e583a0fb8b1698aa71045bad491113ae302ebbff..cb05a7fbbf59b7af19f8125c262da3210faeafd9 100644 (file)
 #include <Model_ResultPart.h>
 #include <Model_ResultConstruction.h>
 #include <Model_ResultBody.h>
+#include <ModelAPI_Validator.h>
 #include <Events_Loop.h>
 #include <Events_Error.h>
 
 #include <TDataStd_Integer.hxx>
 #include <TDataStd_Comment.hxx>
-#include <TDataStd_UAttribute.hxx>
 #include <TDF_ChildIDIterator.hxx>
 #include <TDataStd_ReferenceArray.hxx>
 #include <TDataStd_HLabelArray1.hxx>
@@ -49,11 +49,10 @@ Model_Document::Model_Document(const std::string theID, const std::string theKin
     : myID(theID), myKind(theKind),
       myDoc(new TDocStd_Document("BinOcaf"))  // binary OCAF format
 {
-  myDoc->SetUndoLimit(UNDO_LIMIT);
+  myDoc->SetUndoLimit(UNDO_LIMIT);  
   myTransactionsAfterSave = 0;
   myNestedNum = -1;
   myExecuteFeatures = true;
-  //myDoc->SetNestedTransactionMode();
   // to have something in the document and avoid empty doc open/save problem
   // in transaction for nesting correct working
   myDoc->NewCommand();
@@ -148,7 +147,7 @@ bool Model_Document::load(const char* theFileName)
     myDoc->SetUndoLimit(UNDO_LIMIT);
     // to avoid the problem that feature is created in the current, not this, document
     Model_Session::get()->setActiveDocument(anApp->getDocument(myID));
-    synchronizeFeatures();
+    synchronizeFeatures(false, true);
   }
   return !isError;
 }
@@ -266,10 +265,12 @@ void Model_Document::finishOperation()
   if (!myDoc->HasOpenCommand() && myNestedNum != -1)
     boost::static_pointer_cast<Model_Session>(Model_Session::get())
         ->setCheckTransactions(false);  // for nested transaction commit
+  synchronizeBackRefs();
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
   if (!myDoc->HasOpenCommand() && myNestedNum != -1)
     boost::static_pointer_cast<Model_Session>(Model_Session::get())
@@ -287,7 +288,6 @@ void Model_Document::finishOperation()
     myIsEmptyTr[myTransactionsAfterSave] = !myDoc->CommitCommand();  // && (myNestedNum == -1);
     myTransactionsAfterSave++;
   }
-
 }
 
 void Model_Document::abortOperation()
@@ -306,7 +306,7 @@ void Model_Document::abortOperation()
       myNestedNum = -1;
     myDoc->AbortCommand();
   }
-  synchronizeFeatures(true);
+  synchronizeFeatures(true, false); // references were not changed since transaction start
   // abort for all subs
   std::set<std::string>::iterator aSubIter = mySubs.begin();
   for (; aSubIter != mySubs.end(); aSubIter++)
@@ -345,7 +345,7 @@ void Model_Document::undo()
     myNestedNum--;
   if (!myIsEmptyTr[myTransactionsAfterSave])
     myDoc->Undo();
-  synchronizeFeatures(true);
+  synchronizeFeatures(true, true);
   // undo for all subs
   std::set<std::string>::iterator aSubIter = mySubs.begin();
   for (; aSubIter != mySubs.end(); aSubIter++)
@@ -371,7 +371,7 @@ void Model_Document::redo()
   if (!myIsEmptyTr[myTransactionsAfterSave])
     myDoc->Redo();
   myTransactionsAfterSave++;
-  synchronizeFeatures(true);
+  synchronizeFeatures(true, true);
   // redo for all subs
   std::set<std::string>::iterator aSubIter = mySubs.begin();
   for (; aSubIter != mySubs.end(); aSubIter++)
@@ -469,16 +469,11 @@ void Model_Document::removeFeature(FeaturePtr theFeature, const bool theCheck)
     // check the feature: it must have no depended objects on it
     std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
     for(; aResIter != theFeature->results().cend(); aResIter++) {
-      if (myConcealedResults.find(*aResIter) != myConcealedResults.end()) {
-        Events_Error::send("Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
-        return;
-      }
-    }
-    NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator anObjIter(myObjs);
-    for(; anObjIter.More(); anObjIter.Next()) {
-      DataPtr aData = anObjIter.Value()->data();
-      if (aData->referencesTo(theFeature)) {
-        Events_Error::send("Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
+      boost::shared_ptr<Model_Data> aData = 
+        boost::dynamic_pointer_cast<Model_Data>((*aResIter)->data());
+      if (aData && !aData->refsToMe().empty()) {
+        Events_Error::send(
+          "Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
         return;
       }
     }
@@ -495,22 +490,11 @@ void Model_Document::removeFeature(FeaturePtr theFeature, const bool theCheck)
   // erase all attributes under the label of feature
   aFeatureLabel.ForgetAllAttributes();
   // remove it from the references array
-  RemoveFromRefArray(featuresLabel(), aFeatureLabel);
-
+  if (theFeature->isInHistory()) {
+    RemoveFromRefArray(featuresLabel(), aFeatureLabel);
+  }
   // event: feature is deleted
   ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
-  /* this is in "erase"
-  // results of this feature must be redisplayed
-  static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
-  std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
-  for (; aRIter != aResults.cend(); aRIter++) {
-    boost::shared_ptr<ModelAPI_Result> aRes = *aRIter;
-    aRes->setData(boost::shared_ptr<ModelAPI_Data>());  // deleted flag
-    ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
-    ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), aRes->groupName());
-  }
-  */
 }
 
 FeaturePtr Model_Document::feature(TDF_Label& theLabel)
@@ -592,9 +576,9 @@ ObjectPtr Model_Document::object(const std::string& theGroupID, const int theInd
       std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
       for (; aRIter != aResults.cend(); aRIter++) {
         if ((*aRIter)->groupName() != theGroupID) continue;
-        bool isIn = theHidden;
+        bool isIn = theHidden && (*aRIter)->isInHistory();
         if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
-          isIn = myConcealedResults.find(*aRIter) == myConcealedResults.end();
+          isIn = !(*aRIter)->isConcealed();
         }
         if (isIn) {
           if (anIndex == theIndex)
@@ -631,7 +615,7 @@ int Model_Document::size(const std::string& theGroupID, const bool theHidden)
         if ((*aRIter)->groupName() != theGroupID) continue;
         bool isIn = theHidden;
         if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
-          isIn = myConcealedResults.find(*aRIter) == myConcealedResults.end();
+          isIn = !(*aRIter)->isConcealed();
         }
         if (isIn)
           aResult++;
@@ -666,12 +650,12 @@ void Model_Document::setUniqueName(FeaturePtr theFeature)
   // check this is unique, if not, increase index by 1
   for (aFIter.Initialize(myObjs); aFIter.More();) {
     FeaturePtr aFeature = aFIter.Value();
-    bool isSameName = aFeature->isInHistory() && aFeature->data()->name() == aName;
+    bool isSameName = aFeature->data()->name() == aName;
     if (!isSameName) {  // check also results to avoid same results names (actual for Parts)
       const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
       std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
       for (; aRIter != aResults.cend(); aRIter++) {
-        isSameName = (*aRIter)->isInHistory() && (*aRIter)->data()->name() == aName;
+        isSameName = (*aRIter)->data()->name() == aName;
       }
     }
     if (isSameName) {
@@ -703,7 +687,7 @@ void Model_Document::initData(ObjectPtr theObj, TDF_Label theLab, const int theT
   }
 }
 
-void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
+void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences)
 {
   boost::shared_ptr<ModelAPI_Document> aThis = 
     Model_Application::getApplication()->getDocument(myID);
@@ -787,6 +771,10 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
       aFIter.Next();
   }
 
+  if (theUpdateReferences) {
+    synchronizeBackRefs();
+  }
+
   myExecuteFeatures = false;
   aLoop->activateFlushes(true);
 
@@ -796,11 +784,74 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
     aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
   }
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
   boost::static_pointer_cast<Model_Session>(Model_Session::get())
     ->setCheckTransactions(true);
   myExecuteFeatures = true;
 }
 
+void Model_Document::synchronizeBackRefs()
+{
+  boost::shared_ptr<ModelAPI_Document> aThis = 
+    Model_Application::getApplication()->getDocument(myID);
+  // keeps the concealed flags of result to catch the change and create created/deleted events
+  std::list<std::pair<ResultPtr, bool> > aConcealed;
+  // first cycle: erase all data about back-references
+  NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFeatures(myObjs);
+  for(; aFeatures.More(); aFeatures.Next()) {
+    FeaturePtr aFeature = aFeatures.Value();
+    boost::shared_ptr<Model_Data> aFData = 
+      boost::dynamic_pointer_cast<Model_Data>(aFeature->data());
+    if (aFData) {
+      aFData->eraseBackReferences();
+    }
+    const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
+    std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+    for (; aRIter != aResults.cend(); aRIter++) {
+      boost::shared_ptr<Model_Data> aResData = 
+        boost::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
+      if (aResData) {
+        aConcealed.push_back(std::pair<ResultPtr, bool>(*aRIter, (*aRIter)->isConcealed()));
+        aResData->eraseBackReferences();
+      }
+    }
+  }
+
+  // second cycle: set new back-references: only features may have reference, iterate only them
+  ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+  for(aFeatures.Initialize(myObjs); aFeatures.More(); aFeatures.Next()) {
+    FeaturePtr aFeature = aFeatures.Value();
+    boost::shared_ptr<Model_Data> aFData = 
+      boost::dynamic_pointer_cast<Model_Data>(aFeature->data());
+    if (aFData) {
+      std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
+      aFData->referencesToObjects(aRefs);
+      std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRefsIter = aRefs.begin();
+      for(; aRefsIter != aRefs.end(); aRefsIter++) {
+        std::list<ObjectPtr>::iterator aRefTo = aRefsIter->second.begin();
+        for(; aRefTo != aRefsIter->second.end(); aRefTo++) {
+          if (*aRefTo) {
+            boost::shared_ptr<Model_Data> aRefData = 
+              boost::dynamic_pointer_cast<Model_Data>((*aRefTo)->data());
+            aRefData->addBackReference(aFeature, aRefsIter->first); // here the Concealed flag is updated
+          }
+        }
+      }
+    }
+  }
+  std::list<std::pair<ResultPtr, bool> >::iterator aCIter = aConcealed.begin();
+  for(; aCIter != aConcealed.end(); aCIter++) {
+    if (aCIter->first->isConcealed() != aCIter->second) { // somethign is changed => produce event
+      if (aCIter->second) { // was concealed become not => creation event
+        static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+        ModelAPI_EventCreator::get()->sendUpdated(aCIter->first, anEvent);
+      } else { // was not concealed become concealed => delete event
+        ModelAPI_EventCreator::get()->sendDeleted(aThis, aCIter->first->groupName());
+      }
+    }
+  }
+}
+
 TDF_Label Model_Document::resultLabel(
   const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theResultIndex) 
 {
@@ -822,15 +873,11 @@ void Model_Document::storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData
   }
 }
 
-static const Standard_GUID ID_CONSTRUCTION("b59fa408-8ab1-42b8-980c-af5adeebe7e4");
-static const Standard_GUID ID_BODY("c1148e9a-9b17-4e9c-9160-18e918fd0013");
-static const Standard_GUID ID_PART("1b3319b9-3e0a-4298-a1dc-3fb5aaf9be59");
-
 boost::shared_ptr<ModelAPI_ResultConstruction> Model_Document::createConstruction(
     const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
 {
   TDF_Label aLab = resultLabel(theFeatureData, theIndex);
-  TDataStd_UAttribute::Set(aLab, ID_CONSTRUCTION);
+  TDataStd_Comment::Set(aLab, ModelAPI_ResultConstruction::group().c_str());
   ObjectPtr anOldObject = object(aLab);
   boost::shared_ptr<ModelAPI_ResultConstruction> aResult;
   if (anOldObject) {
@@ -847,7 +894,7 @@ boost::shared_ptr<ModelAPI_ResultBody> Model_Document::createBody(
     const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
 {
   TDF_Label aLab = resultLabel(theFeatureData, theIndex);
-  TDataStd_UAttribute::Set(aLab, ID_BODY);
+  TDataStd_Comment::Set(aLab, ModelAPI_ResultBody::group().c_str());
   ObjectPtr anOldObject = object(aLab);
   boost::shared_ptr<ModelAPI_ResultBody> aResult;
   if (anOldObject) {
@@ -864,7 +911,7 @@ boost::shared_ptr<ModelAPI_ResultPart> Model_Document::createPart(
     const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
 {
   TDF_Label aLab = resultLabel(theFeatureData, theIndex);
-  TDataStd_UAttribute::Set(aLab, ID_PART);
+  TDataStd_Comment::Set(aLab, ModelAPI_ResultPart::group().c_str());
   ObjectPtr anOldObject = object(aLab);
   boost::shared_ptr<ModelAPI_ResultPart> aResult;
   if (anOldObject) {
@@ -916,12 +963,16 @@ void Model_Document::updateResults(FeaturePtr theFeature)
     ResultPtr aNewBody;
     if (aResSize <= aResIndex) {
       TDF_Label anArgLab = aLabIter.Value();
-      if (anArgLab.IsAttribute(ID_BODY)) {
-        aNewBody = createBody(theFeature->data(), aResIndex);
-      } else if (anArgLab.IsAttribute(ID_PART)) {
-        aNewBody = createPart(theFeature->data(), aResIndex);
-      } else if (!anArgLab.IsAttribute(ID_CONSTRUCTION) && anArgLab.FindChild(1).HasAttribute()) {
-        Events_Error::send("Unknown type of result is found in the document");
+      Handle(TDataStd_Comment) aGroup;
+      if (anArgLab.FindAttribute(TDataStd_Comment::GetID(), aGroup)) {
+        if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) {
+          aNewBody = createBody(theFeature->data(), aResIndex);
+        } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) {
+          aNewBody = createPart(theFeature->data(), aResIndex);
+        } else if (aGroup->Get() != ModelAPI_ResultConstruction::group().c_str()) {
+          Events_Error::send(std::string("Unknown type of result is found in the document:") +
+            TCollection_AsciiString(aGroup->Get()).ToCString());
+        }
       }
       if (aNewBody) {
         theFeature->setResult(aNewBody, aResIndex);
@@ -930,48 +981,6 @@ void Model_Document::updateResults(FeaturePtr theFeature)
   }
 }
 
-void Model_Document::objectIsReferenced(const ObjectPtr& theObject)
-{
-  // only bodies are concealed now
-  ResultBodyPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
-  if (aResult) {
-    if (myConcealedResults.find(aResult) != myConcealedResults.end()) {
-      Events_Error::send(std::string("The object '") + aResult->data()->name() +
-        "' is already referenced");
-    } else {
-      myConcealedResults.insert(aResult);
-      boost::shared_ptr<ModelAPI_Document> aThis = 
-        Model_Application::getApplication()->getDocument(myID);
-      ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_ResultBody::group());
-
-      static Events_Loop* aLoop = Events_Loop::loop();
-      static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-      static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
-      aECreator->sendUpdated(aResult, EVENT_DISP);
-    }
-  }
-}
-
-void Model_Document::objectIsNotReferenced(const ObjectPtr& theObject)
-{
-  // only bodies are concealed now
-  ResultBodyPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
-  if (aResult) {
-    std::set<ResultPtr>::iterator aFind = myConcealedResults.find(aResult);
-    if (aFind != myConcealedResults.end()) {
-      ResultPtr aFeature = *aFind;
-      myConcealedResults.erase(aFind);
-      boost::shared_ptr<ModelAPI_Document> aThis = 
-        Model_Application::getApplication()->getDocument(myID);
-      static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
-      ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent, false);
-    } else {
-      Events_Error::send(std::string("The object '") + aResult->data()->name() +
-        "' was not referenced '");
-    }
-  }
-}
-
 Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper)
 {
   return TDF_LabelMapHasher::HashCode(theLab, theUpper);
index 6f813bd231da45a6b72917c1b7cb508605c3259f..cbea4a19e58826dd8c9148f0e33679ccea3b60d8 100644 (file)
@@ -130,12 +130,6 @@ class Model_Document : public ModelAPI_Document
   ///! On abort, undo or redo it is not necessary: results in document are updated automatically
   bool executeFeatures() {return myExecuteFeatures;}
 
-  ///! Reutrns true is result was conecaled because of usage it by other object
-  virtual bool isConcealed(const boost::shared_ptr<ModelAPI_Object>& theResult) {
-    return myConcealedResults.find(boost::dynamic_pointer_cast<ModelAPI_Result>(theResult))
-      != myConcealedResults.end();
-  }
-
  protected:
 
   //! Returns (creates if needed) the features label
@@ -146,7 +140,11 @@ class Model_Document : public ModelAPI_Document
   void setUniqueName(FeaturePtr theFeature);
 
   //! Synchronizes myFeatures list with the updated document
-  void synchronizeFeatures(const bool theMarkUpdated = false);
+  //! \param theMarkUpdated causes the "update" event for all features
+  //! \param theUpdateReferences causes the update of back-references
+  void synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences);
+  //! Synchronizes the BackReferences list in Data of Features and Results
+  void synchronizeBackRefs();
 
   //! Creates new document with binary file format
   Model_Document(const std::string theID, const std::string theKind);
@@ -174,11 +172,6 @@ class Model_Document : public ModelAPI_Document
   //! Updates the results list of the feature basing on the current data tree
   void updateResults(FeaturePtr theFeature);
 
-  //! Stores information that there is a reference to this object
-  void objectIsReferenced(const ObjectPtr& theObject);
-  //! Removes information that there is a reference to this object
-  void objectIsNotReferenced(const ObjectPtr& theObject);
-
   //! Returns all sub documents
   const std::set<std::string>& subDocuments() const {return mySubs;}
 
@@ -198,8 +191,6 @@ class Model_Document : public ModelAPI_Document
   /// All features managed by this document (not only in history of OB)
   /// For optimization mapped by labels
   NCollection_DataMap<TDF_Label, FeaturePtr> myObjs;
-  /// Results that are referenced and must be concealed for object browser
-  std::set<ResultPtr> myConcealedResults;
 
   ///< set of identifiers of sub-documents of this document
   std::set<std::string> mySubs;
index 967265f837880942854bc7446676a9b3eac60073..ce342c2e99a07a647388c2d6099a8079b6a75edb 100644 (file)
@@ -7,10 +7,17 @@
 #include <TNaming_Builder.hxx>
 #include <TNaming_NamedShape.hxx>
 #include <TopoDS_Shape.hxx>
+#include <TDF_ChildIterator.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopExp_Explorer.hxx>
 #include <GeomAPI_Shape.h>
-
+#include <GeomAlgoAPI_MakeShape.h>
+// DEB
+//#include <TCollection_AsciiString.hxx>
+//#include <TDF_Tool.hxx>
 Model_ResultBody::Model_ResultBody()
 {
+  setIsConcealed(false);
 }
 
 void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
@@ -18,7 +25,9 @@ void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
   boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
   if (aData) {
     TDF_Label& aShapeLab = aData->shapeLab();
-    // TODO: to add the naming mechanism for shape storage in the next iteration
+    // clean builders
+    clean();   
+    // store the new shape as primitive
     TNaming_Builder aBuilder(aShapeLab);
     if (!theShape)
       return;  // bad shape
@@ -30,6 +39,50 @@ void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
   }
 }
 
+void Model_ResultBody::storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+                                         const boost::shared_ptr<GeomAPI_Shape>& theToShape)
+{
+  boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+  if (aData) {
+    TDF_Label& aShapeLab = aData->shapeLab();
+    // clean builders
+    clean();   
+    // store the new shape as primitive
+    TNaming_Builder aBuilder(aShapeLab);
+    if (!theFromShape || !theToShape)
+      return;  // bad shape
+    TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
+    if (aShapeBasis.IsNull())
+      return;  // null shape inside
+       TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
+    if (aShapeNew.IsNull())
+      return;  // null shape inside
+    aBuilder.Generated(aShapeBasis, aShapeNew);
+  }
+}
+
+void Model_ResultBody::storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+                                         const boost::shared_ptr<GeomAPI_Shape>& theNewShape)
+{
+  boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+  if (aData) {
+    TDF_Label& aShapeLab = aData->shapeLab();
+    // clean builders
+    clean();   
+    // store the new shape as primitive
+    TNaming_Builder aBuilder(aShapeLab);
+    if (!theOldShape || !theNewShape)
+      return;  // bad shape
+    TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
+    if (aShapeOld.IsNull())
+      return;  // null shape inside
+       TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
+    if (aShapeNew.IsNull())
+      return;  // null shape inside
+    aBuilder.Generated(aShapeOld, aShapeNew);
+  }
+}
+
 boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
 {
   boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
@@ -52,3 +105,140 @@ boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
 {
   return myOwner;
 }
+
+void Model_ResultBody::clean()
+{
+  std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
+  for(; aBuilder != myBuilders.end(); aBuilder++)
+    delete *aBuilder;
+}
+
+Model_ResultBody::~Model_ResultBody()
+{
+  clean();
+}
+
+TNaming_Builder* Model_ResultBody::builder(const int theTag)
+{
+  if (myBuilders.size() <= (unsigned int)theTag) {
+    myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
+  }
+  if (!myBuilders[theTag]) {
+    boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+    myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
+       //TCollection_AsciiString entry;//
+       //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
+       //cout << "Label = " <<entry.ToCString() <<endl;
+  }
+  return myBuilders[theTag];
+}
+
+void Model_ResultBody::generated(
+  const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
+{
+  TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
+  builder(theTag)->Generated(aShape);
+}
+
+void Model_ResultBody::generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+    const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
+{
+  TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
+  TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
+  builder(theTag)->Generated(anOldShape, aNewShape);
+}
+
+
+void Model_ResultBody::modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+    const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
+{
+  TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
+  TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
+  builder(theTag)->Modify(anOldShape, aNewShape);
+}
+
+void Model_ResultBody::deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+    const int theTag)
+{
+  TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
+  builder(theTag)->Delete(aShape);
+}
+
+void Model_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag)
+{
+  TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
+  TopTools_MapOfShape aView;
+  TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
+  for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
+    const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
+    if (!aView.Add(aRoot)) continue;
+       boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
+       aRShape->setImpl((new TopoDS_Shape(aRoot)));
+    if (theMS->isDeleted (aRShape)) {
+               builder(theTag)->Delete(aRoot);
+    }
+  }
+}
+
+void Model_ResultBody::loadAndOrientModifiedShapes (
+                                                  GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag,
+                                               GeomAPI_DataMapOfShapeShape& theSubShapes)
+{
+  TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
+  TopTools_MapOfShape aView;
+  TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
+  for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+    const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
+    if (!aView.Add(aRoot)) continue;
+       ListOfShape aList;
+       boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
+       aRShape->setImpl((new TopoDS_Shape(aRoot)));
+       theMS->generated(aRShape, aList);
+       std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
+    for (; anIt != aLast; anIt++) {
+      TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();    
+         if (theSubShapes.isBound(*anIt)) {
+               boost::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
+               aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
+      }
+      if (!aRoot.IsSame (aNewShape)) 
+                 builder(theTag)->Modify(aRoot,aNewShape);
+    }
+  }
+}
+
+void Model_ResultBody::loadAndOrientGeneratedShapes (
+                                                  GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag,
+                                               GeomAPI_DataMapOfShapeShape& theSubShapes)
+{
+  TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
+  TopTools_MapOfShape aView;
+  TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
+  for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+    const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
+    if (!aView.Add(aRoot)) continue;
+       ListOfShape aList;
+       boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
+       aRShape->setImpl((new TopoDS_Shape(aRoot)));
+       theMS->generated(aRShape, aList);
+       std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
+    for (; anIt != aLast; anIt++) {
+      TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();    
+         if (theSubShapes.isBound(*anIt)) {
+               boost::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
+               aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
+      }
+      if (!aRoot.IsSame (aNewShape)) 
+                 builder(theTag)->Generated(aRoot,aNewShape);
+    }
+  }
+}
\ No newline at end of file
index 08ce28ab0cd88aafb8226f1b7cccc4d0a4903671..340b35bb515e9699b244f69d22680eb7acd2cebe 100644 (file)
@@ -7,6 +7,11 @@
 
 #include "Model.h"
 #include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <vector>
+
+class TNaming_Builder;
 
 /**\class ModelAPI_ResultBody
  * \ingroup DataModel
 class Model_ResultBody : public ModelAPI_ResultBody
 {
   boost::shared_ptr<ModelAPI_Feature> myOwner;  ///< owner of this result
- public:
+  /// builders that tores the naming history: one per label to allow store several shapes to one 
+  /// label; index in vector corresponds to the label tag
+  std::vector<TNaming_Builder*> myBuilders;
+public:
   /// Stores the shape (called by the execution method).
   MODEL_EXPORT virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape);
+
+  /// Stores the generated shape (called by the execution method).
+  MODEL_EXPORT virtual void storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+                                              const boost::shared_ptr<GeomAPI_Shape>& theToShape);
+
+  /// Stores the modified shape (called by the execution method).
+  MODEL_EXPORT virtual void storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+                                              const boost::shared_ptr<GeomAPI_Shape>& theNewShape);
+
   /// Returns the shape-result produced by this feature
   MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape();
   /// Returns the source feature of this result
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> owner();
 
- protected:
+  /// Records the subshape newShape which was generated during a topological construction.
+  /// As an example, consider the case of a face generated in construction of a box.
+  MODEL_EXPORT virtual void generated(const boost::shared_ptr<GeomAPI_Shape>& theNewShape, 
+    const int theTag = 1);
+
+  /// Records the shape newShape which was generated from the shape oldShape during a topological 
+  /// construction. As an example, consider the case of a face generated from an edge in 
+  /// construction of a prism.
+  MODEL_EXPORT virtual void generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+    const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1);
+
+
+  /// Records the shape newShape which is a modification of the shape oldShape.
+  /// As an example, consider the case of a face split or merged in a Boolean operation.
+  MODEL_EXPORT virtual void modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+    const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1);
+
+  /// Records the shape oldShape which was deleted from the current label.
+  /// As an example, consider the case of a face removed by a Boolean operation.
+  MODEL_EXPORT virtual void deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+    const int theTag = 1);
+
+  /// load deleted shapes
+  MODEL_EXPORT virtual void loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag);
+  /// load and orient modified shapes
+  MODEL_EXPORT virtual void loadAndOrientModifiedShapes (
+                                                  GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag,
+                                               GeomAPI_DataMapOfShapeShape& theSubShapes);
+   /// load and orient generated shapes
+  MODEL_EXPORT virtual void loadAndOrientGeneratedShapes (
+                                                  GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag,
+                                               GeomAPI_DataMapOfShapeShape& theSubShapes);
+
+  /// Removes the stored builders
+  MODEL_EXPORT virtual ~Model_ResultBody();
+
+protected:
   /// Makes a body on the given feature
   Model_ResultBody();
 
+  /// Removes the stored builders
+  void clean();
+
+  /// Returns (creates if necessary) the builder created on the needed tag of sub-label
+  TNaming_Builder* builder(const int theTag);
+
   friend class Model_Document;
 };
 
index 0b6d56612c64ffd89b2e735e8f45f67788a29f97..8af38252d8805c917b64bb5b34ace6b63ed55860 100644 (file)
@@ -17,6 +17,7 @@ boost::shared_ptr<GeomAPI_Shape>& Model_ResultConstruction::shape()
 Model_ResultConstruction::Model_ResultConstruction()
 {
   myIsInHistory = true;
+  setIsConcealed(false);
 }
 
 void Model_ResultConstruction::setIsInHistory(const bool isInHistory)
index 98319c4749f33fc524bba9e5ee00662d21a87043..a1fb09b010ff87b8cbbc935e96201ebcbb7d1dfe 100644 (file)
@@ -19,6 +19,7 @@ boost::shared_ptr<ModelAPI_Feature> Model_ResultPart::owner()
 
 Model_ResultPart::Model_ResultPart()
 {
+  setIsConcealed(false);
 }
 
 void Model_ResultPart::setData(boost::shared_ptr<ModelAPI_Data> theData)
index 26c337e525de8663d092c2045aaf7244af06cc54..a42eb204696b7283251aae226a13b145bf6cc8e0 100644 (file)
@@ -103,7 +103,7 @@ FeaturePtr Model_Session::createFeature(string theFeatureID)
     std::pair<std::string, std::string>& aPlugin = myPlugins[theFeatureID]; // plugin and doc kind
     if (!aPlugin.second.empty() && aPlugin.second != activeDocument()->kind()) {
       Events_Error::send(
-          string("Feature '") + theFeatureID + "' can not be created in document '"
+          string("Feature '") + theFeatureID + "' can be created only in document '"
               + aPlugin.second + "' by the XML definition");
       return FeaturePtr();
     }
@@ -202,7 +202,7 @@ boost::shared_ptr<ModelAPI_Document> Model_Session::copy(
   aRT->SetRelocation(aSourceRoot, aTargetRoot);
   TDF_CopyTool::Copy(aDS, aRT);
 
-  aNew->synchronizeFeatures();
+  aNew->synchronizeFeatures(false, true);
   return aNew;
 }
 
index 9ddd9f8e63d8e6847fa8f5ef1d90122bd0fcf325..c6a669718b51b5456b35293d41880af09acfee91 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <Model_Update.h>
 #include <Model_Document.h>
+#include <Model_Data.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Session.h>
 #include <Events_Loop.h>
 #include <Events_LongOp.h>
 #include <Events_Error.h>
@@ -89,7 +94,7 @@ void Model_Update::processEvent(const boost::shared_ptr<Events_Message>& theMess
       aDocs = ModelAPI_Session::get()->allOpenedDocuments();
     }
   }
-  // collect all documents involved into the update
+  // collect all documents involved into the update process
   set<boost::shared_ptr<ModelAPI_Object> >::iterator aFIter = myInitial.begin();
   for (; aFIter != myInitial.end(); aFIter++) {
     aDocs.push_back((*aFIter)->document());
@@ -123,49 +128,32 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
   bool aMustbeUpdated = myInitial.find(theFeature) != myInitial.end();
   if (theFeature) {  // only real feature contains references to other objects
     if (theFeature->data()->mustBeUpdated()) aMustbeUpdated = true;
-    // references
-    list<boost::shared_ptr<ModelAPI_Attribute> > aRefs = theFeature->data()->attributes(
-        ModelAPI_AttributeReference::type());
-    list<boost::shared_ptr<ModelAPI_Attribute> >::iterator aRefsIter = aRefs.begin();
-    for (; aRefsIter != aRefs.end(); aRefsIter++) {
-      boost::shared_ptr<ModelAPI_Object> aSub = boost::dynamic_pointer_cast<
-          ModelAPI_AttributeReference>(*aRefsIter)->value();
-      if (updateObject(aSub)) {
-        aMustbeUpdated = true;
-      }
-    }
-    // reference to attribute or object
-    list<boost::shared_ptr<ModelAPI_Attribute> > aRefAttrs = theFeature->data()->attributes(
-        ModelAPI_AttributeRefAttr::type());
-    for (aRefsIter = aRefAttrs.begin(); aRefsIter != aRefAttrs.end(); aRefsIter++) {
-      boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
-        boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefsIter);
-      if (!aRef) continue;
-      if (aRef->isObject()) {
-        boost::shared_ptr<ModelAPI_Object> aSub = aRef->object();
-        if (updateObject(aSub)) {
-          aMustbeUpdated = true;
-        }
-      } else if (aRef->attr()) { // reference to the attribute
-        boost::shared_ptr<ModelAPI_Object> aSub = aRef->attr()->owner();
-        if (updateObject(aSub)) {
+
+    // composite feature must be executed after sub-features execution
+    CompositeFeaturePtr aComposite = 
+      boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
+    if (aComposite) {
+      int aSubsNum = aComposite->numberOfSubs();
+      for(int a = 0; a < aSubsNum; a++) {
+        if (updateFeature(aComposite->subFeature(a)))
           aMustbeUpdated = true;
-        }
       }
     }
-    // lists of references
-    aRefs = theFeature->data()->attributes(ModelAPI_AttributeRefList::type());
-    for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
-      list<ObjectPtr> aListRef = boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*aRefsIter)
-          ->list();
-      list<ObjectPtr>::iterator aListIter = aListRef.begin();
-      for (; aListIter != aListRef.end(); aListIter++) {
-        boost::shared_ptr<ModelAPI_Object> aSub = *aListIter;
-        if (updateObject(aSub)) {
+    // check all references: if referenced objects are updated, this object also must be updated
+    std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
+    boost::shared_ptr<Model_Data> aData = 
+      boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+    aData->referencesToObjects(aRefs);
+    std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRef = aRefs.begin();
+    for(; aRef != aRefs.end(); aRef++) {
+      std::list<ObjectPtr>::iterator aRefObj = aRef->second.begin();
+      for(; aRefObj != aRef->second.end(); aRefObj++) {
+        if (updateObject(*aRefObj)) {
           aMustbeUpdated = true;
         }
       }
     }
+
     // execute feature if it must be updated
     if (aMustbeUpdated) {
 
@@ -174,7 +162,26 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
         ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
         if (aFactory->validate(theFeature)) {
           if (isAutomatic || (myJustCreatedOrUpdated.find(theFeature) != myJustCreatedOrUpdated.end()) ||
-            !theFeature->isPersistentResult() /* execute quick, not persistent results */) {
+            !theFeature->isPersistentResult() /* execute quick, not persistent results */) 
+          {
+            // before execution update the selection attributes if any
+            list<AttributePtr> aRefs = 
+              theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+            list<AttributePtr>::iterator aRefsIter = aRefs.begin();
+            for (; aRefsIter != aRefs.end(); aRefsIter++) {
+              boost::shared_ptr<ModelAPI_AttributeSelection> aSel =
+                boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*aRefsIter);
+              aSel->update(); // this must be done on execution since it may be long operation
+            }
+            aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelectionList::type());
+            for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
+              boost::shared_ptr<ModelAPI_AttributeSelectionList> aSel =
+                boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*aRefsIter);
+              for(int a = aSel->size() - 1; a >= 0; a--) {
+                aSel->value(a)->update();
+              }
+            }
+            // execute in try-catch to avoid internal problems of the feature
             try {
               theFeature->execute();
             } catch(...) {
@@ -231,6 +238,11 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
 
 bool Model_Update::updateObject(boost::shared_ptr<ModelAPI_Object> theObject)
 {
+  if (myUpdated.find(theObject) != myUpdated.end())
+    return myUpdated[theObject];  // already processed
+  return myInitial.find(theObject) != myInitial.end();
+
+  /* remove algorithm for update of all features by dependencies tree
   if (!theObject)
     return false;
   FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
@@ -251,4 +263,5 @@ bool Model_Update::updateObject(boost::shared_ptr<ModelAPI_Object> theObject)
   if (myInitial.find(theObject) != myInitial.end())
     return true;
   return false;  // nothing is known
+  */
 }
index ee5ab1a9ccad2ed6178752e68faec45fa51bfbdb..eecd08b33013590344a004f9e794fc7a7031ac4a 100644 (file)
@@ -186,7 +186,7 @@ bool Model_ValidatorsFactory::validate(const boost::shared_ptr<ModelAPI_Feature>
     std::list<std::string>::iterator anAttrIter = aLtAttributes.begin();
     for (; anAttrIter != aLtAttributes.end(); anAttrIter++) {
       std::map<std::string, AttrValidators>::const_iterator anAttr = 
-        aFeatureIter->second.find(*anAttrIter);
+          aFeatureIter->second.find(*anAttrIter);
       if (anAttr != aFeatureIter->second.end()) {
         AttrValidators::const_iterator aValIter = anAttr->second.cbegin();
         for (; aValIter != anAttr->second.cend(); aValIter++) {
@@ -198,8 +198,8 @@ bool Model_ValidatorsFactory::validate(const boost::shared_ptr<ModelAPI_Feature>
             const ModelAPI_AttributeValidator* anAttrValidator = 
               dynamic_cast<const ModelAPI_AttributeValidator*>(aFound->second);
             if (anAttrValidator) {
-              if (!anAttrValidator->isValid(theFeature->data()->attribute(*anAttrIter),
-                aValIter->second)) {
+              AttributePtr anAttribute = theFeature->data()->attribute(*anAttrIter);
+              if (!anAttrValidator->isValid(anAttribute, aValIter->second)) {
                   return false;
               }
             }
@@ -211,8 +211,7 @@ bool Model_ValidatorsFactory::validate(const boost::shared_ptr<ModelAPI_Feature>
   return true;
 }
 
-void Model_ValidatorsFactory::registerNotObligatory(
-  std::string theFeature, std::string theAttribute) 
+void Model_ValidatorsFactory::registerNotObligatory(std::string theFeature, std::string theAttribute)
 {
   std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(kDefaultId);
   if (it != myIDs.end()) {
@@ -221,4 +220,22 @@ void Model_ValidatorsFactory::registerNotObligatory(
       aValidator->registerNotObligatory(theFeature, theAttribute);
     }
   }
-}
\ No newline at end of file
+}
+
+void Model_ValidatorsFactory::registerConcealment(std::string theFeature, std::string theAttribute)
+{
+  std::map<std::string, std::set<std::string> >::iterator aFind = myConcealed.find(theFeature);
+  if (aFind == myConcealed.end()) {
+    std::set<std::string> aNewSet;
+    aNewSet.insert(theAttribute);
+    myConcealed[theFeature] = aNewSet;
+  } else {
+    aFind->second.insert(theAttribute);
+  }
+}
+
+bool Model_ValidatorsFactory::isConcealed(std::string theFeature, std::string theAttribute)
+{
+  std::map<std::string, std::set<std::string> >::iterator aFind = myConcealed.find(theFeature);
+  return aFind != myConcealed.end() && aFind->second.find(theAttribute) != aFind->second.end();
+}
index 38d2d7bf5bca0b60b539bb4499000e0b7824c03c..5fa3a8a9004441d4e0000a4f9eff83f25de94df5 100644 (file)
@@ -32,6 +32,10 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
   std::map<std::string, AttrValidators> myFeatures;
   /// validators IDs and arguments by feature and attribute IDs
   std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
+  /// Stores the registered attributes that leads to the concealment of referenced objects in 
+  /// data tree. Map from feature kind to set of attribute IDs.
+  std::map<std::string, std::set<std::string> > myConcealed;
+
  public:
   /// Registers the instance of the validator by the ID
   MODEL_EXPORT virtual void registerValidator(const std::string& theID,
@@ -72,6 +76,13 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
   /// so, it is not needed for the standard validation mechanism
   virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
 
+  /// register that this attribute conceals in the object browser
+  /// all referenced features after execution
+  virtual void registerConcealment(std::string theFeature, std::string theAttribute);
+
+  /// Returns true that it was registered that attribute conceals the referenced result
+  virtual bool isConcealed(std::string theFeature, std::string theAttribute);
+
 protected:
   void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const;
   /// Get instance from Session
index 9af7ad47a800884d7d7d2a07fc99bdb01d9a12fa..0bfa08a58c57ad2e1486feafaa3df577f0cb887a 100644 (file)
@@ -8,6 +8,7 @@ SET(PROJECT_HEADERS
     ModelAPI_Session.h
     ModelAPI_Plugin.h
     ModelAPI_Feature.h
+    ModelAPI_CompositeFeature.h
     ModelAPI_Data.h
     ModelAPI_Object.h
     ModelAPI_Document.h
@@ -20,6 +21,8 @@ SET(PROJECT_HEADERS
     ModelAPI_AttributeRefList.h
     ModelAPI_AttributeBoolean.h
     ModelAPI_AttributeString.h
+    ModelAPI_AttributeSelection.h
+    ModelAPI_AttributeSelectionList.h
     ModelAPI_Events.h
     ModelAPI_Validator.h
     ModelAPI_FeatureValidator.h
@@ -53,6 +56,7 @@ INCLUDE_DIRECTORIES(
   ../Config 
   ../Events
   ../GeomAPI
+  ../GeomAlgoAPI
 )
 
 SET(CMAKE_SWIG_FLAGS "")
index 65f4b5ae539250b7bf024f5a34c75711a337f4d2..e7ecbed9b54758c10395535b35147c378e4a73f3 100644 (file)
@@ -9,6 +9,7 @@
   #include "ModelAPI_Object.h"
   #include "ModelAPI_Feature.h"
   #include "ModelAPI_Plugin.h"
+  #include "ModelAPI_CompositeFeature.h"
   #include "ModelAPI_Data.h"
   #include "ModelAPI_Attribute.h"
   #include "ModelAPI_AttributeDocRef.h"
@@ -17,6 +18,8 @@
   #include "ModelAPI_AttributeString.h"
   #include "ModelAPI_AttributeReference.h"
   #include "ModelAPI_AttributeRefAttr.h"
+  #include "ModelAPI_AttributeSelection.h"
+  #include "ModelAPI_AttributeSelectionList.h"
   #include "ModelAPI_Validator.h"
   #include "ModelAPI_AttributeRefList.h"
   #include "ModelAPI_AttributeBoolean.h"
   #include "ModelAPI_ResultBody.h"
   #include "ModelAPI_ResultPart.h"
   
-  template<class T> boost::shared_ptr<T> castTo(boost::shared_ptr<ModelAPI_Result> theObject) 
+  template<class T1, class T2> 
+  boost::shared_ptr<T1> boost_cast(boost::shared_ptr<T2> theObject)
   { 
-    return boost::dynamic_pointer_cast<T>(theObject); 
+    return boost::dynamic_pointer_cast<T1>(theObject); 
   }
   
-   
 %}
 
 // to avoid error on this
@@ -52,6 +55,7 @@
 %shared_ptr(ModelAPI_Object)
 // %shared_ptr(ModelAPI_Plugin)
 %shared_ptr(ModelAPI_Feature)
+%shared_ptr(ModelAPI_CompositeFeature)
 %shared_ptr(ModelAPI_Data)
 %shared_ptr(ModelAPI_Attribute)
 %shared_ptr(ModelAPI_AttributeDocRef)
@@ -62,6 +66,8 @@
 %shared_ptr(ModelAPI_AttributeRefAttr)
 %shared_ptr(ModelAPI_AttributeRefList)
 %shared_ptr(ModelAPI_AttributeBoolean)
+%shared_ptr(ModelAPI_AttributeSelection)
+%shared_ptr(ModelAPI_AttributeSelectionList)
 %shared_ptr(ModelAPI_Result)
 %shared_ptr(ModelAPI_ResultConstruction)
 %shared_ptr(ModelAPI_ResultBody)
@@ -76,6 +82,7 @@
 %include "ModelAPI_Object.h"
 %include "ModelAPI_Plugin.h"
 %include "ModelAPI_Feature.h"
+%include "ModelAPI_CompositeFeature.h"
 %include "ModelAPI_Data.h"
 %include "ModelAPI_Attribute.h"
 %include "ModelAPI_AttributeDocRef.h"
 %include "ModelAPI_AttributeString.h"
 %include "ModelAPI_AttributeReference.h"
 %include "ModelAPI_AttributeRefAttr.h"
-%include "ModelAPI_Validator.h"
+%include "ModelAPI_AttributeBoolean.h"
+%include "ModelAPI_AttributeSelection.h"
+%include "ModelAPI_AttributeSelectionList.h"
 %include "ModelAPI_AttributeRefList.h"
+%include "ModelAPI_Validator.h"
 %include "ModelAPI_Result.h"
 %include "ModelAPI_ResultConstruction.h"
 %include "ModelAPI_ResultBody.h"
 %include "ModelAPI_ResultPart.h"
-%include "ModelAPI_AttributeBoolean.h"
 
 %template(ObjectList) std::list<boost::shared_ptr<ModelAPI_Object> >;
 %template(ResultList) std::list<boost::shared_ptr<ModelAPI_Result> >;
 
-template<class T> boost::shared_ptr<T> castTo(boost::shared_ptr<ModelAPI_Result> theObject);
-%template(modelAPI_ResultConstruction) castTo<ModelAPI_ResultConstruction>;
-%template(modelAPI_ResultBody) castTo<ModelAPI_ResultBody>;
-%template(modelAPI_ResultPart) castTo<ModelAPI_ResultPart>;
+template<class T1, class T2> boost::shared_ptr<T1> boost_cast(boost::shared_ptr<T2> theObject);
+%template(modelAPI_CompositeFeature) boost_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
+%template(modelAPI_ResultConstruction) boost_cast<ModelAPI_ResultConstruction, ModelAPI_Result>;
+%template(modelAPI_ResultBody) boost_cast<ModelAPI_ResultBody, ModelAPI_Result>;
+%template(modelAPI_ResultPart) boost_cast<ModelAPI_ResultPart, ModelAPI_Result>;
+
+
index c54b395561b908739737abb7ba47674b92e11f43..cfef5172421791a08ebd6958ca018a3000be1378 100644 (file)
@@ -23,6 +23,8 @@ class ModelAPI_Attribute
   // accessible from the attributes
   bool myIsInitialized;
   bool myIsArgument;
+  bool myIsImmutable;
+
  public:
 
   /// Returns the type of this class of attributes, not static method
@@ -70,12 +72,29 @@ class ModelAPI_Attribute
     return myIsArgument;
   }
 
+  /// Immutable argument can not be changed programaticaly (e.g. by constraint)
+  /// By default it is false.
+  /// Returns the previous state of the attribute's immutability.
+  MODELAPI_EXPORT bool setImmutable(const bool theFlag)
+  {
+    bool aResult = myIsImmutable;
+    myIsImmutable = theFlag;
+    return aResult;
+  }
+
+  /// Returns true if can not be changed programaticaly
+  MODELAPI_EXPORT bool isImmutable()
+  {
+    return myIsImmutable;
+  }
+
  protected:
   /// Objects are created for features automatically
   ModelAPI_Attribute()
   {
     myIsInitialized = false;
     myIsArgument = true;
+    myIsImmutable = false;
   }
 
 };
index dcd76efc7a9b7184de03fe8cbcf42c25899f0ab8..cf431322bf298de5b87f8aea74aa707746ad4c43 100644 (file)
@@ -45,4 +45,6 @@ class ModelAPI_AttributeBoolean : public ModelAPI_Attribute
   }
 };
 
+typedef boost::shared_ptr<ModelAPI_AttributeBoolean> AttributeBooleanPtr;
+
 #endif
index 7ee1ff1ca0477a790475474e05c6aea5bd620d54..cf7cc84f379c0f8cab8cb209312d4034fd8a3c06 100644 (file)
@@ -46,4 +46,6 @@ class ModelAPI_AttributeDocRef : public ModelAPI_Attribute
   }
 };
 
+typedef boost::shared_ptr<ModelAPI_AttributeDocRef> AttributeDocRefPtr;
+
 #endif
index dc862f3a63d37bda21f87d2fb6fcd6f1ecedfd24..a3bf80601bbac2ade06f79d8de8f621b32b2276b 100644 (file)
@@ -56,4 +56,6 @@ class ModelAPI_AttributeRefAttr : public ModelAPI_Attribute
   }
 };
 
+typedef boost::shared_ptr<ModelAPI_AttributeRefAttr> AttributeRefAttrPtr;
+
 #endif
index b8b5c700ba1346b80213fa587d70c68c54692408..d8edfe8d0bfdb1a4d8411512cc6b1823e3fdabda 100644 (file)
@@ -36,11 +36,14 @@ class ModelAPI_AttributeRefList : public ModelAPI_Attribute
   MODELAPI_EXPORT virtual void remove(ObjectPtr theObject) = 0;
 
   /// Returns number of features in the list
-  MODELAPI_EXPORT virtual int size() = 0;
+  MODELAPI_EXPORT virtual int size() const = 0;
 
   /// Returns the list of features
   MODELAPI_EXPORT virtual std::list<ObjectPtr> list() = 0;
 
+ /// Returns the referenced object by the zero-based index
+  MODELAPI_EXPORT virtual ObjectPtr object(const int theIndex) const = 0;
+
  protected:
   /// Objects are created for features automatically
   MODELAPI_EXPORT ModelAPI_AttributeRefList()
@@ -48,4 +51,6 @@ class ModelAPI_AttributeRefList : public ModelAPI_Attribute
   }
 };
 
+typedef boost::shared_ptr<ModelAPI_AttributeRefList> AttributeRefListPtr;
+
 #endif
index 14d63ae32551893516dcd42ab8b0b3df4faf0fc9..5354e8af54a15214a9d8ee3d76873107b4a65286 100644 (file)
@@ -46,4 +46,6 @@ class ModelAPI_AttributeReference : public ModelAPI_Attribute
   }
 };
 
+typedef boost::shared_ptr<ModelAPI_AttributeReference> AttributeReferencePtr;
+
 #endif
diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h
new file mode 100644 (file)
index 0000000..40882dd
--- /dev/null
@@ -0,0 +1,60 @@
+// File:        ModelAPI_AttributeSelection.h
+// Created:     2 Oct 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef ModelAPI_AttributeSelection_H_
+#define ModelAPI_AttributeSelection_H_
+
+#include "ModelAPI_Attribute.h"
+#include <ModelAPI_Result.h>
+
+/**\class ModelAPI_AttributeSelection
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
+ */
+
+class ModelAPI_AttributeSelection : public ModelAPI_Attribute
+{
+ public:
+  /// Defines the result and its selected sub-shape
+  virtual void setValue(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
+
+  /// Returns the selected subshape
+  virtual boost::shared_ptr<GeomAPI_Shape> value() = 0;
+
+  /// Returns the context of the selection (the whole shape owner)
+  virtual ResultPtr context() = 0;
+
+  /// Updates the underlied selection due to the changes in the referenced objects
+  /// \returns false if update is failed
+  virtual bool update() = 0;
+
+  /// Returns the type of this class of attributes
+  static std::string type()
+  {
+    return "Selection";
+  }
+
+  /// Returns the type of this class of attributes, not static method
+  virtual std::string attributeType()
+  {
+    return type();
+  }
+
+  /// To virtually destroy the fields of successors
+  virtual ~ModelAPI_AttributeSelection()
+  {
+  }
+
+ protected:
+  /// Objects are created for features automatically
+  MODELAPI_EXPORT ModelAPI_AttributeSelection()
+  {
+  }
+};
+
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeSelection> AttributeSelectionPtr;
+
+#endif
diff --git a/src/ModelAPI/ModelAPI_AttributeSelectionList.h b/src/ModelAPI/ModelAPI_AttributeSelectionList.h
new file mode 100644 (file)
index 0000000..6dc13dd
--- /dev/null
@@ -0,0 +1,60 @@
+// File:        ModelAPI_AttributeSelectionList.h
+// Created:     22 Oct 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef ModelAPI_AttributeSelectionList_H_
+#define ModelAPI_AttributeSelectionList_H_
+
+#include "ModelAPI_AttributeSelection.h"
+#include <ModelAPI_Result.h>
+
+/**\class ModelAPI_AttributeSelectionList
+ * \ingroup DataModel
+ * \brief Attribute that contains list of references to the sub-shapes with
+ * possibility to manage them.
+ */
+
+class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
+{
+ public:
+  /// Adds the new reference to the end of the list
+  virtual void append(
+    const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
+
+  /// Returns the number ofselection attributes in the list
+  virtual int size() = 0;
+
+  /// Returns the attribute selection by the index (zero based)
+  virtual boost::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex) = 0;
+
+  /// Returns all attributes
+  virtual void clear() = 0;
+
+  /// Returns the type of this class of attributes
+  static std::string type()
+  {
+    return "SelectionList";
+  }
+
+  /// Returns the type of this class of attributes, not static method
+  virtual std::string attributeType()
+  {
+    return type();
+  }
+
+  /// To virtually destroy the fields of successors
+  virtual ~ModelAPI_AttributeSelectionList()
+  {
+  }
+
+ protected:
+  /// Objects are created for features automatically
+  MODELAPI_EXPORT ModelAPI_AttributeSelectionList()
+  {
+  }
+};
+
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeSelectionList> AttributeSelectionListPtr;
+
+#endif
index 63a1b9e6fb8e8e103e5a73b3a50b220f086acf08..aa0680cbb5311c5939590d570595af06697c7765 100644 (file)
@@ -17,8 +17,8 @@ public:
   //! returns true if attribute is valid
   //! \param theAttribute the checked attribute
   //! \param theArguments arguments of the attribute
-  virtual bool isValid(
-    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const = 0;
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments) const = 0;
 };
 
 #endif
diff --git a/src/ModelAPI/ModelAPI_CompositeFeature.h b/src/ModelAPI/ModelAPI_CompositeFeature.h
new file mode 100644 (file)
index 0000000..878ca84
--- /dev/null
@@ -0,0 +1,38 @@
+// File:        ModelAPI_CompositeFeature.hxx
+// Created:     20 Oct 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef ModelAPI_CompositeFeature_H_
+#define ModelAPI_CompositeFeature_H_
+
+#include "ModelAPI_Feature.h"
+
+/**\class ModelAPI_CompositeFeature
+ * \ingroup DataModel
+ * \brief Feature that consists of other features: like sketcher
+ * with edges inside. It just allows t oadd a feature to this feature only
+ * instead of adding in both document and this feature.
+ */
+class ModelAPI_CompositeFeature : public ModelAPI_Feature
+{
+public:
+  /// Adds feature to the sketch and to its document
+  virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
+
+  /// Returns the number of sub-elements
+  virtual int numberOfSubs() const = 0;
+
+  /// Returns the sub-feature by zero-base index
+  virtual boost::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex) const = 0;
+
+  /// Returns the sub-feature unique identifier in this composite feature by zero-base index
+  virtual int subFeatureId(const int theIndex) const = 0;
+
+  /// Returns true if feature or reuslt belong to this composite feature as subs
+  virtual bool isSub(ObjectPtr theObject) const = 0;
+};
+
+//! Pointer on the composite feature object
+typedef boost::shared_ptr<ModelAPI_CompositeFeature> CompositeFeaturePtr;
+
+#endif
index 1265a51bd2a08738bfa1c14a1559d9d18c585873..2acf4fc6bf2cc264c2123d1c2094aa2f11119c6a 100644 (file)
@@ -21,6 +21,8 @@ class ModelAPI_AttributeString;
 class ModelAPI_Document;
 class ModelAPI_Attribute;
 class ModelAPI_Feature;
+class ModelAPI_AttributeSelection;
+class ModelAPI_AttributeSelectionList;
 class GeomAPI_Shape;
 
 /**\class ModelAPI_Data
@@ -47,6 +49,11 @@ class MODELAPI_EXPORT ModelAPI_Data
   virtual boost::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
   /// Returns the attribute that contains reference to a feature
   virtual boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
+  /// Returns the attribute that contains selection to a shape
+  virtual boost::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
+  /// Returns the attribute that contains selection to a shape
+  virtual boost::shared_ptr<ModelAPI_AttributeSelectionList> 
+    selectionList(const std::string& theID) = 0;
   /// Returns the attribute that contains reference to an attribute of a feature
   virtual boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
   /// Returns the attribute that contains list of references to features
@@ -99,8 +106,8 @@ class MODELAPI_EXPORT ModelAPI_Data
   /// Returns true if feature must be updated (re-executed) on rebuild
   virtual bool mustBeUpdated() = 0;
 
-  /// Returns true if this data attributes are referenced to the given feature or its results
-  virtual bool referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature) = 0;
+  /// Returns the identifier of feature-owner, unique in this document
+  virtual int featureId() const = 0;
 
  protected:
   /// Objects are created for features automatically
index 773ec389cf5a49b52cd8259c8374a5b28e8f6119..cdfa1d75ed89bb6661e2d7e30a239cfc3eab1a88 100644 (file)
@@ -81,9 +81,6 @@ public:
   virtual boost::shared_ptr<ModelAPI_Feature> feature(
       const boost::shared_ptr<ModelAPI_Result>& theResult) = 0;
 
-  ///! Reutrns true is result was conecaled because of usage it by other object
-  virtual bool isConcealed(const boost::shared_ptr<ModelAPI_Object>& theResult) = 0;
-
 protected:
   /// Only for SWIG wrapping it is here
   MODELAPI_EXPORT ModelAPI_Document()
index b3dc06045a0461975b881b84a58398613e2281ab..14a1e396f55f0ad3c252e315a7c2c8f93d1937d0 100644 (file)
@@ -7,6 +7,7 @@
 #include <ModelAPI_Result.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
+#include <ModelAPI_Session.h>
 #include <Events_Loop.h>
 
 const std::list<boost::shared_ptr<ModelAPI_Result> >& ModelAPI_Feature::results()
index a6c51d0407958d4831cc29773cc8e127aec5e9d1..269471f84f9404277236c65c621970f087295e49 100644 (file)
@@ -5,13 +5,27 @@
 #ifndef ModelAPI_Feature_H_
 #define ModelAPI_Feature_H_
 
-#include "ModelAPI_Object.h"
-#include "ModelAPI_Session.h"
+#include <ModelAPI.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Result.h>
 
-#include <string>
-#include <list>
 #include <boost/shared_ptr.hpp>
 
+#include <list>
+#include <string>
+
 class ModelAPI_Data;
 class ModelAPI_Document;
 class ModelAPI_Result;
@@ -36,6 +50,12 @@ class ModelAPI_Feature : public ModelAPI_Object
     return MY_GROUP;
   }
 
+  /// Returns document this feature belongs to
+  virtual boost::shared_ptr<ModelAPI_Document> document() const
+  {
+    return ModelAPI_Object::document();
+  }
+
   /// Returns the group identifier of this result
   virtual std::string groupName()
   {
@@ -84,9 +104,73 @@ class ModelAPI_Feature : public ModelAPI_Object
 
   MODELAPI_EXPORT static boost::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
 
+ //
+ // Helper methods, aliases for data()->method()
+ // -----------------------------------------------------------------------------------------------
+  inline std::string name()
+  {
+    return data()->name();
+  }
+
+  inline boost::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID)
+  {
+    return data()->boolean(theID);
+  }
+
+  inline boost::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID)
+  {
+    return data()->document(theID);
+  }
+
+  inline boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID)
+  {
+    return data()->real(theID);
+  }
+
+  inline boost::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID)
+  {
+    return data()->integer(theID);
+  }
+
+  inline boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
+  {
+    return data()->refattr(theID);
+  }
+
+  inline boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID)
+  {
+    return data()->reference(theID);
+  }
+
+  inline boost::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID)
+  {
+    return data()->reflist(theID);
+  }
+
+  inline boost::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID)
+  {
+    return data()->selection(theID);
+  }
+
+  inline boost::shared_ptr<ModelAPI_AttributeSelectionList> selectionList(const std::string& theID)
+  {
+    return data()->selectionList(theID);
+  }
+
+  inline boost::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID)
+  {
+    return data()->string(theID);
+  }
+
+  inline boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
+  {
+    return data()->attribute(theID);
+  }
+ // -----------------------------------------------------------------------------------------------
 };
 
 //! Pointer on feature object
 typedef boost::shared_ptr<ModelAPI_Feature> FeaturePtr;
 
 #endif
+
index 9241d9b6545310c70a13dd62e1e65d30186314d4..7ac6696f5ad5b0433b2d662bd2c5917f6858372f 100644 (file)
@@ -34,7 +34,7 @@ class ModelAPI_Object
   }
 
   /// Returns the data manager of this object: attributes
-  virtual boost::shared_ptr<ModelAPI_Data> data()
+  virtual boost::shared_ptr<ModelAPI_Data> data() const
   {
     return myData;
   }
@@ -46,7 +46,7 @@ class ModelAPI_Object
   }
 
   /// Returns document this feature belongs to
-  virtual boost::shared_ptr<ModelAPI_Document> document()
+  virtual boost::shared_ptr<ModelAPI_Document> document() const
   {
     return myDoc;
   }
@@ -54,6 +54,9 @@ class ModelAPI_Object
   /// Returns the group identifier of this object
   virtual std::string groupName() = 0;
 
+  /// To use virtuality for destructors
+  virtual ~ModelAPI_Object() {}
+
  protected:
   /// Sets the data manager of an object (document does)
   virtual void setData(boost::shared_ptr<ModelAPI_Data> theData)
index af9e7ce87edba6ae1b672dc98f7c7cffe056d77b..eb664ec221c92ccb1a0befd1b1a9a5ab3d035c76 100644 (file)
@@ -17,12 +17,19 @@ class ModelAPI_Feature;
  */
 class ModelAPI_Result : public ModelAPI_Object
 {
+  bool myIsConcealed; ///< the result is concealed from the data tree (referenced by other objects)
  public:
-  /// Returns the source feature of this result
-  //virtual boost::shared_ptr<ModelAPI_Feature> owner() = 0;
+   /// Returns true if the result is concealed from the data tree (referenced by other objects)
+  inline bool isConcealed() {return myIsConcealed;}
+
+  /// Returns true if the result is concealed from the data tree (referenced by other objects)
+  inline void setIsConcealed(const bool theValue) {myIsConcealed = theValue;}
+
+  /// To virtually destroy the fields of successors
+  virtual ~ModelAPI_Result()
+  {
+  }
 
-  /// Returns the group identifier of this result
-  //virtual std::string groupName() = 0;
 };
 
 //! Pointer on feature object
index c2eff7efcfa22b68d049d9b235045d75860b7a4f..4991cf27986c61ab24453c3873a87628baad583d 100644 (file)
@@ -7,20 +7,22 @@
 
 #include "ModelAPI_Result.h"
 #include <GeomAPI_Shape.h>
-
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <boost/shared_ptr.hpp>
 #include <string>
 
 /**\class ModelAPI_ResultBody
- * \ingroup DataModel
- * \brief The body (shape) result of a feature.
- *
- * Provides a shape that may be displayed in the viewer.
- * May provide really huge results, so, working with this kind
- * of result must be optimized.
- */
+* \ingroup DataModel
+* \brief The body (shape) result of a feature.
+*
+* Provides a shape that may be displayed in the viewer.
+* May provide really huge results, so, working with this kind
+* of result must be optimized.
+*/
 class ModelAPI_ResultBody : public ModelAPI_Result
 {
- public:
+public:
   /// Returns the group identifier of this result
   virtual std::string groupName()
   {
@@ -36,20 +38,59 @@ class ModelAPI_ResultBody : public ModelAPI_Result
 
   /// Stores the shape (called by the execution method).
   virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape) = 0;
+
+  /// Stores the generated shape (called by the execution method).
+  virtual void storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+                                 const boost::shared_ptr<GeomAPI_Shape>& theToShape) = 0;
+
+  /// Stores the modified shape (called by the execution method).
+  virtual void storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+                                 const boost::shared_ptr<GeomAPI_Shape>& theNewShape) = 0;
+
   /// Returns the shape-result produced by this feature
   virtual boost::shared_ptr<GeomAPI_Shape> shape() = 0;
 
-  /// To virtually destroy the fields of successors
-  virtual ~ModelAPI_ResultBody()
-  {
-  }
+  /// Records the subshape newShape which was generated during a topological construction.
+  /// As an example, consider the case of a face generated in construction of a box.
+  virtual void generated(
+    const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1) = 0;
 
- protected:
-  /// Use plugin manager for features creation: this method is 
-  /// defined here only for SWIG-wrapping
-  ModelAPI_ResultBody()
-  {
-  }
+  /// Records the shape newShape which was generated from the shape oldShape during a topological 
+  /// construction. As an example, consider the case of a face generated from an edge in 
+  /// construction of a prism.
+  virtual void generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+    const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1) = 0;
+
+  /// Records the shape newShape which is a modification of the shape oldShape.
+  /// As an example, consider the case of a face split or merged in a Boolean operation.
+  virtual void modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+    const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1) = 0;
+
+  /// Records the shape oldShape which was deleted from the current label.
+  /// As an example, consider the case of a face removed by a Boolean operation.
+  virtual void deleted(
+    const boost::shared_ptr<GeomAPI_Shape>& theOldShape, const int theTag = 1) = 0;
+  
+  /// load deleted shapes
+  virtual void loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag) = 0;
+  /// load and orient modified shapes
+  virtual void loadAndOrientModifiedShapes (
+                                                  GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag,
+                                               GeomAPI_DataMapOfShapeShape& theSubShapes) = 0;
+  /// load and orient generated shapes
+  virtual void loadAndOrientGeneratedShapes (
+                                                  GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag,
+                                               GeomAPI_DataMapOfShapeShape& theSubShapes) = 0;
+protected:
 };
 
 //! Pointer on feature object
index 565dd13d379835aca3504e8951174a5a7af53058..db8a54ca2c32b820601dcd261c42429dd40f8633 100644 (file)
@@ -22,6 +22,8 @@
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Validator.h>
 
index ea47856f4afd2b34b2a70191c165443d2d8be3f0..cd73508d58ecb55d3b82e1590bacc6abe6b24a51 100644 (file)
@@ -83,6 +83,13 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
   /// so, it is not needed for the standard validation mechanism
   virtual void registerNotObligatory(std::string theFeature, std::string theAttribute) = 0;
 
+  /// register that this attribute conceals in the object browser
+  /// all referenced features after execution
+  virtual void registerConcealment(std::string theFeature, std::string theAttribute) = 0;
+
+  /// Returns true that it was registered that attribute conceals the referenced result
+  virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0;
+
  protected:
   /// Get instance from Session
   ModelAPI_ValidatorsFactory()
index 1d0a37209b80cba0da6721496cb0f3d4a349a71b..26f54acb57863f07827cc21a36449d08221d9668 100644 (file)
@@ -6,13 +6,12 @@ assert(not aSession.canRedo())
 \r
 aSession.startOperation()\r
 aFeature = aDoc.addFeature("Point")\r
-aFeatureData = aFeature.data()\r
 # Since validators are introduced we have to initialize all\r
 # the feature's attributes\r
-aFeatureData.real("x").setValue(1.)\r
-aFeatureData.real("y").setValue(-1.)\r
-aFeatureData.real("z").setValue(0.)\r
-aFeatureName = aFeatureData.name()\r
+aFeature.real("x").setValue(1.)\r
+aFeature.real("y").setValue(-1.)\r
+aFeature.real("z").setValue(0.)\r
+aFeatureName = aFeature.name()\r
 assert(aFeatureName == "Point_1")\r
 \r
 aFeature.execute()\r
index 860e340941d3ccc84d164246ca20409d0f6c8544..ddf454e2c6a816cf620a27716dd3c64492265ca2 100644 (file)
@@ -3,7 +3,7 @@ SET(CMAKE_AUTOMOC ON)
 
 SET(PROJECT_HEADERS
        ModuleBase.h
-       ModuleBase_IOperation.h
+       ModuleBase_Tools.h
        ModuleBase_IModule.h
        ModuleBase_Operation.h
        ModuleBase_OperationDescription.h       
@@ -28,10 +28,17 @@ SET(PROJECT_HEADERS
        ModuleBase_WidgetChoice.h
        ModuleBase_WidgetFileSelector.h
        ModuleBase_DoubleSpinBox.h
+       ModuleBase_IPropertyPanel.h
+       ModuleBase_IViewer.h
+       ModuleBase_WidgetLineEdit.h
+       ModuleBase_WidgetMultiSelector.h
+       ModuleBase_ViewerFilters.h
+       ModuleBase_ResultPrs.h
 )
 
 SET(PROJECT_SOURCES
-       ModuleBase_IOperation.cpp
+       ModuleBase_Tools.cpp
+       ModuleBase_IModule.cpp
        ModuleBase_Operation.cpp
        ModuleBase_OperationDescription.cpp
        ModuleBase_ModelWidget.cpp
@@ -50,12 +57,17 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetChoice.cpp
        ModuleBase_WidgetFileSelector.cpp
        ModuleBase_DoubleSpinBox.cpp
+    ModuleBase_WidgetLineEdit.cpp
+       ModuleBase_WidgetMultiSelector.cpp
+       ModuleBase_ViewerFilters.cpp
+       ModuleBase_ResultPrs.cpp
 )
 
 SET(PROJECT_LIBRARIES
     Config
     ModelAPI
        GeomAPI
+       GeomAlgoAPI
     ${QT_LIBRARIES}
        ${CAS_VIEWER}
        ${CAS_KERNEL}
@@ -80,6 +92,7 @@ INCLUDE_DIRECTORIES(
     ${CMAKE_SOURCE_DIR}/src/ModelAPI
     ${CMAKE_SOURCE_DIR}/src/GeomDataAPI
     ${CMAKE_SOURCE_DIR}/src/GeomAPI
+    ${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
 )
 
 ADD_DEFINITIONS(-DMODULEBASE_EXPORTS ${CAS_DEFINITIONS})
index 56049acec437d3ace6a27f5c9922e9c4edcf9629..926de63ca9fb4a83dc85f9403c747bdecc31abe0 100644 (file)
@@ -10,5 +10,4 @@ typedef QList<short> QShortList;     //!< list of short int values
 typedef QList<double> QDoubleList;    //!< list of double values
 typedef QList<FeaturePtr> QFeatureList;  //!< List of features
 typedef QList<ResultPtr> QResultList;  //!< List of results
-
 #endif
diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp
new file mode 100644 (file)
index 0000000..df2502f
--- /dev/null
@@ -0,0 +1,49 @@
+
+#include "ModuleBase_IModule.h"
+#include "ModuleBase_IViewer.h"
+#include "ModuleBase_ViewerPrs.h"
+#include "ModuleBase_Operation.h"
+#include "ModuleBase_ISelection.h"
+
+#include <Events_Loop.h>
+
+#include <ModelAPI_Events.h>
+
+#include <Config_PointerMessage.h>
+
+
+ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent)
+  : QObject(theParent), myWorkshop(theParent) 
+{
+  connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+  connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
+          SLOT(onMousePressed(QMouseEvent*)));
+  connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
+          SLOT(onMouseReleased(QMouseEvent*)));
+  connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
+          SLOT(onMouseMoved(QMouseEvent*)));
+  connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
+          SLOT(onKeyRelease(QKeyEvent*)));
+  connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
+          SLOT(onMouseDoubleClick(QMouseEvent*)));
+}
+
+
+void ModuleBase_IModule::launchOperation(const QString& theCmdId)
+{
+  ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
+  ModuleBase_ISelection* aSelection = myWorkshop->selection();
+  // Initialise operation with preliminary selection
+  anOperation->initSelection(aSelection);
+  sendOperation(anOperation);
+}
+
+
+void ModuleBase_IModule::sendOperation(ModuleBase_Operation* theOperation)
+{
+  static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
+  boost::shared_ptr<Config_PointerMessage> aMessage =
+      boost::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
+  aMessage->setPointer(theOperation);
+  Events_Loop::loop()->send(aMessage);
+}
index 6404849276d5534225e3a22a4b5572708913cf2e..5787ccfb09989d5aa62afee6753a0117fc91b384 100644 (file)
-#ifndef ModuleBase_IModule_H\r
-#define ModuleBase_IModule_H\r
+#ifndef ModuleBase_IModule_H
+#define ModuleBase_IModule_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <QString>
+#include <QObject>
+
+
+class QAction;
+class QMouseEvent;\r
+class QKeyEvent;\r
+class Config_WidgetAPI;
+class ModuleBase_ModelWidget;
+class ModuleBase_Operation;
+class ModuleBase_IWorkshop;
+
+/**
+ * Interface to a module
+ */
+class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
+{
+  Q_OBJECT
+ public:
+
+   ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
+
+  virtual ~ModuleBase_IModule() {}
+
+  /// Reads description of features from XML file 
+  virtual void createFeatures() = 0;
+
+  /// Called on creation of menu item in desktop
+  virtual void featureCreated(QAction*) = 0;
+
+  /// Creates an operation and send it to loop
+  /// \param theCmdId the operation name
+  virtual void launchOperation(const QString& theCmdId);
+
+  /// Called when it is necessary to update a command state (enable or disable it)
+  //virtual bool isFeatureEnabled(const QString& theCmdId) const = 0;
+
+  /// Creates custom widgets for property panel
+  virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
+                                      Config_WidgetAPI* theWidgetApi,
+                                      QList<ModuleBase_ModelWidget*>& theModelWidgets)
+  {
+    return 0;
+  }
+
+  ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
+
+protected slots:
+
+  /// Called on selection changed event
+  virtual void onSelectionChanged() {}
+
+  /// SLOT, that is called by mouse press in the viewer.\r
+  /// The mouse released point is sent to the current operation to be processed.\r
+  /// \param theEvent the mouse event\r
+  virtual void onMousePressed(QMouseEvent* theEvent) {}\r
 \r
-#include <QString>\r
-#include <QObject>\r
+  /// SLOT, that is called by mouse release in the viewer.\r
+  /// The mouse released point is sent to the current operation to be processed.\r
+  /// \param theEvent the mouse event\r
+  virtual void onMouseReleased(QMouseEvent* theEvent) {}\r
+  \r
+  /// SLOT, that is called by mouse move in the viewer.\r
+  /// The mouse moved point is sent to the current operation to be processed.\r
+  /// \param theEvent the mouse event\r
+  virtual void onMouseMoved(QMouseEvent* theEvent) {}\r
 \r
-class QAction;\r
-class XGUI_Workshop;\r
-class Config_WidgetAPI;\r
-class ModuleBase_ModelWidget;\r
+  /// SLOT, that is called by the mouse double click in the viewer.\r
+  /// \param theEvent the mouse event\r
+  virtual void onMouseDoubleClick(QMouseEvent* theEvent) {}\r
 \r
-/**\r
- * Interface to a module\r
- */\r
-class ModuleBase_IModule : public QObject\r
-{\r
- public:\r
-  /// Reads description of features from XML file \r
-  virtual void createFeatures() = 0;\r
-\r
-  /// Called on creation of menu item in desktop\r
-  virtual void featureCreated(QAction*) = 0;\r
-\r
-  /// Creates an operation and send it to loop\r
-  /// \param theCmdId the operation name\r
-  virtual void launchOperation(const QString& theCmdId) = 0;\r
-\r
-  /// Called when it is necessary to update a command state (enable or disable it)\r
-  //virtual bool isFeatureEnabled(const QString& theCmdId) const = 0;\r
-\r
-  /// Creates custom widgets for property panel\r
-  virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
-                                      Config_WidgetAPI* theWidgetApi,\r
-                                      QList<ModuleBase_ModelWidget*>& theModelWidgets)\r
-  {\r
-    return 0;\r
-  }\r
-\r
-  virtual ~ModuleBase_IModule()\r
-  {\r
-  }\r
-  ;\r
-};\r
-\r
-//! This function must return a new module instance.\r
-extern "C" {\r
-typedef ModuleBase_IModule* (*CREATE_FUNC)(XGUI_Workshop*);\r
-}\r
-\r
-#define CREATE_MODULE "createModule"\r
-\r
-#endif //ModuleBase_IModule\r
\ No newline at end of file
+  /// SLOT, that is called by the key in the viewer is clicked.\r
+  /// \param theEvent the mouse event\r
+  virtual void onKeyRelease(QKeyEvent* theEvent) {}\r
+
+ protected:
+  /// Sends the operation for launching
+  /// \param theOperation the operation
+  void sendOperation(ModuleBase_Operation* theOperation);
+
+  /// Creates a new operation
+  /// \param theCmdId the operation name
+  /// \param theFeatureKind a kind of feature to get the feature xml description
+  virtual ModuleBase_Operation* createOperation(const std::string& theCmdId,
+                                        const std::string& theFeatureKind = "") = 0;
+
+
+protected:
+
+  ModuleBase_IWorkshop* myWorkshop;
+
+};
+
+//! This function must return a new module instance.
+extern "C" {
+typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
+}
+
+#define CREATE_MODULE "createModule"
+
+#endif //ModuleBase_IModule
diff --git a/src/ModuleBase/ModuleBase_IOperation.cpp b/src/ModuleBase/ModuleBase_IOperation.cpp
deleted file mode 100644 (file)
index f9fb72b..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * ModuleBase_IOperation.cpp
- *
- *  Created on: May 5, 2014
- *      Author: nds
- */
-
-#include "ModuleBase_IOperation.h"
-#include "ModuleBase_OperationDescription.h"
-#include "ModuleBase_ModelWidget.h"
-
-#include <ModelAPI_Document.h>
-#include <ModelAPI_Session.h>
-
-#ifdef _DEBUG
-#include <QDebug>
-#endif
-
-ModuleBase_IOperation::ModuleBase_IOperation(const QString& theId, QObject* theParent)
-    : QObject(theParent),
-      myIsEditing(false),
-      myIsModified(false)
-{
-  myDescription = new ModuleBase_OperationDescription(theId);
-}
-
-ModuleBase_IOperation::~ModuleBase_IOperation()
-{
-  delete myDescription;
-}
-
-ModuleBase_OperationDescription* ModuleBase_IOperation::getDescription() const
-{
-  return myDescription;
-}
-
-bool ModuleBase_IOperation::canBeCommitted() const
-{
-  return true;
-}
-
-/*void ModuleBase_IOperation::setModelWidgets(const std::string& theXmlRepresentation,
- QList<ModuleBase_ModelWidget*> theWidgets)
- {
- QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast = theWidgets.end();
- for (; anIt != aLast; anIt++) {
- QObject::connect(*anIt, SIGNAL(valuesChanged()),  this, SLOT(storeCustomValue()));
- }
- getDescription()->setModelWidgets(theXmlRepresentation, theWidgets);
- }*/
-
-boost::shared_ptr<ModelAPI_Document> ModuleBase_IOperation::document() const
-{
-  return ModelAPI_Session::get()->moduleDocument();
-}
-
-void ModuleBase_IOperation::start()
-{
-  ModelAPI_Session::get()->startOperation();
-
-  startOperation();
-  emit started();
-}
-
-void ModuleBase_IOperation::resume()
-{
-  emit resumed();
-}
-
-void ModuleBase_IOperation::abort()
-{
-  abortOperation();
-  emit aborted();
-
-  stopOperation();
-
-  ModelAPI_Session::get()->abortOperation();
-  emit stopped();
-}
-
-bool ModuleBase_IOperation::commit()
-{
-  if (canBeCommitted()) {
-    commitOperation();
-    emit committed();
-
-    stopOperation();
-
-    ModelAPI_Session::get()->finishOperation();
-    emit stopped();
-
-    afterCommitOperation();
-    return true;
-  }
-  return false;
-}
-
-void ModuleBase_IOperation::setRunning(bool theState)
-{
-  if (!theState) {
-    abort();
-  }
-}
diff --git a/src/ModuleBase/ModuleBase_IOperation.h b/src/ModuleBase/ModuleBase_IOperation.h
deleted file mode 100644 (file)
index 583f8ec..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * ModuleBase_IOperation.h
- *
- *  Created on: May 5, 2014
- *      Author: nds
- */
-
-#ifndef ModuleBase_IOperation_H
-#define ModuleBase_IOperation_H
-
-#include <ModuleBase.h>
-
-#include <QObject>
-#include <QString>
-#include <QList>
-#include <QStringList>
-
-#include <boost/shared_ptr.hpp>
-
-class ModelAPI_Document;
-class ModuleBase_OperationDescription;
-//class ModuleBase_ModelWidget;
-
-/*!
- \class ModuleBase_IOperation
- * \brief Base class for all operations
- *
- *  Base class for all operations. If you perform an action it is reasonable to create
- *  operation intended for this. This is a base class for all operations which provides
- *  mechanism for correct starting operations, starting operations above already started
- *  ones, committing operations and so on. To create own operation it is reasonable to
- *  inherit it from this class and redefines virtual methods to provide own behavior
- *  Main virtual methods are
- *  - virtual bool      isReadyToStart();
- *  - virtual void      startOperation();
- *  - virtual void      abortOperation();
- *  - virtual void      commitOperation();
- */
-
-class MODULEBASE_EXPORT ModuleBase_IOperation : public QObject
-{
-Q_OBJECT
-
- public:
-  /// Constructor
-  /// Constructs an empty operation. Constructor should work very fast because many
-  /// operators may be created after starting workshop but only several from them
-  /// may be used. As result this constructor stores given workshop in myApp field
-  /// and set Waiting status.
-  /// \param theId the operation identifier
-  /// \param theParent the QObject parent
-  ModuleBase_IOperation(const QString& theId = "", QObject* theParent = 0);
-  /// Destructor
-  virtual ~ModuleBase_IOperation();
-
-  /// Returns the operation description
-  /// /returns the instance of the description class
-  ModuleBase_OperationDescription* getDescription() const;
-
-  /**
-  * Must return true if this operation can be launched as nested for any current operation
-  * and it is not necessary to check this operation on validity. By default 
-  * the operation is not granted.
-  * The method has to be redefined for granted operations.
-  */
-  virtual bool isGranted(ModuleBase_IOperation* theOperation) const  { return false; }
-
-  /**
-  * Must return True if the operation's feature is valid.
-  * Since IOperation does not have any feature returns false.
-  */
-  virtual bool isValid() const { return false; }
-
-  /// Sets a list of model widgets, according to the operation feature xml definition
-  /// \param theXmlRepresentation an xml feature definition
-  /// \param theWidgets a list of widgets
-  //void setModelWidgets(const std::string& theXmlRepresentation,
-  //                     QList<ModuleBase_ModelWidget*> theWidgets);
-
-  /// Returns True if data of its feature was modified during operation
-  virtual bool isModified() const
-  {
-    return myIsModified;
-  }
-
-  /// Returns True id the current operation is launched in editing mode
-  bool isEditOperation() const
-  {
-    return myIsEditing;
-  }
-
-  /// Returns list of nested features
-  QStringList nestedFeatures() const { return myNestedFeatures; }
-
-  /// Sets list of nested features
-  void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
-
-signals:
-  void started();  /// the operation is started
-  void aborted();  /// the operation is aborted
-  void committed();  /// the operation is committed
-  void stopped();  /// the operation is aborted or committed
-  void resumed();  /// the operation is resumed
-
- public slots:
-  /// Starts operation
-  /// Public slot. Verifies whether operation can be started and starts operation.
-  /// This slot is not virtual and cannot be redefined. Redefine startOperation method
-  /// to change behavior of operation. There is no point in using this method. It would
-  /// be better to inherit own operator from base one and redefine startOperation method
-  /// instead.
-  void start();
-  /// Resumes operation
-  /// Public slot. Verifies whether operation can be started and starts operation.
-  /// This slot is not virtual and cannot be redefined. Redefine startOperation method
-  /// to change behavior of operation. There is no point in using this method. It would
-  /// be better to inherit own operator from base one and redefine startOperation method
-  /// instead.
-  void resume();
-  /// Aborts operation
-  /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
-  /// Redefine abortOperation method to change behavior of operation instead
-  void abort();
-  /// Commits operation
-  /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
-  /// Redefine commitOperation method to change behavior of operation instead
-  bool commit();
-
-  /// Alias for start/abort slots
-  /// Public slot. Aborts operation if false, else does nothing.
-  /// Provided for S/S compatibility with QAction's toggle(bool)
-  /// \param theState th flag to abort, if it is true, do nothing, overwise abort
-  void setRunning(bool theState);
-
-  // Data model methods.
-  /// Stores a custom value in model.
-  virtual void storeCustomValue() = 0;
-
- protected:
-  /// Virtual method called when operation started (see start() method for more description)
-  /// Default impl calls corresponding slot and commits immediately.
-  virtual void startOperation() = 0;
-
-  /// Virtual method called when operation stopped - committed or aborted.
-  virtual void stopOperation() = 0;
-
-  /// Virtual method called when operation aborted (see abort() method for more description)
-  virtual void abortOperation() = 0;
-
-  /// Virtual method called when operation committed (see commit() method for more description)
-  virtual void commitOperation() = 0;
-
-  /// Virtual method called after operation committed (see commit() method for more description)
-  /// it is important that the method is called after the stop() signal is emitted
-  virtual void afterCommitOperation() = 0;
-
-  /// Verifies whether this operator can be commited.
-  /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
-  virtual bool canBeCommitted() const;
-
-  /// Returns pointer to the root document.
-  boost::shared_ptr<ModelAPI_Document> document() const;
-
-  /// Editing feature flag
-  bool myIsEditing;
-
-  /// Modified feature flag
-  bool myIsModified;
-
- private:
-  ModuleBase_OperationDescription* myDescription;  /// the container to have the operation description
-
-  QStringList myNestedFeatures;
-};
-
-#endif
diff --git a/src/ModuleBase/ModuleBase_IPropertyPanel.h b/src/ModuleBase/ModuleBase_IPropertyPanel.h
new file mode 100644 (file)
index 0000000..7f8d9d3
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * ModuleBase_IPropertyPanel.h
+ *
+ *  Created on: Oct 01, 2014
+ *      Author: vsv
+ */
+
+#ifndef ModuleBase_PROPERTYPANEL_H_
+#define ModuleBase_PROPERTYPANEL_H_
+
+#include "ModuleBase.h"
+
+#include <QDockWidget>
+#include <QKeyEvent>
+
+class ModuleBase_ModelWidget;
+
+class MODULEBASE_EXPORT ModuleBase_IPropertyPanel : public QDockWidget
+{
+Q_OBJECT
+public:
+  ModuleBase_IPropertyPanel(QWidget* theParent) : QDockWidget(theParent) {}
+
+  /// Returns currently active widget
+  virtual ModuleBase_ModelWidget* activeWidget() const = 0;
+
+  /// Returns all property panel's widget created by WidgetFactory
+  virtual const QList<ModuleBase_ModelWidget*>& modelWidgets() const = 0;
+
+signals:
+  /// The signal about key release on the control, that corresponds to the attribute
+  /// \param theEvent key release event
+  void keyReleased(QKeyEvent* theEvent);
+  /// The signal about the widget activation
+  /// \param theWidget the activated widget
+  void widgetActivated(ModuleBase_ModelWidget* theWidget);
+
+public slots:
+  /// Activate the next widget in the property panel
+  /// \param theWidget a widget. The next widget should be activated
+  virtual void activateNextWidget(ModuleBase_ModelWidget* theWidget) = 0;
+
+  /// Activate the next from current widget in the property panel
+  virtual void activateNextWidget() = 0;
+};
+
+#endif
\ No newline at end of file
index 43bd0ea86650863887c248c69ac603b3059a73ff..c1b06ca1b71fae47724684d7c339f41e2fdcd158 100644 (file)
@@ -14,7 +14,7 @@
 #include <NCollection_List.hxx>
 #include <TopoDS_Shape.hxx>
 
-#include <list>
+#include <QList>
 
 class ModuleBase_ISelection
 {
@@ -23,12 +23,12 @@ class ModuleBase_ISelection
   /// Returns a list of viewer selected presentations
   /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
   /// \return list of presentations
-  virtual std::list<ModuleBase_ViewerPrs> getSelected(int theShapeTypeToSkip = -1) const = 0;
+  virtual QList<ModuleBase_ViewerPrs> getSelected(int theShapeTypeToSkip = -1) const = 0;
 
   /// Returns a list of viewer highlited presentations
   /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
   /// \return list of presentations
-  virtual std::list<ModuleBase_ViewerPrs> getHighlighted(int theShapeTypeToSkip = -1) const = 0;
+  virtual QList<ModuleBase_ViewerPrs> getHighlighted(int theShapeTypeToSkip = -1) const = 0;
 
   /**
    * Returns list of features currently selected in 3d viewer
@@ -47,7 +47,8 @@ class ModuleBase_ISelection
   virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const = 0;
 
   //! Returns list of currently selected shapes
-  virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList) const = 0;
+  virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList, 
+    std::list<ObjectPtr>& theOwners) const = 0;
 
 };
 
diff --git a/src/ModuleBase/ModuleBase_IViewer.h b/src/ModuleBase/ModuleBase_IViewer.h
new file mode 100644 (file)
index 0000000..6858fbe
--- /dev/null
@@ -0,0 +1,74 @@
+#ifndef ModuleBase_IViewer_H
+#define ModuleBase_IViewer_H
+
+#include "ModuleBase.h"
+#include <QObject>
+#include <AIS_InteractiveContext.hxx>
+#include <V3d_View.hxx>
+
+class QMouseEvent;
+class QKeyEvent;
+class QContextMenuEvent;
+
+/**
+ * A Base object for definition of connector object to
+ * Salome Viewer. Reimplemented in NewGeom_SalomeViewer class
+ */
+class MODULEBASE_EXPORT ModuleBase_IViewer : public QObject
+{
+Q_OBJECT
+ public:
+  ModuleBase_IViewer(QObject* theParent)
+      : QObject(theParent)
+  {
+  }
+
+  //! Returns AIS_InteractiveContext from current OCCViewer
+  virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
+
+  //! Retrurns V3d_Vioewer from current viewer
+  virtual Handle(V3d_Viewer) v3dViewer() const = 0;
+
+  //! Returns Vsd_View object from currently active view window
+  virtual Handle(V3d_View) activeView() const = 0;
+
+  //! Enable or disable selection in the viewer
+  virtual void enableSelection(bool isEnabled) = 0;
+
+  //! Returns true if selection is enabled
+  virtual bool isSelectionEnabled() const = 0;
+
+  //! Enable or disable multiselection in the viewer
+  virtual void enableMultiselection(bool isEnable) = 0;
+
+  //! Returns true if multiselection is enabled
+  virtual bool isMultiSelectionEnabled() const = 0;
+
+  //! Perfroms the fit all for the active view
+  virtual void fitAll() = 0;
+
+  //! Sets the view projection
+  /// \param theX the X projection value
+  /// \param theY the Y projection value
+  /// \param theZ the Z projection value
+  virtual void setViewProjection(double theX, double theY, double theZ) = 0;
+
+
+signals:
+  void lastViewClosed();
+  void tryCloseView();
+  void deleteView();
+  void viewCreated();
+  void mousePress(QMouseEvent* theEvent);
+  void mouseRelease(QMouseEvent* theEvent);
+  void mouseDoubleClick(QMouseEvent* theEvent);
+  void mouseMove(QMouseEvent* theEvent);
+  void keyPress(QKeyEvent* theEvent);
+  void keyRelease(QKeyEvent* theEvent);
+  void activated();
+
+  void selectionChanged();
+  void contextMenuRequested(QContextMenuEvent*);
+};
+
+#endif
index b05e2d62976875af9a6eddeec709a7eefcb5a89a..12e9aef22040c91a4a762d8028dcb794291c48b7 100644 (file)
@@ -6,14 +6,17 @@
 #define ModuleBase_IWorkshop_H
 
 #include "ModuleBase.h"
+#include "ModuleBase_Definitions.h"
 
 #include <ModelAPI_Object.h>
-
-#include <AIS_InteractiveContext.hxx>
+#include <GeomAPI_AISObject.h>
 
 #include <QObject>
 
 class ModuleBase_IModule;
+class ModuleBase_ISelection;
+class ModuleBase_IViewer;
+class ModuleBase_Operation;
 
 /**
  * Class which provides access to Workshop object serveces
@@ -24,25 +27,44 @@ Q_OBJECT
  public:
   ModuleBase_IWorkshop(QObject* theParent)
       : QObject(theParent)
-  {
-  }
+  {}
 
   virtual ~ModuleBase_IWorkshop()
-  {
-  }
-  ;
+  {}
+
+  virtual ModuleBase_ISelection* selection() const = 0;
 
-  //! Returns AIS_InteractiveContext from current OCCViewer
-  virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
+  /// Activate sub-shapes selection (opens local context)
+  /// Types has to be dined according to TopAbs_ShapeEnum
+  virtual void activateSubShapesSelection(const QIntList& theTypes) = 0;
 
-  //! Returns list of currently selected data objects
-  virtual QList<ObjectPtr> selectedObjects() const = 0;
+  /// Deactivate sub-shapes selection (closes local context)
+  virtual void deactivateSubShapesSelection() = 0;
 
   //! Returns instance of loaded module
   virtual ModuleBase_IModule* module() const = 0;
 
+  //! Returns current viewer
+  virtual ModuleBase_IViewer* viewer() const = 0;
+
+  //! Returns currently active operation
+  virtual ModuleBase_Operation* currentOperation() const = 0;
+
+  //! Returns AIS opbject by data object
+  virtual AISObjectPtr findPresentation(const ObjectPtr& theObject) const = 0;
+
+  //! Returns data object by AIS
+  virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
+
+  //! Select features clearing previous selection. 
+  //! If the list is empty then selection will be cleared
+  virtual void setSelected(const QList<ObjectPtr>& theFeatures) = 0;
+
 signals:
   void selectionChanged();
+
+  void operationStarted(ModuleBase_Operation*);
+  void operationStopped(ModuleBase_Operation*);
 };
 
 #endif
index 939345b517beefd395652896b194802d34b728a9..5a6ba6e1eb5b8032feef6a283c3cc5e09b16c8c1 100644 (file)
 
 #include <QEvent>
 #include <QWidget>
+#include <QGraphicsDropShadowEffect>
+#include <QColor>
+#include <QLabel>
 
-ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData,
+ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData,
                                                const std::string& theParentId)
     : QObject(theParent),
       myParentId(theParentId)
 {
   myIsComputedDefault = false;
-  myIsObligatory = theData ? theData->getBooleanAttribute(FEATURE_OBLIGATORY, true) : true;
   myAttributeID = theData ? theData->widgetId() : "";
 }
 
@@ -36,8 +38,32 @@ void ModuleBase_ModelWidget::enableFocusProcessing()
 {
   QList<QWidget*> aMyControls = getControls();
   foreach(QWidget*  eachControl, aMyControls) {
-    if(!myFocusInWidgets.contains(eachControl)) {
-      enableFocusProcessing(eachControl);
+    eachControl->setFocusPolicy(Qt::StrongFocus);
+    eachControl->installEventFilter(this);
+  }
+}
+
+void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
+{
+  QList<QWidget*> aWidgetList = getControls();
+  foreach(QWidget* aWidget, aWidgetList) {
+    QLabel* aLabel = qobject_cast<QLabel*>(aWidget);
+    // We won't set the effect to QLabels - it looks ugly
+    if(aLabel) continue;
+    if(isHighlighted) {
+      // If effect is the installed on a different widget, setGraphicsEffect() will
+      // remove the effect from the widget and install it on this widget.
+      // That's why we create a new effect for each widget
+      QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect();
+      aGlowEffect->setOffset(.0);
+      aGlowEffect->setBlurRadius(10.0);
+      aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF
+      aWidget->setGraphicsEffect(aGlowEffect);
+    } else {
+      QGraphicsEffect* anEffect = aWidget->graphicsEffect();
+      if(anEffect)
+        anEffect->deleteLater();
+      aWidget->setGraphicsEffect(NULL);
     }
   }
 }
@@ -64,20 +90,15 @@ void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const
   ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
 }
 
-void ModuleBase_ModelWidget::enableFocusProcessing(QWidget* theWidget)
-{
-  theWidget->setFocusPolicy(Qt::StrongFocus);
-  theWidget->installEventFilter(this);
-  myFocusInWidgets.append(theWidget);
-}
-
 bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
 {
-  QWidget* aWidget = dynamic_cast<QWidget*>(theObject);
-  if (theEvent->type() == QEvent::MouseButtonRelease && 
-      myFocusInWidgets.contains(aWidget)) {
-    emit focusInWidget(this);
+  QWidget* aWidget = qobject_cast<QWidget*>(theObject);
+  if (theEvent->type() == QEvent::FocusIn) {
+    if (getControls().contains(aWidget)) {
+      emit focusInWidget(this);
+    }
   } 
   // pass the event on to the parent class
+
   return QObject::eventFilter(theObject, theEvent);
 }
index 91b9738546d4e3e55c299ba48f7041c368604c44..25c0bf2469a3d34fc077546ae0ce56ec108a5b88 100644 (file)
@@ -32,21 +32,13 @@ Q_OBJECT
   /// Constructor
   /// \theParent the parent object
   /// \theData the widget configuation. The attribute of the model widget is obtained from
-  ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData,
+  ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData,
                          const std::string& theParentId);
   /// Destructor
   virtual ~ModuleBase_ModelWidget()
   {
   }
 
-  /// Set the given wrapped value to the current widget
-  /// This value should be processed in the widget according to the needs
-  /// \param theValue the wrapped widget value
-  virtual bool setValue(ModuleBase_WidgetValue* theValue)
-  {
-    return false;
-  }
-
   /// Returns the state whether the attribute of the feature is initialized
   /// \param theObject a model feature to be checked
   /// \return the boolean result
@@ -56,9 +48,16 @@ Q_OBJECT
   /// on operation's execute, like radius for circle's constraint (can not be zero)
   bool isComputedDefault() { return myIsComputedDefault; }
 
-  /// Returns false for non-obligatory widgets which are
-  /// valid even if they are not initialized
-  bool isObligatory() { return myIsObligatory; }
+  /// Defines if it is supposed that the widget should interact with the viewer.
+  virtual bool isViewerSelector() { return false; }
+
+  /// Set the given wrapped value to the current widget
+  /// This value should be processed in the widget according to the needs
+  /// \param theValue the wrapped widget value
+  virtual bool setValue(ModuleBase_WidgetValue* theValue)
+  {
+    return false;
+  }
 
   /// Saves the internal parameters to the given feature
   /// \param theObject a model feature to be changed
@@ -66,19 +65,28 @@ Q_OBJECT
 
   virtual bool restoreValue() = 0;
 
-  void enableFocusProcessing();
   /// Set focus to the first control of the current widget. The focus policy of the control is checked.
   /// If the widget has the NonFocus focus policy, it is skipped.
   /// \return the state whether the widget can accept the focus
   virtual bool focusTo();
 
+  /// Returns the internal parent wiget control, that can be shown anywhere
+  /// \returns the widget
+  virtual QWidget* getControl() const = 0;
+
   /// Returns list of widget controls
   /// \return a control list
   virtual QList<QWidget*> getControls() const = 0;
 
+
   /// FocusIn events processing
   virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
 
+
+  void enableFocusProcessing();
+
+  void setHighlighted(bool isHighlighted);
+
   /// Returns the attribute name
   /// \returns the string value
   std::string attributeID() const
@@ -97,14 +105,12 @@ Q_OBJECT
   {
     return myFeature;
   }
+
   void setFeature(const FeaturePtr& theFeature)
   {
     myFeature = theFeature;
   }
 
-  /// Defines if it is supposed that the widget should interact with the viewer.
-  virtual bool isViewerSelector() { return false; }
-
 signals:
   /// The signal about widget values changed
   void valuesChanged();
@@ -129,22 +135,13 @@ signals:
 
   void updateObject(ObjectPtr theObj) const;
 
- private:
-  /// Let the widget process FocusIn events
-  void enableFocusProcessing(QWidget* theWidget);
-
  protected:
   std::string myAttributeID; /// the attribute name of the model feature
   std::string myParentId;    /// name of parent
   FeaturePtr myFeature;
 
-    bool myIsComputedDefault; /// Value should be computed on execute,
-                              /// like radius for circle's constraint (can not be zero)
-    bool myIsObligatory;      /// Non-obligatory widget is valid even if it is not initialized
-
- private:
-   /// Contains a list of widgets that may accept focus
-   QList<QWidget*> myFocusInWidgets;
+  bool myIsComputedDefault; /// Value should be computed on execute,
+                            /// like radius for circle's constraint (can not be zero)
 };
 
 #endif
index fd0724f287ef8e32fbeb2045f18e0961f75beae3..896da097e6160d7f73ed867ea9b9c3a5dc48869d 100644 (file)
@@ -9,6 +9,10 @@
 
 #include "ModuleBase_OperationDescription.h"
 #include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_WidgetValueFeature.h"
+#include "ModuleBase_ViewerPrs.h"
+#include "ModuleBase_IPropertyPanel.h"
+#include "ModuleBase_ISelection.h"
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_Object.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
+
+#include <GeomAPI_Pnt2d.h>
 
 #include <Events_Loop.h>
 
 #endif
 
 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
-    : ModuleBase_IOperation(theId, theParent)
+    : QObject(theParent),
+      myIsEditing(false),
+      myIsModified(false),
+      myPropertyPanel(NULL)
 {
+  myDescription = new ModuleBase_OperationDescription(theId);
 }
 
 ModuleBase_Operation::~ModuleBase_Operation()
 {
+  delete myDescription;
 }
 
 QString ModuleBase_Operation::id() const
@@ -74,16 +87,10 @@ void ModuleBase_Operation::storeCustomValue()
     aCustom->storeValue();
 }
 
-void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
-{
-}
-
 void ModuleBase_Operation::startOperation()
 {
   if (!myIsEditing)
     createFeature();
-  //emit callSlot();
-  //commit();
 }
 
 void ModuleBase_Operation::stopOperation()
@@ -104,26 +111,7 @@ void ModuleBase_Operation::afterCommitOperation()
 
 bool ModuleBase_Operation::canBeCommitted() const
 {
-  if (ModuleBase_IOperation::canBeCommitted()) {
-    /*    FeaturePtr aFeature = feature();
-     std::string aId = aFeature->getKind();
-
-     SessionPtr aMgr = ModelAPI_Session::get();
-     ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-     std::list<ModelAPI_Validator*> aValidators;
-     aFactory->validators(aId, aValidators);
-     std::list<ModelAPI_Validator*>::const_iterator aIt;
-     for (aIt = aValidators.cbegin(); aIt != aValidators.cend(); ++aIt) {
-     const ModuleBase_FeatureValidator* aFValidator = 
-     dynamic_cast<const ModuleBase_FeatureValidator*>(*aIt);
-     if (aFValidator) {
-     if (!aFValidator->isValid(aFeature))
-     return false;
-     }
-     }*/
-    return true;
-  }
-  return false;
+  return true;
 }
 
 void ModuleBase_Operation::flushUpdated()
@@ -136,10 +124,15 @@ void ModuleBase_Operation::flushCreated()
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
 }
 
-FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
+FeaturePtr ModuleBase_Operation::createFeature(
+  const bool theFlushMessage, CompositeFeaturePtr theCompositeFeature)
 {
-  boost::shared_ptr<ModelAPI_Document> aDoc = document();
-  myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
+  if (theCompositeFeature) {
+    myFeature = theCompositeFeature->addFeature(getDescription()->operationId().toStdString());
+  } else {
+    boost::shared_ptr<ModelAPI_Document> aDoc = document();
+    myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
+  }
   if (myFeature) {  // TODO: generate an error if feature was not created
     myIsModified = true;
     // Model update should call "execute" of a feature.
@@ -160,11 +153,6 @@ FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
 void ModuleBase_Operation::setFeature(FeaturePtr theFeature)
 {
   myFeature = theFeature;
-}
-
-void ModuleBase_Operation::setEditingFeature(FeaturePtr theFeature)
-{
-  setFeature(theFeature);
   myIsEditing = true;
 }
 
@@ -184,3 +172,163 @@ bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const
   return false;
 }
 
+
+boost::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
+{
+  return ModelAPI_Session::get()->moduleDocument();
+}
+
+
+void ModuleBase_Operation::start()
+{
+  ModelAPI_Session::get()->startOperation();
+
+  startOperation();
+  emit started();
+}
+
+void ModuleBase_Operation::resume()
+{
+  if (myPropertyPanel)
+    connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
+            this,            SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
+  emit resumed();
+}
+
+void ModuleBase_Operation::abort()
+{
+  abortOperation();
+  emit aborted();
+  if (myPropertyPanel)
+    disconnect(myPropertyPanel, 0, this, 0);
+
+  stopOperation();
+
+  ModelAPI_Session::get()->abortOperation();
+  emit stopped();
+}
+
+bool ModuleBase_Operation::commit()
+{
+  if (canBeCommitted()) {
+    commitOperation();
+    emit committed();
+
+  if (myPropertyPanel)
+    disconnect(myPropertyPanel, 0, this, 0);
+
+    stopOperation();
+    ModelAPI_Session::get()->finishOperation();
+
+    emit stopped();
+
+    afterCommitOperation();
+    return true;
+  }
+  return false;
+}
+
+void ModuleBase_Operation::setRunning(bool theState)
+{
+  if (!theState) {
+    abort();
+  }
+}
+
+bool ModuleBase_Operation::activateByPreselection()
+{
+  if (!myPropertyPanel)
+    return false;
+  if (myPreSelection.empty())
+    return false;
+  const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
+  if (aWidgets.empty())
+    return false;
+  
+  ModuleBase_ModelWidget* aWgt;
+  ModuleBase_ViewerPrs aPrs;
+  QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
+  QList<ModuleBase_ViewerPrs>::const_iterator aPIt;
+  for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin();
+       (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd());
+       ++aWIt, ++aPIt) {
+    aWgt = (*aWIt);
+    aPrs = (*aPIt);
+    ModuleBase_WidgetValueFeature aValue;
+    aValue.setObject(aPrs.object());
+    if (!aWgt->setValue(&aValue))
+      break;
+  }
+  if (canBeCommitted()) {
+    // if all widgets are filled with selection
+    commit();
+    return true;
+  }
+
+  //ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+  //if ((myPreSelection.size() > 0) && aActiveWgt) {
+  //  const ModuleBase_ViewerPrs& aPrs = myPreSelection.first();
+  //  ModuleBase_WidgetValueFeature aValue;
+  //  aValue.setObject(aPrs.object());
+  //  if (aActiveWgt->setValue(&aValue)) {
+  //    myPreSelection.removeOne(aPrs);
+  //    myPropertyPanel->activateNextWidget();
+  //  }
+  //  // If preselection is enough to make a valid feature - apply it immediately
+  //}
+  return false;
+}
+
+void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection)
+{
+  myPreSelection.clear();
+
+  // Check that the selected result are not results of operation feature
+  QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+  FeaturePtr aFeature = feature();
+  if (aFeature) {
+    std::list<ResultPtr> aResults = aFeature->results();
+    QList<ObjectPtr> aResList;
+    std::list<ResultPtr>::const_iterator aIt;
+    for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
+      aResList.append(*aIt);
+
+    foreach (ModuleBase_ViewerPrs aPrs, aSelected) {
+      if ((!aResList.contains(aPrs.object())) && (aPrs.object() != aFeature))
+        myPreSelection.append(aPrs);
+    }
+  } else
+    myPreSelection = aSelected;
+}
+
+void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
+{
+  //activateByPreselection();
+  //if (theWidget && myPropertyPanel) {
+  //  myPropertyPanel->activateNextWidget();
+  ////  //emit activateNextWidget(myActiveWidget);
+  //}
+}
+
+bool ModuleBase_Operation::setWidgetValue(ObjectPtr theFeature, double theX, double theY)
+{
+  ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+  if (!aActiveWgt)
+    return false;
+  ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
+  aValue->setObject(theFeature);
+  aValue->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
+  bool isApplyed = aActiveWgt->setValue(aValue);
+
+  delete aValue;
+  myIsModified = (myIsModified || isApplyed);
+  return isApplyed;
+}
+
+
+void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) 
+{ 
+  myPropertyPanel = theProp; 
+  connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this,
+          SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
+}
index 17be4cba4286a6e6e63ea45c6ed6e3ec622c681a..9d1a1c04ad2e3310c2040d0ac03ccbedddc93b0d 100644 (file)
@@ -9,17 +9,19 @@
 #define ModuleBase_Operation_H
 
 #include <ModuleBase.h>
-#include <ModuleBase_IOperation.h>
+#include <ModuleBase_ViewerPrs.h>
 
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Document.h>
 
 #include <QObject>
 #include <QString>
+#include <QStringList>
 
-#include <boost/shared_ptr.hpp>
-
-class ModelAPI_Document;
 class ModuleBase_ModelWidget;
+class ModuleBase_OperationDescription;
+class ModuleBase_IPropertyPanel;
+class ModuleBase_ISelection;
 
 class QKeyEvent;
 
@@ -39,7 +41,7 @@ class QKeyEvent;
  *  - virtual void      commitOperation();
  */
 
-class MODULEBASE_EXPORT ModuleBase_Operation : public ModuleBase_IOperation
+class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
 {
 Q_OBJECT
 
@@ -51,13 +53,48 @@ Q_OBJECT
   /// Destructor
   virtual ~ModuleBase_Operation();
 
+  /// Returns the operation description
+  /// /returns the instance of the description class
+  ModuleBase_OperationDescription* getDescription() const { return myDescription; }
+
+  /**
+  * Must return true if this operation can be launched as nested for any current operation
+  * and it is not necessary to check this operation on validity. By default 
+  * the operation is not granted.
+  * The method has to be redefined for granted operations.
+  */
+  virtual bool isGranted(ModuleBase_Operation* theOperation) const  { return false; }
+
+  /// Sets a list of model widgets, according to the operation feature xml definition
+  /// \param theXmlRepresentation an xml feature definition
+  /// \param theWidgets a list of widgets
+  //void setModelWidgets(const std::string& theXmlRepresentation,
+  //                     QList<ModuleBase_ModelWidget*> theWidgets);
+
+  /// Returns True if data of its feature was modified during operation
+  virtual bool isModified() const { return myIsModified; }
+
+  /// Returns True id the current operation is launched in editing mode
+  bool isEditOperation() const { return myIsEditing; }
+
+  /// Returns list of nested features
+  QStringList nestedFeatures() const { return myNestedFeatures; }
+
+  /// Sets list of nested features
+  void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
+
+
   // Returns operations Id from it's description
   QString id() const;
+
   /// Returns the operation feature
   /// \return the feature
   FeaturePtr feature() const;
 
-  /// Returns true is feature of operation is valid.
+  /**
+  * Must return True if the operation's feature is valid.
+  * Since IOperation does not have any feature returns false.
+  */
   virtual bool isValid() const;
 
   /// Returns whether the nested operations are enabled.
@@ -65,44 +102,89 @@ Q_OBJECT
   /// \return enabled state
   virtual bool isNestedOperationsEnabled() const;
 
-  // Data model methods.
-  /// Stores a custom value in model.
-  void storeCustomValue();
-
   /// Sets the operation feature
-  void setEditingFeature(FeaturePtr theFeature);
+  void setFeature(FeaturePtr theFeature);
 
   /// Returns True if the current operation works with the given object (feature or result)
   virtual bool hasObject(ObjectPtr theObj) const;
 
   virtual void keyReleased(const int theKey) {};
 
-  virtual void activateNextToCurrentWidget() {};
-
   /// If operation needs to redisplay its result during operation
   /// then this method has to return True
   virtual bool hasPreview() const { return false; }
 
+  /// Initialisation of operation with preliminary selection
+  /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
+  virtual void initSelection(ModuleBase_ISelection* theSelection);
+
+  virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
+
+  ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
+
+  /// Activates widgets by preselection if it is accepted
+  virtual bool activateByPreselection();
+
+signals:
+  void started();  /// the operation is started
+  void aborted();  /// the operation is aborted
+  void committed();  /// the operation is committed
+  void stopped();  /// the operation is aborted or committed
+  void resumed();  /// the operation is resumed
+
  public slots:
+  /// Starts operation
+  /// Public slot. Verifies whether operation can be started and starts operation.
+  /// This slot is not virtual and cannot be redefined. Redefine startOperation method
+  /// to change behavior of operation. There is no point in using this method. It would
+  /// be better to inherit own operator from base one and redefine startOperation method
+  /// instead.
+  void start();
+  /// Resumes operation
+  /// Public slot. Verifies whether operation can be started and starts operation.
+  /// This slot is not virtual and cannot be redefined. Redefine startOperation method
+  /// to change behavior of operation. There is no point in using this method. It would
+  /// be better to inherit own operator from base one and redefine startOperation method
+  /// instead.
+  void resume();
+  /// Aborts operation
+  /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
+  /// Redefine abortOperation method to change behavior of operation instead
+  void abort();
+  /// Commits operation
+  /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
+  /// Redefine commitOperation method to change behavior of operation instead
+  bool commit();
+
+  /// Alias for start/abort slots
+  /// Public slot. Aborts operation if false, else does nothing.
+  /// Provided for S/S compatibility with QAction's toggle(bool)
+  /// \param theState th flag to abort, if it is true, do nothing, overwise abort
+  void setRunning(bool theState);
+
+  // Data model methods.
+  /// Stores a custom value in model.
+  virtual void storeCustomValue();
+
   /// Slots which listen the mode widget activation
   /// \param theWidget the model widget
   virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
 
-signals:
-  /// Signals about the activating of the next widget
-  /// \param theWidget the previous active widget
-  void activateNextWidget(ModuleBase_ModelWidget* theWidget);
-
  protected:
   /// Virtual method called when operation started (see start() method for more description)
   /// Default impl calls corresponding slot and commits immediately.
   virtual void startOperation();
+
   /// Virtual method called when operation stopped - committed or aborted.
   virtual void stopOperation();
+
   /// Virtual method called when operation aborted (see abort() method for more description)
   virtual void abortOperation();
+
   /// Virtual method called when operation committed (see commit() method for more description)
   virtual void commitOperation();
+
   /// Virtual method called after operation committed (see commit() method for more description)
   virtual void afterCommitOperation();
 
@@ -113,19 +195,45 @@ signals:
 
   /// Creates an operation new feature
   /// \param theFlushMessage the flag whether the create message should be flushed
-  /// \returns the created feature
-  virtual FeaturePtr createFeature(const bool theFlushMessage = true);
-
- protected:
-  /// Sets the operation feature
-  void setFeature(FeaturePtr theFeature);
+  /// \param theCompositeFeature the feature that must be used for adding the created object or null
+  /// \returns the created 
+  virtual FeaturePtr createFeature(const bool theFlushMessage = true, 
+    CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
 
   /// Verifies whether this operator can be commited.
   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
   virtual bool canBeCommitted() const;
 
+  /// Returns pointer to the root document.
+  boost::shared_ptr<ModelAPI_Document> document() const;
+
+  /// Set value to the active widget
+  /// \param theFeature the feature
+  /// \param theX the horizontal coordinate
+  /// \param theY the vertical coordinate
+  /// \return true if the point is set
+  virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
+
  protected:
   FeaturePtr myFeature;  /// the operation feature to be handled
+
+  /// the container to have the operation description
+  ModuleBase_OperationDescription* myDescription;  
+
+  /// Editing feature flag
+  bool myIsEditing;
+
+  /// Modified feature flag
+  bool myIsModified;
+
+  /// List of nested operations IDs
+  QStringList myNestedFeatures;
+
+  /// List of pre-selected object 
+  QList<ModuleBase_ViewerPrs> myPreSelection;
+
+  /// Access to property panel
+  ModuleBase_IPropertyPanel* myPropertyPanel;
 };
 
 #endif
diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp
new file mode 100644 (file)
index 0000000..6de0bba
--- /dev/null
@@ -0,0 +1,77 @@
+// File:        ModuleBase_ResultPrs.cpp
+// Created:     21 October 2014
+// Author:      Vitaly SMETANNIKOV
+
+#include "ModuleBase_ResultPrs.h"
+
+#include <ModelAPI_Tools.h>
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAlgoAPI_SketchBuilder.h>
+
+#include <BRep_Builder.hxx>
+#include <AIS_Drawer.hxx>
+#include <Prs3d_IsoAspect.hxx>
+#include <TopoDS_Builder.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, AIS_Shape);
+
+ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
+  : AIS_Shape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
+{
+  boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
+  boost::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = 
+    boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapePtr);
+  if (aWirePtr) {
+    if (aWirePtr->hasPlane() ) {
+      // If this is a wire with plane defined thin it is a sketch-like object
+      // It must have invisible faces
+      GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
+        aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, myFacesList);
+
+      myOriginalShape = aWirePtr->impl<TopoDS_Shape>();
+      Set(myOriginalShape);
+      myIsSketchMode = true;
+    } else {
+      Set(aWirePtr->impl<TopoDS_Shape>());
+    }
+  } else {
+    Set(aShapePtr->impl<TopoDS_Shape>());
+  }
+}
+
+
+void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+                                   const Handle(Prs3d_Presentation)& thePresentation, 
+                                   const Standard_Integer theMode)
+{
+  boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
+  if (!aShapePtr)
+    return;
+  myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
+  Set(aShapePtr->impl<TopoDS_Shape>());
+  AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
+}
+
+
+void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+                                            const Standard_Integer aMode)
+{
+  if (myIsSketchMode) {
+    if (aMode == TopAbs_FACE) {
+      BRep_Builder aBuilder;
+      TopoDS_Compound aComp;
+      aBuilder.MakeCompound(aComp);
+      aBuilder.Add(aComp, myOriginalShape);
+      std::list<boost::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
+      for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
+        TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
+        aBuilder.Add(aComp, aFace);
+      }
+      Set(aComp);
+    } else {
+      Set(myOriginalShape);
+    }
+  }
+  AIS_Shape::ComputeSelection(aSelection, aMode);
+}
\ No newline at end of file
diff --git a/src/ModuleBase/ModuleBase_ResultPrs.h b/src/ModuleBase/ModuleBase_ResultPrs.h
new file mode 100644 (file)
index 0000000..0d2d058
--- /dev/null
@@ -0,0 +1,42 @@
+// File:        ModuleBase_ResultPrs.h
+// Created:     21 October 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef ModuleBase_ResultPrs_H
+#define ModuleBase_ResultPrs_H
+
+#include "ModuleBase.h"
+
+#include <ModelAPI_Result.h>
+
+#include <AIS_Shape.hxx>
+#include <Standard_DefineHandle.hxx>
+
+DEFINE_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape)
+
+class ModuleBase_ResultPrs: public AIS_Shape
+{
+public:
+  Standard_EXPORT ModuleBase_ResultPrs(ResultPtr theResult);
+
+  Standard_EXPORT ResultPtr getResult() const { return myResult; }
+
+  DEFINE_STANDARD_RTTI(ModuleBase_ResultPrs)
+protected:
+  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+    const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
+
+  Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+    const Standard_Integer aMode) ;
+
+private:
+  ResultPtr myResult;
+
+  bool myIsSketchMode;
+
+  TopoDS_Shape myOriginalShape;
+  std::list<boost::shared_ptr<GeomAPI_Shape> > myFacesList;
+};
+
+
+#endif
\ No newline at end of file
index f68de8da5cba818502ee05c88496a59d239488e9..8df14bdc35b74bfb93fce4cdb053f9ac5c302114 100644 (file)
@@ -12,4 +12,35 @@ namespace ModuleBase_Tools {
 //******************************************************************
 
 //******************************************************************
+
+void adjustMargins(QWidget* theWidget)
+{
+  if(!theWidget)
+    return;
+  adjustMargins(theWidget->layout());
+}
+
+void adjustMargins(QLayout* theLayout)
+{
+  if(!theLayout)
+    return;
+  theLayout->setContentsMargins(2, 5, 5, 2);
+  theLayout->setSpacing(4);
+}
+
+void zeroMargins(QWidget* theWidget)
+{
+  if(!theWidget)
+    return;
+  zeroMargins(theWidget->layout());
+}
+
+void zeroMargins(QLayout* theLayout)
+{
+  if(!theLayout)
+    return;
+  theLayout->setContentsMargins(0, 0, 0, 0);
+  theLayout->setSpacing(5);
+}
+
 }
index e2a09c54624833ac3bd0d9f17aa25e7aa0fc2222..6c903d3fbd7b41d7aeba8ff97694fa2aef27cd87 100644 (file)
@@ -7,21 +7,22 @@
 
 #include "ModuleBase.h"
 
-#include <ModelAPI_Result.h>
-#include <ModelAPI_Feature.h>
+#include <QWidget>
+#include <QLayout>
 
 class GeomAPI_Shape;
 
 namespace ModuleBase_Tools {
 
-/**
- * Returns returns a shape if the result has a shape method. Otherwise returns NULL pointer
+/*
+ * Methods to adjust margins and spacings.
  */
-MODULEBASE_EXPORT boost::shared_ptr<GeomAPI_Shape> shape(ResultPtr theResult);
+MODULEBASE_EXPORT void adjustMargins(QWidget* theWidget);
+MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout);
 
-MODULEBASE_EXPORT FeaturePtr feature(ObjectPtr theObject);
+MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget);
+MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout);
 
 }
-;
 
 #endif
diff --git a/src/ModuleBase/ModuleBase_ViewerFilters.cpp b/src/ModuleBase/ModuleBase_ViewerFilters.cpp
new file mode 100644 (file)
index 0000000..b104371
--- /dev/null
@@ -0,0 +1,83 @@
+// File:        ModuleBase_ViewerFilters.cpp
+// Created:     07 Okt 2014
+// Author:      Vitaly SMETANNIKOV
+
+
+#include "ModuleBase_ViewerFilters.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+
+#include <StdSelect_BRepOwner.hxx>
+
+#include <BRep_Tool.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <Geom_Curve.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
+
+
+//TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
+Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+  if (theOwner->HasSelectable()) {
+    Handle(AIS_InteractiveObject) aAisObj = 
+      Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+    if (!aAisObj.IsNull()) {
+      boost::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+      aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
+      ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
+      if (aObj) {
+        DocumentPtr aDoc = aObj->document();
+        SessionPtr aMgr = ModelAPI_Session::get();
+        return (aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument());
+      }
+    }
+  }
+  return Standard_False;
+}
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+
+Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+  if (theOwner->HasSelectable()) {
+    Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+    if (!aShapeOwner.IsNull()) {
+      TopoDS_Shape aShape = aShapeOwner->Shape();
+      TopAbs_ShapeEnum aType = aShape.ShapeType();
+      switch (aType) {
+      case TopAbs_VERTEX:
+        {
+          gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
+          return myPlane.Distance(aPnt) < Precision::Confusion();
+        }
+      case TopAbs_EDGE:
+        {
+          TopoDS_Edge aEdge = TopoDS::Edge(aShape);
+          Standard_Real aFirst, aLast;
+          Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
+          gp_Pnt aFirstPnt = aCurve->Value(aFirst);
+          gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
+          gp_Pnt aLastPnt = aCurve->Value(aLast);
+          bool aD1 = myPlane.Distance(aFirstPnt) < Precision::Confusion();
+          bool aD2 = myPlane.Distance(aMidPnt) < Precision::Confusion();
+          bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion();
+          return aD1 && aD2 && aD3;
+        }
+      }
+    } else {
+      // This is not object controlled by the filter
+      return Standard_True;
+    }
+  }
+  return Standard_False;
+}
diff --git a/src/ModuleBase/ModuleBase_ViewerFilters.h b/src/ModuleBase/ModuleBase_ViewerFilters.h
new file mode 100644 (file)
index 0000000..d26d3db
--- /dev/null
@@ -0,0 +1,55 @@
+// File:        ModuleBase_ViewerFilters.h
+// Created:     07 Okt 2014
+// Author:      Vitaly SMETANNIKOV
+
+
+#ifndef ModuleBase_ViewerFilters_H
+#define ModuleBase_ViewerFilters_H
+
+#include <SelectMgr_Filter.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <gp_Pln.hxx>
+
+
+class ModuleBase_IWorkshop;
+
+
+/**
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select objects which belong to 
+* currently active document or to global document
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
+class ModuleBase_ShapeDocumentFilter: public SelectMgr_Filter
+{
+public:
+  Standard_EXPORT ModuleBase_ShapeDocumentFilter(ModuleBase_IWorkshop* theWorkshop): SelectMgr_Filter(),
+    myWorkshop(theWorkshop) {}
+
+  Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+  DEFINE_STANDARD_RTTI(ModuleBase_ShapeDocumentFilter)
+
+private:
+  ModuleBase_IWorkshop* myWorkshop;
+};
+
+/**
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select of Vertexes and Edges which belongs to the given plane
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+class ModuleBase_ShapeInPlaneFilter: public SelectMgr_Filter
+{
+public:
+  Standard_EXPORT ModuleBase_ShapeInPlaneFilter(const gp_Pln& thePane): 
+      SelectMgr_Filter(), myPlane(thePane) {}
+
+  Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+  DEFINE_STANDARD_RTTI(ModuleBase_ShapeInPlaneFilter)
+private:
+  gp_Pln myPlane;
+};
+
+#endif
\ No newline at end of file
index 6cd23ff9794843c679d57f36f9beda1196a8b134..cc0197d577d18d90a5876633cfdf4ce348c92262 100644 (file)
@@ -24,11 +24,11 @@ ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent,
 {
   QString aText = QString::fromStdString(theData->widgetLabel());
   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
-  QString aDefault = QString::fromStdString(theData->getProperty("default"));
+  bool isChecked = theData->getBooleanAttribute(ANY_WDG_DEFAULT, false);
 
   myCheckBox = new QCheckBox(aText, theParent);
   myCheckBox->setToolTip(aToolTip);
-  myCheckBox->setChecked(aDefault == "true");
+  myCheckBox->setChecked(isChecked);
 
   connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
 }
index ba5a281eda49256daa308c3571deff2a360c2da0..3a3ed74593529adbb266e78327d359a3717ec81d 100644 (file)
@@ -3,6 +3,7 @@
 // Author:      Vitaly Smetannikov
 
 #include "ModuleBase_WidgetChoice.h"
+#include <ModuleBase_Tools.h>
 
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_Data.h>
@@ -20,7 +21,7 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
 {
   myContainer = new QWidget(theParent);
   QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
-  aLayout->setContentsMargins(0, 0, 0, 0);
+  ModuleBase_Tools::adjustMargins(aLayout);
 
   QString aLabelText = QString::fromStdString(theData->widgetLabel());
   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
@@ -82,4 +83,4 @@ void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
 {
   emit valuesChanged();
   emit focusOutWidget(this);
-}
\ No newline at end of file
+}
index 6d470dbbd14567860f40444e50068f7f1ce2b6e6..922ab91519dde70b29a459e79aa762472c752bff 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <ModuleBase_WidgetDoubleValue.h>
 #include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
@@ -18,7 +19,6 @@
 #include <QLayout>
 #include <QLabel>
 #include <QEvent>
-#include <QKeyEvent>
 #include <QTimer>
 
 #include <math.h>
@@ -37,7 +37,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
 {
   myContainer = new QWidget(theParent);
   QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
-  aControlLay->setContentsMargins(0, 0, 0, 0);
+  ModuleBase_Tools::adjustMargins(aControlLay);
 
   QString aLabelText = QString::fromStdString(theData->widgetLabel());
   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
@@ -77,7 +77,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
     mySpinBox->setSingleStep(aStepVal);
   }
 
-  aProp = theData->getProperty(DOUBLE_WDG_DEFAULT);
+  aProp = theData->getProperty(ANY_WDG_DEFAULT);
   double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
   if (isOk) {
     mySpinBox->setValue(aDefVal);
@@ -92,8 +92,6 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
   aControlLay->setStretch(1, 1);
 
   connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
-
-  mySpinBox->installEventFilter(this);
 }
 
 ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
index 6f32c7606bba64efe3d4c8b9685bd751c90e83d3..ee5bc67f476ba024490da025fc8dbea9f5f87b10 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <ModuleBase_WidgetEditor.h>
 #include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -40,7 +41,7 @@ double editedValue(double theValue, bool& isDone)
   QDialog aDlg;
   aDlg.setWindowFlags(Qt::FramelessWindowHint);
   QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
-  aLay->setContentsMargins(0, 0, 0, 0);
+  ModuleBase_Tools::zeroMargins(aLay);
 
   QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg);
   aEditor->setValidator(new QDoubleValidator(aEditor));
index 00a479ad10c1ec8fb14a88cdc04c796ab1ab6463..bd45e4ee04ae26eabd8b8a42cbde496e3f80423b 100644 (file)
 #include <ModuleBase_WidgetChoice.h>
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IModule.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_WidgetLineEdit.h>
+#include <ModuleBase_WidgetMultiSelector.h>
+
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -53,6 +58,7 @@ ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(const std::string& theXmlRepr
 
 ModuleBase_WidgetFactory::~ModuleBase_WidgetFactory()
 {
+  delete myWidgetApi;
 }
 
 void ModuleBase_WidgetFactory::createWidget(QWidget* theParent)
@@ -62,13 +68,12 @@ void ModuleBase_WidgetFactory::createWidget(QWidget* theParent)
     return;
 
   QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent);
-  aWidgetLay->setContentsMargins(2, 2, 2, 2);
   do {  //Iterate over each node
     std::string aWdgType = myWidgetApi->widgetType();
     //Create a widget (doublevalue, groupbox, toolbox, etc.
     QWidget* aWidget = createWidgetByType(aWdgType, theParent);
     if (aWidget) {
-      if (!myWidgetApi->getBooleanAttribute(FEATURE_INTERNAL, false)) {
+      if (!myWidgetApi->getBooleanAttribute(ATTRIBUTE_INTERNAL, false)) {
         aWidgetLay->addWidget(aWidget);
       } else {
         aWidget->setVisible(false);
@@ -78,6 +83,7 @@ void ModuleBase_WidgetFactory::createWidget(QWidget* theParent)
       //if current widget is groupbox (container) process it's children recursively
       QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
       createWidget(aWidget);
+      ModuleBase_Tools::adjustMargins(aWidget);
       QGroupBox* aGrBox = qobject_cast<QGroupBox*>(aWidget);
       aGrBox->setTitle(aGroupName);
     }
@@ -88,6 +94,7 @@ void ModuleBase_WidgetFactory::createWidget(QWidget* theParent)
       do {
         QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
         QWidget* aPage = new QWidget(aWidget);
+        ModuleBase_Tools::adjustMargins(aPage);
         createWidget(aPage);
         if (aWdgType == WDG_SWITCH) {
           ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
@@ -116,6 +123,25 @@ QWidget* ModuleBase_WidgetFactory::labelControl(QWidget* theParent)
   return result;
 }
 
+void ModuleBase_WidgetFactory::processAttributes()
+{
+  // register that this attribute in feature is not obligatory for the feature execution
+  // so, it is not needed for the standard validation mechanism
+  bool isObligatory = true;
+  bool isConcealment = false;
+  if( myWidgetApi ){
+    isObligatory = myWidgetApi->getBooleanAttribute(ATTRIBUTE_OBLIGATORY, true);
+    isConcealment = myWidgetApi->getBooleanAttribute(ATTRIBUTE_CONCEALMENT, false);
+  }
+  boost::shared_ptr<ModelAPI_Session> aSession = ModelAPI_Session::get();
+  if (!isObligatory) {
+    aSession->validators()->registerNotObligatory(myParentId, myWidgetApi->widgetId());
+  }
+  if(isConcealment) {
+    aSession->validators()->registerConcealment(myParentId, myWidgetApi->widgetId());
+  }
+}
+
 QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
                                                       QWidget* theParent)
 {
@@ -153,6 +179,12 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType
   } else if (theType == WDG_CHOICE) {
     result = choiceControl(theParent);
 
+  } else if (theType == WDG_STRINGVALUE) {
+    result = lineEditControl(theParent);
+
+  } else if (theType == WDG_MULTISELECTOR) {
+    result = multiSelectorControl(theParent);
+
   } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
     result = createContainer(theType, theParent);
   } else {
@@ -163,14 +195,7 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType
 #endif
   }
   if (result) {
-    // register that this attribute in feature is not obligatory for the feature execution
-    // so, it is not needed for the standard validation mechanism
-    bool isObligatory = 
-      myWidgetApi ? myWidgetApi->getBooleanAttribute(FEATURE_OBLIGATORY, true) : true;
-    if (!isObligatory) {
-      ModelAPI_Session::get()->validators()->registerNotObligatory(
-        myParentId, myWidgetApi->widgetId());
-    }
+    processAttributes();
   }
 
   return result;
@@ -276,6 +301,22 @@ QWidget* ModuleBase_WidgetFactory::choiceControl(QWidget* theParent)
   return aChoiceWgt->getControl();
 }
 
+QWidget* ModuleBase_WidgetFactory::lineEditControl(QWidget* theParent)
+{
+  ModuleBase_WidgetLineEdit* aLineEditWgt =
+      new ModuleBase_WidgetLineEdit(theParent, myWidgetApi,myParentId);
+  myModelWidgets.append(aLineEditWgt);
+  return aLineEditWgt->getControl();
+}
+
+QWidget* ModuleBase_WidgetFactory::multiSelectorControl(QWidget* theParent)
+{
+  ModuleBase_WidgetMultiSelector* aMultiselectorWgt =
+      new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId);
+  myModelWidgets.append(aMultiselectorWgt);
+  return aMultiselectorWgt->getControl();
+}
+
 QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
 {
   return QString::fromStdString(theStdString);
index 6ea4debf31035e2c1bfae2b586f509b5f574bfab..43b8208b6596d3912f436ea914ded46e337e8ab5 100644 (file)
@@ -48,8 +48,12 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory
   QWidget* point2dDistanceControl(QWidget* theParent);
   QWidget* fileSelectorControl(QWidget* theParent);
   QWidget* choiceControl(QWidget* theParent);
+  QWidget* lineEditControl(QWidget* theParent);
+  QWidget* multiSelectorControl(QWidget* theParent);
+
 
   QString qs(const std::string& theStdString) const;
+  void processAttributes();
 
  private:
   Config_WidgetAPI* myWidgetApi;
index 4269711c8a3d15eea287901016083d28857aadf5..faf664fe53e9d48180ac7323988e5be4e256808f 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <ModuleBase_WidgetValueFeature.h>
 #include <ModuleBase_WidgetValue.h>
+#include <ModuleBase_Tools.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -20,6 +21,7 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_ResultValidator.h>
 #include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_Session.h>
 
 #include <QWidget>
 #include <QLineEdit>
@@ -33,7 +35,7 @@ ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent,
 {
   myContainer = new QWidget(theParent);
   QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
-  aControlLay->setContentsMargins(0, 0, 0, 0);
+  ModuleBase_Tools::adjustMargins(aControlLay);
 
   QString aLabelText = QString::fromStdString(theData->widgetLabel());
   myLabel = new QLabel(aLabelText, myContainer);
index a2e8186c8f2e85797ae3468b11507ab77f803405..36191b141ad90918838b0122f2bacc47ccbc7fa0 100644 (file)
@@ -8,7 +8,10 @@
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
 #include <ModuleBase_WidgetFileSelector.h>
+#include <ModuleBase_Tools.h>
 
 #include <Config_WidgetAPI.h>
 
@@ -30,13 +33,11 @@ ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent,
     : ModuleBase_ModelWidget(theParent, theData, theParentId)
 {
   myTitle = QString::fromStdString(theData->getProperty("title"));
-  //TODO(sbh): Get them from the feature
-  myFormats = getSupportedFormats(theData);
   myDefaultPath = QString::fromStdString(theData->getProperty("path"));
 
   myMainWidget = new QWidget(theParent);
   QGridLayout* aMainLay = new QGridLayout(myMainWidget);
-  aMainLay->setContentsMargins(0, 0, 0, 0);
+  ModuleBase_Tools::adjustMargins(aMainLay);
   QLabel* aTitleLabel = new QLabel(myTitle, myMainWidget);
   aTitleLabel->setIndent(1);
   aMainLay->addWidget(aTitleLabel, 0, 0);
@@ -63,6 +64,9 @@ ModuleBase_WidgetFileSelector::~ModuleBase_WidgetFileSelector()
 
 bool ModuleBase_WidgetFileSelector::storeValue() const
 {
+  // A rare case when plugin was not loaded. 
+  if(!myFeature)
+    return false;
   DataPtr aData = myFeature->data();
   AttributeStringPtr aStringAttr = aData->string(attributeID());
   QString aWidgetValue = myPathField->text();
@@ -73,6 +77,9 @@ bool ModuleBase_WidgetFileSelector::storeValue() const
 
 bool ModuleBase_WidgetFileSelector::restoreValue()
 {
+  // A rare case when plugin was not loaded. 
+  if(!myFeature)
+    return false;
   DataPtr aData = myFeature->data();
   AttributeStringPtr aStringAttr = aData->string(attributeID());
 
@@ -100,13 +107,13 @@ QList<QWidget*> ModuleBase_WidgetFileSelector::getControls() const
 bool ModuleBase_WidgetFileSelector::isCurrentPathValid()
 {
   QFileInfo aFile (myPathField->text());
-  return aFile.exists() && myFormats.contains(aFile.suffix(), Qt::CaseInsensitive);
+  return aFile.exists();
 }
 
 
 void ModuleBase_WidgetFileSelector::onPathSelectionBtn()
 {
-  QString aFilter = formatsString(myFormats);
+  QString aFilter = formatsString();
   QString aFileName = QFileDialog::getOpenFileName(myMainWidget, myTitle, myDefaultPath, aFilter);
   if (!aFileName.isEmpty()) {
     myPathField->setText(aFileName);
@@ -121,20 +128,40 @@ void ModuleBase_WidgetFileSelector::onPathChanged()
   emit valuesChanged();
 }
 
-QStringList ModuleBase_WidgetFileSelector::getSupportedFormats(const Config_WidgetAPI* theData) const
-{
-  QString aXMLFormat = QString::fromStdString(theData->getProperty("formats"));
-  aXMLFormat = aXMLFormat.toUpper();
-  const QChar kSep = ',';
-  return aXMLFormat.split(kSep, QString::SkipEmptyParts);
-}
-
-QString ModuleBase_WidgetFileSelector::formatsString(const QStringList theFormats) const
+QString ModuleBase_WidgetFileSelector::formatsString() const
 {
   QStringList aResult;
-  foreach(QString eachFormat, theFormats)  {
+  QStringList aValidatorFormats = getValidatorFormats();
+
+  foreach(QString eachFormat, aValidatorFormats)  {
     aResult << QString("%1 files (*.%1)").arg(eachFormat);
   }
+  aResult << QString("All files (*.*)");
   return aResult.join(";;");
 }
 
+QStringList ModuleBase_WidgetFileSelector::getValidatorFormats() const
+{
+  SessionPtr aMgr = ModelAPI_Session::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  std::list<ModelAPI_Validator*> allValidators;
+  std::list<std::list<std::string> > allArguments;
+  aFactory->validators(myFeature->getKind(), myAttributeID, allValidators, allArguments);
+  //TODO(sbh): extract as separate method
+  if(allArguments.empty())
+    return QStringList();
+  std::list<std::string> anArgumentList = allArguments.front();
+  std::list<std::string>::const_iterator it = anArgumentList.begin();
+  QStringList aResult;
+  for (; it != anArgumentList.end(); ++it) {
+    std::string anArg = *it;
+    int aSepPos = anArg.find(":");
+    if (aSepPos == std::string::npos) {
+      continue;
+    }
+    QString aFormat = QString::fromStdString(anArg.substr(0, aSepPos));
+    aFormat = aFormat.toUpper();
+    aResult.append(aFormat);
+  }
+  return aResult;
+}
index 2d48e430b57a4510900234ec79090b636a2616e1..4e78830aa2b8b7fe8fed6dad7b857472f34b42bb 100644 (file)
@@ -50,13 +50,12 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelW
   void onPathChanged();
 
  protected:
-  QStringList getSupportedFormats(const Config_WidgetAPI* theData) const;
-  QString formatsString(const QStringList theFormats) const;
+  QString formatsString() const;
+  QStringList getValidatorFormats() const;
 
  private:
   QLineEdit* myPathField;
   QWidget* myMainWidget;
-  QStringList myFormats;
 
   QString myTitle;
   QString myDefaultPath;
diff --git a/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp b/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp
new file mode 100644 (file)
index 0000000..bf311c5
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * ModuleBase_WidgetLineEdit.cpp
+ *
+ *  Created on: Aug 28, 2014
+ *      Author: sbh
+ */
+
+#include <ModuleBase_WidgetLineEdit.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_Validator.h>
+
+#include <Config_WidgetAPI.h>
+
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QObject>
+#include <QString>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+#include <string>
+
+ModuleBase_WidgetLineEdit::ModuleBase_WidgetLineEdit(QWidget* theParent,
+                                                     const Config_WidgetAPI* theData,
+                                                     const std::string& theParentId)
+    : ModuleBase_ModelWidget(theParent, theData, theParentId)
+{
+  myMainWidget = new QWidget(theParent);
+  QHBoxLayout* aMainLay = new QHBoxLayout(myMainWidget);
+  ModuleBase_Tools::adjustMargins(aMainLay);
+  QString aTitle = QString::fromStdString(theData->widgetLabel());
+  QLabel* aTitleLabel = new QLabel(aTitle, myMainWidget);
+  aMainLay->addWidget(aTitleLabel);
+  myLineEdit = new QLineEdit(myMainWidget);
+  aMainLay->addWidget(myLineEdit);
+  myLineEdit->setMinimumHeight(20);
+  myMainWidget->setLayout(aMainLay);
+
+  connect(myLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged()));
+}
+
+ModuleBase_WidgetLineEdit::~ModuleBase_WidgetLineEdit()
+{
+}
+
+bool ModuleBase_WidgetLineEdit::storeValue() const
+{
+  // A rare case when plugin was not loaded. 
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string(attributeID());
+  QString aWidgetValue = myLineEdit->text();
+  aStringAttr->setValue(aWidgetValue.toStdString());
+  updateObject(myFeature);
+  return true;
+}
+
+bool ModuleBase_WidgetLineEdit::restoreValue()
+{
+  // A rare case when plugin was not loaded. 
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string(attributeID());
+
+  bool isBlocked = myLineEdit->blockSignals(true);
+  myLineEdit->setText(QString::fromStdString(aStringAttr->value()));
+  myLineEdit->blockSignals(isBlocked);
+
+  return true;
+}
+
+QWidget* ModuleBase_WidgetLineEdit::getControl() const
+{
+  return myMainWidget;
+}
+
+QList<QWidget*> ModuleBase_WidgetLineEdit::getControls() const
+{
+  QList<QWidget*> result;
+  result << myLineEdit;
+  return result;
+}
+
+void ModuleBase_WidgetLineEdit::onTextChanged()
+{
+  storeValue();
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetLineEdit.h b/src/ModuleBase/ModuleBase_WidgetLineEdit.h
new file mode 100644 (file)
index 0000000..92eff34
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * ModuleBase_WidgetLineEdit.h
+ *
+ *  Created on: Oct 8, 2014
+ *      Author: sbh
+ */
+
+#ifndef MODULEBASE_WIDGETLINEEDIT_H_
+#define MODULEBASE_WIDGETLINEEDIT_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+#include <QList>
+#include <QString>
+#include <QStringList>
+
+class QWidget;
+class QLineEdit;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetLineEdit : public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+ public:
+  ModuleBase_WidgetLineEdit(QWidget* theParent,
+                                const Config_WidgetAPI* theData,
+                                const std::string& theParentId);
+  virtual ~ModuleBase_WidgetLineEdit();
+
+  /// Saves the internal parameters to the given feature
+  /// \param theObject a model feature to be changed
+  virtual bool storeValue() const;
+
+  virtual bool restoreValue();
+
+  /// Returns the internal parent wiget control, that can be shown anywhere
+  /// \returns the widget
+  QWidget* getControl() const;
+
+  /// Returns list of widget controls
+  /// \return a control list
+  virtual QList<QWidget*> getControls() const;
+
+ public slots:
+  void onTextChanged();
+
+ private:
+  QLineEdit* myLineEdit;
+  QWidget* myMainWidget;
+};
+
+#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
new file mode 100644 (file)
index 0000000..ed40ee2
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * ModuleBase_WidgetMultiSelector.cpp
+ *
+ *  Created on: Aug 28, 2014
+ *      Author: sbh
+ */
+
+#include <ModuleBase_WidgetMultiSelector.h>
+#include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
+#include <Config_WidgetAPI.h>
+
+#include <QGridLayout>
+#include <QLabel>
+#include <QListWidget>
+#include <QObject>
+#include <QString>
+#include <QComboBox>
+#include <QEvent>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+#include <string>
+
+ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
+                                                               ModuleBase_IWorkshop* theWorkshop,
+                                                               const Config_WidgetAPI* theData,
+                                                               const std::string& theParentId)
+    : ModuleBase_ModelWidget(theParent, theData, theParentId),
+      myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false)
+{
+  myMainWidget = new QWidget(theParent);
+  QGridLayout* aMainLay = new QGridLayout(myMainWidget);
+  ModuleBase_Tools::adjustMargins(aMainLay);
+
+  QLabel* aTypeLabel = new QLabel(tr("Type"), myMainWidget);
+  aMainLay->addWidget(aTypeLabel, 0, 0);
+
+  myTypeCombo = new QComboBox(myMainWidget);
+  // There is no sence to paramerize list of types while we can not parametrize selection mode
+  QString aTypesStr("Vertices Edges Faces Solids");
+  myShapeTypes = aTypesStr.split(' ');
+  myTypeCombo->addItems(myShapeTypes);
+  aMainLay->addWidget(myTypeCombo, 0, 1);
+
+  QLabel* aListLabel = new QLabel(tr("Selected objects:"), myMainWidget);
+  aMainLay->addWidget(aListLabel, 1, 0, 1, -1);
+
+  myListControl = new QListWidget(myMainWidget);
+  aMainLay->addWidget(myListControl, 2, 0, 2, -1);
+  aMainLay->setColumnStretch(1, 1);
+  myMainWidget->setLayout(aMainLay);
+
+  //TODO: Move into the base class
+  myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false);
+  //TODO_END
+  connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged()));
+  activateSelection(true);
+}
+
+ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
+{
+  activateSelection(false);
+}
+
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::storeValue() const
+{
+  // A rare case when plugin was not loaded. 
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelectionListAttr = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+  if (aSelectionListAttr && (mySelection.size() > 0)) {
+    aSelectionListAttr->clear();
+    foreach (GeomSelection aSelec, mySelection) {
+      aSelectionListAttr->append(aSelec.first, aSelec.second);
+    }
+    updateObject(myFeature);
+    return true;
+  }
+  return false;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::restoreValue()
+{
+  // A rare case when plugin was not loaded. 
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelectionListAttr = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+  if (aSelectionListAttr) {
+    mySelection.clear();
+    for (int i = 0; i < aSelectionListAttr->size(); i++) {
+      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+      mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
+    }
+    updateSelectionList();
+    return true;
+  }
+  return false;
+}
+
+//********************************************************************
+QWidget* ModuleBase_WidgetMultiSelector::getControl() const
+{
+  return myMainWidget;
+}
+
+//********************************************************************
+QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
+{
+  QList<QWidget*> result;
+  result << myTypeCombo;
+  result << myListControl;
+  return result;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::eventFilter(QObject* theObj, QEvent* theEvent)
+{
+  if (theObj == myListControl) {
+    if (theEvent->type() == QEvent::FocusIn)
+      activateSelection(true);
+  }
+  return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onSelectionChanged()
+{
+  ModuleBase_ISelection* aSelection = myWorkshop->selection();
+  NCollection_List<TopoDS_Shape> aSelectedShapes; //, aFilteredShapes;
+  std::list<ObjectPtr> aOwnersList;
+  aSelection->selectedShapes(aSelectedShapes, aOwnersList);
+
+  mySelection.clear();
+  std::list<ObjectPtr>::const_iterator aIt;
+  NCollection_List<TopoDS_Shape>::Iterator aShpIt(aSelectedShapes);
+  GeomShapePtr aShape;
+  for (aIt = aOwnersList.cbegin(); aIt != aOwnersList.cend(); aShpIt.Next(), aIt++) {
+    ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(*aIt);
+    aShape = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+    aShape->setImpl(new TopoDS_Shape(aShpIt.Value()));
+    mySelection.append(GeomSelection(aResult, aShape));
+  }
+  updateSelectionList();
+  storeValue();
+  emit valuesChanged();
+}
+
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::updateSelectionList()
+{
+  QString aType;
+  if (myTypeCombo->currentText().toLower() == "vertices")
+    aType = "vertex";
+  else if (myTypeCombo->currentText().toLower() == "edges")
+    aType = "edge";
+  else if (myTypeCombo->currentText().toLower() == "faces")
+    aType = "face";
+  else if (myTypeCombo->currentText().toLower() == "solids")
+    aType = "solid";
+  myListControl->clear();
+  int i = 1;
+  foreach (GeomSelection aSel, mySelection) {
+    QString aName(aSel.first->data()->name().c_str());
+    aName += ":" + aType + QString("_%1").arg(i);
+    myListControl->addItem(aName);
+    i++;
+  }
+}
+
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
+                                                  NCollection_List<TopoDS_Shape>& theResult)
+{
+  if(myTypeCombo->count() == 0 || theShapesToFilter.IsEmpty())
+    return;
+  TopAbs_ShapeEnum aReferenceType =
+      ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText());
+  NCollection_List<TopoDS_Shape>::Iterator anIter(theShapesToFilter);
+  for (; anIter.More(); anIter.Next()) {
+    TopoDS_Shape aShape = anIter.Value();
+    if (aShape.IsNull() || aShape.ShapeType() != aReferenceType)
+      continue;
+    theResult.Append(aShape);
+  }
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate)
+{
+  myIsActive = toActivate;
+  if (myIsActive) {
+    connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+    onSelectionTypeChanged();
+  } else {
+    disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+    myWorkshop->deactivateSubShapesSelection();
+  }
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
+{
+  QString aNewType = myTypeCombo->currentText();
+  QIntList aList;
+  aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType));
+  myWorkshop->activateSubShapesSelection(aList);
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h
new file mode 100644 (file)
index 0000000..c141c87
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * ModuleBase_WidgetMultiSelector.h
+ *
+ *  Created on: Oct 8, 2014
+ *      Author: sbh
+ */
+
+#ifndef MODULEBASE_WIDGETMULTISELECTOR_H_
+#define MODULEBASE_WIDGETMULTISELECTOR_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+#include <GeomAPI_Shape.h>
+#include <ModelAPI_Result.h>
+
+#include <NCollection_List.hxx>
+#include <TopoDS_Shape.hxx>
+
+#include <QList>
+#include <QString>
+#include <QStringList>
+#include <QPair>
+
+class QWidget;
+class QListWidget;
+class QComboBox;
+class ModuleBase_IWorkshop;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+ public:
+  ModuleBase_WidgetMultiSelector(QWidget* theParent,
+                                 ModuleBase_IWorkshop* theWorkshop,
+                                 const Config_WidgetAPI* theData,
+                                 const std::string& theParentId);
+  virtual ~ModuleBase_WidgetMultiSelector();
+
+  /// Saves the internal parameters to the given feature
+  /// \param theObject a model feature to be changed
+  virtual bool storeValue() const;
+
+  virtual bool restoreValue();
+
+  /// Returns the internal parent wiget control, that can be shown anywhere
+  /// \returns the widget
+  QWidget* getControl() const;
+
+  /// Returns list of widget controls
+  /// \return a control list
+  virtual QList<QWidget*> getControls() const;
+
+  virtual bool eventFilter(QObject* theObj, QEvent* theEvent);
+
+ public slots:
+  void activateSelection(bool toActivate);
+  void onSelectionTypeChanged();
+  void onSelectionChanged();
+
+ protected:
+  void filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
+                    NCollection_List<TopoDS_Shape>& theResult);
+
+ private:
+   void updateSelectionList();
+
+  QListWidget* myListControl;
+  QComboBox* myTypeCombo;
+  QWidget* myMainWidget;
+
+  //TODO: Move into the base of selectors
+  ModuleBase_IWorkshop* myWorkshop;
+
+  /// If true then local selector has to be activated in context
+  QStringList myShapeTypes;
+  bool myUseSubShapes;
+  bool myIsActive;
+
+  typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
+  QList<GeomSelection> mySelection;
+};
+
+#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
index 8feec7a6c5e96aa9f7d7983c0d4e7af82a8b9cf7..21cef047dc80351fff5b0ca7a32d1aaa36d132b8 100644 (file)
@@ -5,6 +5,7 @@
 #include <ModuleBase_WidgetPoint2D.h>
 #include <ModuleBase_WidgetValueFeature.h>
 #include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -22,7 +23,6 @@
 #include <QGridLayout>
 #include <QLabel>
 #include <QEvent>
-#include <QKeyEvent>
 
 #include <cfloat>
 #include <climits>
@@ -33,10 +33,12 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
     : ModuleBase_ModelWidget(theParent, theData, theParentId)
 {
   myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
-  myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)),
-                             theParent);
+  QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
+  myGroupBox = new QGroupBox(aPageName, theParent);
+  myGroupBox->setFlat(false);
+
   QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
-  aGroupLay->setContentsMargins(2, 0, 2, 0);
+  ModuleBase_Tools::adjustMargins(aGroupLay);
   aGroupLay->setColumnStretch(1, 1);
   {
     QLabel* aLabel = new QLabel(myGroupBox);
@@ -66,8 +68,6 @@ ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
 
     connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
   }
-  myXSpin->installEventFilter(this);
-  myYSpin->installEventFilter(this);
 }
 
 ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
@@ -107,11 +107,18 @@ bool ModuleBase_WidgetPoint2D::storeValue() const
   boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(attributeID()));
-
+  
   ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
   bool isBlocked = that->blockSignals(true);
+  bool isImmutable = aPoint->setImmutable(true);
+#ifdef _DEBUG
+  std::string _attr_name = myAttributeID;
+  double _X = myXSpin->value();
+  double _Y = myYSpin->value();
+#endif
   aPoint->setValue(myXSpin->value(), myYSpin->value());
   updateObject(myFeature);
+  aPoint->setImmutable(isImmutable);
   that->blockSignals(isBlocked);
 
   return true;
@@ -123,6 +130,11 @@ bool ModuleBase_WidgetPoint2D::restoreValue()
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(attributeID()));
 
+#ifdef _DEBUG
+  std::string _attr_name = myAttributeID;
+  double _X = aPoint->x();
+  double _Y = aPoint->y();
+#endif
   bool isBlocked = this->blockSignals(true);
   myXSpin->setValue(aPoint->x());
   myYSpin->setValue(aPoint->y());
index e0c12b1973b8ba8d4534b33f5593dc83a72d619d..d7518ef6098d73f87483810815450ddebb11fba7 100644 (file)
@@ -2,18 +2,29 @@
 // Created:     2 June 2014
 // Author:      Vitaly Smetannikov
 
-#include "ModuleBase_WidgetShapeSelector.h"
-#include "ModuleBase_IWorkshop.h"
-
+#include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_Definitions.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_WidgetValueFeature.h>
+#include <Config_WidgetAPI.h>
 #include <Events_Loop.h>
-#include <ModelAPI_Events.h>
-#include <ModelAPI_Tools.h>
-
+#include <Events_Message.h>
+#include <GeomAPI_Interface.h>
+#include <GeomAPI_Shape.h>
+#include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_Data.h>
-#include <ModelAPI_Object.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Tools.h>
 #include <Config_WidgetAPI.h>
+#include <Events_Error.h>
 
 #include <GeomAPI_Shape.h>
 
 #include <QEvent>
 #include <QDockWidget>
 
-#include <stdexcept>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Shape.hxx>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <list>
+#include <string>
 
 typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
 static ShapeTypes MyShapeTypes;
@@ -38,15 +55,21 @@ TopAbs_ShapeEnum ModuleBase_WidgetShapeSelector::shapeType(const QString& theTyp
 {
   if (MyShapeTypes.count() == 0) {
     MyShapeTypes["face"] = TopAbs_FACE;
+    MyShapeTypes["faces"] = TopAbs_FACE;
     MyShapeTypes["vertex"] = TopAbs_VERTEX;
+    MyShapeTypes["vertices"] = TopAbs_VERTEX;
     MyShapeTypes["wire"] = TopAbs_WIRE;
     MyShapeTypes["edge"] = TopAbs_EDGE;
+    MyShapeTypes["edges"] = TopAbs_EDGE;
     MyShapeTypes["shell"] = TopAbs_SHELL;
     MyShapeTypes["solid"] = TopAbs_SOLID;
+    MyShapeTypes["solids"] = TopAbs_SOLID;
   }
-  if (MyShapeTypes.contains(theType))
-    return MyShapeTypes[theType];
-  throw std::invalid_argument("Shape type defined in XML is not implemented!");
+  QString aType = theType.toLower();
+  if (MyShapeTypes.contains(aType))
+    return MyShapeTypes[aType];
+  Events_Error::send("Shape type defined in XML is not implemented!");
+  return TopAbs_SHAPE;
 }
 
 ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,
@@ -54,12 +77,12 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen
                                                      const Config_WidgetAPI* theData,
                                                      const std::string& theParentId)
     : ModuleBase_ModelWidget(theParent, theData, theParentId),
-      myWorkshop(theWorkshop), myIsActive(false)
+      myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false)
 {
   myContainer = new QWidget(theParent);
   QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
+  ModuleBase_Tools::adjustMargins(aLayout);
 
-  aLayout->setContentsMargins(0, 0, 0, 0);
   QString aLabelText = QString::fromStdString(theData->widgetLabel());
   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
   myLabel = new QLabel(aLabelText, myContainer);
@@ -83,11 +106,14 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen
 
   std::string aTypes = theData->getProperty("shape_types");
   myShapeTypes = QString(aTypes.c_str()).split(' ');
+
+  myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false); 
 }
 
 //********************************************************************
 ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
 {
+  activateSelection(false);
 }
 
 //********************************************************************
@@ -98,25 +124,45 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const
     return false;
 
   DataPtr aData = myFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeReference> aRef = boost::dynamic_pointer_cast<
-      ModelAPI_AttributeReference>(aData->attribute(attributeID()));
-
-  ObjectPtr aObject = aRef->value();
-  if (!(aObject && aObject->isSame(mySelectedObject))) {
-    aRef->setValue(mySelectedObject);
-    updateObject(myFeature);
+  if (myUseSubShapes) {
+    boost::shared_ptr<ModelAPI_AttributeSelection> aSelect = 
+      boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aData->attribute(attributeID()));
+
+    ResultPtr aBody = boost::dynamic_pointer_cast<ModelAPI_Result>(mySelectedObject);
+    if (aBody) {
+      aSelect->setValue(aBody, myShape);
+      updateObject(myFeature);
+      return true;
+    }
+  } else {
+    boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
+      boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
+
+    ObjectPtr aObject = aRef->value();
+    if (!(aObject && aObject->isSame(mySelectedObject))) {
+      aRef->setValue(mySelectedObject);
+      updateObject(myFeature);
+      return true;
+    }
   }
-  return true;
+  return false;
 }
 
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::restoreValue()
 {
   DataPtr aData = myFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
-
   bool isBlocked = this->blockSignals(true);
-  mySelectedObject = aRef->value();
+  if (myUseSubShapes) {
+    boost::shared_ptr<ModelAPI_AttributeSelection> aSelect = aData->selection(attributeID());
+    if (aSelect) {
+      mySelectedObject = aSelect->context();
+      myShape = aSelect->value();
+    }
+  } else {
+    boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
+    mySelectedObject = aRef->value();
+  }
   updateSelectionName();
 
   this->blockSignals(isBlocked);
@@ -135,7 +181,7 @@ QList<QWidget*> ModuleBase_WidgetShapeSelector::getControls() const
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::onSelectionChanged()
 {
-  QList<ObjectPtr> aObjects = myWorkshop->selectedObjects();
+  QList<ObjectPtr> aObjects = myWorkshop->selection()->selectedObjects();
   if (aObjects.size() > 0) {
     ObjectPtr aObject = aObjects.first();
     if ((!mySelectedObject) && (!aObject))
@@ -143,26 +189,50 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
     if (mySelectedObject && aObject && mySelectedObject->isSame(aObject))
       return;
 
-    // Check that the selection corresponds to selection type
-    if (!isAccepted(aObject))
-      return;
+    // Get sub-shapes from local selection
+    boost::shared_ptr<GeomAPI_Shape> aShape;
+    if (myUseSubShapes) {
+      NCollection_List<TopoDS_Shape> aShapeList;
+      std::list<ObjectPtr> aOwners;
+      myWorkshop->selection()->selectedShapes(aShapeList, aOwners);
+      if (aShapeList.Extent() > 0) {
+        aShape = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+        aShape->setImpl(new TopoDS_Shape(aShapeList.First()));
+      }
+    }
 
-    mySelectedObject = aObject;
-    if (mySelectedObject) {
-      updateSelectionName();
-      raisePanel();
-      static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE);
-      ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent);
-      Events_Loop::loop()->flush(anEvent);
+    // Check that the selection corresponds to selection type
+    if (myUseSubShapes) {
+      if (!isAccepted(aShape))
+        return;
     } else {
-      myTextLine->setText("");
+      if (!isAccepted(aObject))
+        return;
     }
-    activateSelection(false);
-    emit valuesChanged();
+    setObject(aObject, aShape);
     emit focusOutWidget(this);
   }
 }
 
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape)
+{
+  if (mySelectedObject == theObj)
+    return;
+  mySelectedObject = theObj;
+  myShape = theShape;
+  if (mySelectedObject) {
+    raisePanel();
+    if (!myUseSubShapes) {
+      static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE);
+      ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent);
+    }
+  } 
+  updateSelectionName();
+  activateSelection(false);
+  emit valuesChanged();
+}
+
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
 {
@@ -176,6 +246,13 @@ bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
         return false;
     }
   }
+  // Check that object belongs to active document or PartSet
+  DocumentPtr aDoc = aResult->document();
+  SessionPtr aMgr = ModelAPI_Session::get();
+  if (!(aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument()))
+    return false;
+
+  // Check that the shape of necessary type
   boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
   if (!aShapePtr)
     return false;
@@ -199,6 +276,17 @@ bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
   return false;
 }
 
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::isAccepted(boost::shared_ptr<GeomAPI_Shape> theShape) const
+{
+  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+  foreach (QString aType, myShapeTypes) {
+    if (aShape.ShapeType() == shapeType(aType))
+      return true;
+  }
+  return false;
+}
+
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::updateSelectionName()
 {
@@ -232,13 +320,19 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate)
     myTextLine->setPalette(myInactivePalet);
   updateSelectionName();
 
-  if (myIsActive)
+  if (myIsActive) {
     connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-  else
+    if (myUseSubShapes) {
+      QIntList aList;
+      foreach (QString aType, myShapeTypes)
+        aList.append(shapeType(aType));
+      myWorkshop->activateSubShapesSelection(aList);
+    }
+  } else {
     disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-
-//  if (myWorkshop->selectedObjects().size() > 0)
-//    onSelectionChanged();
+    if (myUseSubShapes) 
+      myWorkshop->deactivateSubShapesSelection();
+  }
 }
 
 //********************************************************************
@@ -273,4 +367,22 @@ bool ModuleBase_WidgetShapeSelector::eventFilter(QObject* theObj, QEvent* theEve
       activateSelection(true);
   }
   return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
-}
\ No newline at end of file
+}
+
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::setValue(ModuleBase_WidgetValue* theValue)
+{
+  if (theValue) {
+    ModuleBase_WidgetValueFeature* aFeatureValue =
+        dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
+    if (aFeatureValue && aFeatureValue->object()) {
+      ObjectPtr aObject = aFeatureValue->object();
+      if (isAccepted(aObject)) {
+        setObject(aObject);
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
index 5defe3a2e492b6ef677d894515d8eee4433204c4..7d0a453f6931e4c25646fd6aac9bc739c57e5942 100644 (file)
@@ -9,6 +9,7 @@
 #include "ModuleBase_ModelWidget.h"
 
 #include <ModelAPI_Object.h>
+#include <GeomAPI_Shape.h>
 
 #include <TopAbs_ShapeEnum.hxx>
 
@@ -26,6 +27,8 @@ class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_Model
 {
 Q_OBJECT
  public:
+  static TopAbs_ShapeEnum shapeType(const QString& theType);
+
   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
                             const Config_WidgetAPI* theData, const std::string& theParentId);
 
@@ -55,7 +58,12 @@ Q_OBJECT
     return mySelectedObject;
   }
 
- public slots:
+  /// Set the given wrapped value to the current widget
+  /// This value should be processed in the widget according to the needs
+  /// \param theValue the wrapped widget value
+  virtual bool setValue(ModuleBase_WidgetValue* theValue);
+
+public slots:
 
   /// Activate or deactivate selection
   void activateSelection(bool toActivate);
@@ -70,8 +78,10 @@ private:
   void updateSelectionName();
   void raisePanel() const;
   bool isAccepted(const ObjectPtr theObject) const;
+  bool isAccepted(boost::shared_ptr<GeomAPI_Shape> theShape) const;
 
-  static TopAbs_ShapeEnum shapeType(const QString& theType);
+  // Set the given object as a value of the widget
+  void setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape = boost::shared_ptr<GeomAPI_Shape>());
 
   QWidget* myContainer;
   QLabel* myLabel;
@@ -81,8 +91,13 @@ private:
   ModuleBase_IWorkshop* myWorkshop;
 
   ObjectPtr mySelectedObject;
+  boost::shared_ptr<GeomAPI_Shape> myShape;
+
   QStringList myShapeTypes;
 
+  /// If true then local selector has to be activated in context
+  bool myUseSubShapes;
+
   QPalette myBasePalet;
   QPalette myInactivePalet;
 
index 1883fbb61b86da4da9c4618fa4825ca540bd1486..dcc5bdae5f8d38b2d72bec640556f748019309c3 100644 (file)
@@ -30,6 +30,7 @@ SET(PROJECT_LIBRARIES
     Events
     Config
        XGUI
+       ModuleBase
        ${QT_LIBRARIES}
        ${suit}
        ${std}
index 3b494373ff98b1190a2c8f83ca88cf7727db2103..267cb064740a4958beddfe3dc732bd7836e29f4c 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <XGUI_Workshop.h>
 
+#include <ModelAPI_Session.h>
+
 #include <LightApp_Study.h>
 #include <CAM_Application.h>
 #include <SUIT_Tools.h>
index 412407827058d8722fc4227bd3670c60c29b8743..6bb769fdafa20b1bfe402eca040e8418232c6361 100644 (file)
@@ -8,6 +8,9 @@
 #include <XGUI_ContextMenuMgr.h>
 #include <XGUI_Preferences.h>
 #include <XGUI_ObjectsBrowser.h>
+#include <XGUI_OperationMgr.h>
+
+#include <ModuleBase_Operation.h>
 
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
@@ -87,6 +90,9 @@ void NewGeom_Module::initialize(CAM_Application* theApp)
   LightApp_Module::initialize(theApp);
 
   myWorkshop->startApplication();
+  LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
+  if (anApp)
+    connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
 }
 
 //******************************************************
@@ -125,7 +131,6 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
         mySelector = createSelector(OCCViewManagers.first());
       }
     }
-    myWorkshop->propertyPanel()->hide();
     QtxPopupMgr* aMgr = popupMgr();  // Create popup manager
     action(myEraseAll)->setEnabled(false);
 
@@ -136,6 +141,17 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy)
       QTimer::singleShot(1000, myWorkshop, SLOT(displayAllResults()));
     }
   }
+  SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
+  myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
+
+  // this following row is caused by #187 bug.
+  // SALOME saves the dock widget positions before deactivateModule() and
+  // load it after the module activation. So, if the panel is visible before
+  // deactivate, it becomes visible after activate.
+  // In order to avoid the visible property panel, the widget position save is
+  // switch off in this module
+  aResMgr->setValue("Study", "store_positions", false);
+
   return isDone;
 }
 
@@ -145,9 +161,6 @@ bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
   setMenuShown(false);
   setToolShown(false);
 
-  myWorkshop->propertyPanel()->setVisible(false);
-  desktop()->removeDockWidget(myWorkshop->propertyPanel());
-
   QObject* aObj = myWorkshop->objectBrowser()->parent();
   QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
   if (aObjDoc) {
@@ -157,7 +170,27 @@ bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy)
     aViewAct->setEnabled(false);
   }
 
+  // the active operation should be stopped for the next activation.
+  // There should not be active operation and visualized preview.
+  // Abort operation should be performed before the selection's remove
+  // because the displayed objects should be removed from the viewer, but
+  // the AIS context is obtained from the selector.
+  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+  if (anOperation)
+    anOperation->abort();
+
+  // Delete selector because it has to be redefined on next activation
+  if (mySelector) {
+    myProxyViewer->setSelector(0);
+    delete mySelector;
+    mySelector = 0;
+  }
+
   //myWorkshop->contextMenuMgr()->disconnectViewer();
+
+  SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
+  aResMgr->setValue("Study", "store_positions", myIsStorePositions);
+
   return LightApp_Module::deactivateModule(theStudy);
 }
 
@@ -169,6 +202,17 @@ void NewGeom_Module::onViewManagerAdded(SUIT_ViewManager* theMgr)
   }
 }
 
+//******************************************************
+void NewGeom_Module::onDefaultPreferences()
+{
+  XGUI_Preferences::resetConfig();
+  XGUI_Preferences::updateResourcesByConfig();
+
+  LightApp_Preferences* pref = preferences();
+  if (pref)
+    pref->retrieve();
+}
+
 //******************************************************
 NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
 {
@@ -298,6 +342,21 @@ QStringList NewGeom_Module::nestedActions(const QString& theId) const
   return QStringList();
 }
 
+//******************************************************
+void NewGeom_Module::setDocumentKind(const QString& theId, const QString& theKind)
+{
+  myDocumentType[theId] = theKind;
+}
+
+//******************************************************
+QString NewGeom_Module::documentKind(const QString& theId) const
+{
+  if (myDocumentType.contains(theId))
+    return myDocumentType[theId];
+  return QString();
+
+}
+
 //******************************************************
 void NewGeom_Module::selectionChanged()
 {
@@ -319,7 +378,7 @@ void NewGeom_Module::createPreferences()
   LightApp_Preferences* pref = preferences();
   if (!pref)
     return;
-  XGUI_Preferences::updateCustomProps();
+  XGUI_Preferences::updateConfigByResources();
   QString aModName = moduleName();
 
   QtxPreferenceItem* item = pref->findItem(aModName, true );
@@ -341,8 +400,16 @@ void NewGeom_Module::preferencesChanged(const QString& theSection, const QString
 {
   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
   QString aVal = aResMgr->stringValue(theSection, theParam);
-  if (!aVal.isNull()) {
-    Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
-    aProp->setValue(aVal.toStdString());
+  Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
+  std::string aValue = aVal.toStdString();
+  if (aValue.empty()) {
+    aValue = aProp->defaultValue();
+    aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
+
+    LightApp_Preferences* pref = preferences();
+    if (pref)
+      pref->retrieve();
   }
+  aProp->setValue(aValue);
+
 }
index aad4775ca0fdb0376fc947cfb7dab3ff6316dbe1..11a2e10355d209d230d91c66fc519d26a77c8779 100644 (file)
@@ -58,8 +58,16 @@ Q_OBJECT
   //! Returns list of nested actions according to the given command ID
   virtual QStringList nestedActions(const QString& theId) const;
 
+  //! Set the document kind of the action by the given command Id
+  //! \param theId - the command ID
+  //! \param theKind - the document kind
+  virtual void setDocumentKind(const QString& theId, const QString& theKind);
+
+  //! Returns the document kind of the action by the given command ID
+  virtual QString documentKind(const QString& theId) const;
+
   //! Returns interface to Salome viewer
-  virtual XGUI_SalomeViewer* viewer() const
+  virtual ModuleBase_IViewer* viewer() const
   {
     return myProxyViewer;
   }
@@ -85,6 +93,7 @@ Q_OBJECT
 
  protected slots:
   virtual void onViewManagerAdded(SUIT_ViewManager* theMgr);
+  void onDefaultPreferences();
 
  protected:
   CAM_DataModel* createDataModel();
@@ -101,8 +110,11 @@ Q_OBJECT
   NewGeom_SalomeViewer* myProxyViewer;
 
   QMap<QString, QStringList> myNestedActions;
+  QMap<QString, QString> myDocumentType;
 
   bool myIsOpened;
+  bool myIsStorePositions;
+
 };
 
 #endif
index 4d4a74ec9a2bc0a4bddedc99e68cb717a014370d..d9ce85febf901d738fa94427301ce74ddd4c10ca 100644 (file)
@@ -11,7 +11,7 @@
 #include <QContextMenuEvent>
 
 NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent)
-    : XGUI_SalomeViewer(theParent),
+    : ModuleBase_IViewer(theParent),
       mySelector(0)
 {
 }
@@ -51,6 +51,8 @@ void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
     }
   }
   mySelector = theSel;
+  if (!mySelector)
+    return;
   OCCViewer_Viewer* aViewer = mySelector->viewer();
   SUIT_ViewManager* aMgr = aViewer->getViewManager();
 
@@ -150,3 +152,18 @@ void NewGeom_SalomeViewer::fitAll()
     aVFrame->onFitAll();
   }
 }
+
+//**********************************************
+void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ)
+{
+  SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
+  OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
+  if (aVFrame) {
+    Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
+    if (!aView3d.IsNull()) {
+      aView3d->SetProj(theX, theY, theZ);
+      aView3d->FitAll(0.01, true, true);
+      aView3d->SetZSize(0.);
+    }
+  }
+}
\ No newline at end of file
index 7f638ac86cd3a6eb79d4924336525dda83bb7ad0..29bdd5218be92523f8d6de153d056fbfbded17f1 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "NewGeom.h"
 
-#include <XGUI_SalomeViewer.h>
+#include <ModuleBase_IViewer.h>
 
 class SUIT_ViewWindow;
 class QMouseEvent;
@@ -12,7 +12,7 @@ class QKeyEvent;
 
 class NewGeom_OCCSelector;
 
-class NewGeom_SalomeViewer : public XGUI_SalomeViewer
+class NewGeom_SalomeViewer : public ModuleBase_IViewer
 {
 Q_OBJECT
  public:
@@ -42,6 +42,12 @@ Q_OBJECT
   //! Perfroms the fit all for the active view
   virtual void fitAll();
 
+  //! Sets the view projection
+  /// \param theX the X projection value
+  /// \param theY the Y projection value
+  /// \param theZ the Z projection value
+  virtual void setViewProjection(double theX, double theY, double theZ);
+
   void setSelector(NewGeom_OCCSelector* theSel);
 
   NewGeom_OCCSelector* selector() const
index db530bde71af993674e9c8ff23767701905132f2..20536e2a69ab65127248129aacbc4885b5681fda 100644 (file)
 
 -->
 <document>
+  <section name="launch">
+    <!-- SALOME launching parameters -->
+    <parameter name="modules"    value="GEOM,SMESH,HEXABLOCK,MED,YACS,PARAVIS,NewGeom"/>
+  </section>
   <section name="NewGeom">
     <!-- Major module parameters -->
     <parameter name="name" value="NewGeom"/>
index 1ce2ab944f748f710a1747c6c72673796dcdd296..de011a1b944183dfcef70933a90d699c903aa0f3 100644 (file)
@@ -14,7 +14,6 @@ SET(PROJECT_HEADERS
        PartSet_OperationSketchBase.h
        PartSet_OperationSketch.h
        PartSet_OperationFeatureBase.h
-       PartSet_TestOCC.h
        PartSet_Tools.h
        PartSet_WidgetSketchLabel.h
        PartSet_Validators.h
@@ -30,7 +29,6 @@ SET(PROJECT_SOURCES
        PartSet_OperationSketchBase.cpp
        PartSet_OperationSketch.cpp
        PartSet_OperationFeatureBase.cpp
-       PartSet_TestOCC.cpp
        PartSet_Tools.cpp
        PartSet_WidgetSketchLabel.cpp
        PartSet_Validators.cpp
index f66ac66b4d4c9b85bf70c37870dbe73d5b2ecc92..24c78b60faf03b8beb774960c21bfedaa1be99d0 100644 (file)
@@ -7,6 +7,7 @@
 #include <PartSet_Module.h>
 #include <PartSet_OperationSketchBase.h>
 #include <PartSet_OperationSketch.h>
+#include <PartSet_OperationFeatureCreate.h>
 
 #include <XGUI_Displayer.h>
 #include <XGUI_Workshop.h>
@@ -16,6 +17,7 @@
 
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
+#include <ModelAPI_Feature.h>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -39,12 +41,12 @@ PartSet_Listener::~PartSet_Listener()
 //******************************************************
 void PartSet_Listener::processEvent(const boost::shared_ptr<Events_Message>& theMessage)
 {
-  ModuleBase_Operation* anOperation = myModule->workshop()->operationMgr()->currentOperation();
+  ModuleBase_Operation* anOperation = myModule->xWorkshop()->operationMgr()->currentOperation();
   PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (!aSketchOp)
     return;
 
-  XGUI_Displayer* aDisplayer = myModule->workshop()->displayer();
+  XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer();
   QString aType = QString(theMessage->eventID().eventText());
   if (aType == EVENT_OBJECT_CREATED) {
     boost::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
@@ -52,27 +54,41 @@ void PartSet_Listener::processEvent(const boost::shared_ptr<Events_Message>& the
     std::set<ObjectPtr> aFeatures = aUpdMsg->objects();
 
     PartSet_OperationSketch* aSketchOp = 
-      dynamic_cast<PartSet_OperationSketch*>(myModule->workshop()->operationMgr()->currentOperation());
+      dynamic_cast<PartSet_OperationSketch*>(myModule->xWorkshop()->operationMgr()->currentOperation());
 
     std::set<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
     for (; anIt != aLast; anIt++) {
       ObjectPtr aObj = (*anIt);
-      aDisplayer->deactivate(aObj);
-      boost::shared_ptr<ModelAPI_Feature> aFeature = 
-        boost::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
-      if (aFeature && (aFeature->getKind() == "Sketch")) // Activate sketcher for planes selection
-        myModule->activateFeature(aFeature, false);
       // If current operation is Sketch then there is no active sketching operation
-      // and possible the object was created by Redo operatgion
-      else if (aSketchOp) {
-          XGUI_Displayer* aDisplayer = myModule->workshop()->displayer();
+      // and possible the object was created by Redo operation
+      if (aSketchOp) {
+          XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer();
           // Very possible it is not displayed
           aDisplayer->display(aObj, false);
-          std::list<int> aModes = aSketchOp->getSelectionModes(aObj);
-          aDisplayer->activateInLocalContext(aObj, aModes, false);
       }
     }
+  } else if (aType == EVENT_OBJECT_TO_REDISPLAY) {
+    PartSet_OperationFeatureCreate* aCreationOp = 
+      dynamic_cast<PartSet_OperationFeatureCreate*>
+      (myModule->xWorkshop()->operationMgr()->currentOperation());
+    if (aCreationOp) {
+      // Deactivate currently creating objects for selection
+      XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer();
+      FeaturePtr aFeature = aCreationOp->feature();
+      const std::list<ResultPtr>& aResults = aFeature->results();
+      boost::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
+          boost::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
 
+      std::set<ObjectPtr> aFeatures = aUpdMsg->objects();
+      std::set<ObjectPtr>::const_iterator aObjIt, aNoObj = aFeatures.cend();
+      std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
+      for (; anIt != aLast; anIt++) {
+        aObjIt = aFeatures.find(*anIt);
+        if (aObjIt != aNoObj) {
+          aDisplayer->deactivate(*aObjIt);
+        }
+      }
+    }
   } else if (aType == EVENT_OBJECT_DELETED) {
     boost::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
         boost::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
@@ -83,7 +99,7 @@ void PartSet_Listener::processEvent(const boost::shared_ptr<Events_Message>& the
     for (; anIt != aLast; anIt++) {
       std::string aGroup = *anIt;
       if (aGroup.compare(SketchPlugin_Sketch::ID()) == 0) {  // Update only Sketch group
-        myModule->workshop()->displayer()->eraseDeletedResults();
+        myModule->xWorkshop()->displayer()->eraseDeletedResults();
         myModule->updateCurrentPreview(aGroup);
       }
     }
index b2387c238bdcc42db0e62fee2e657e99ef6fd42b..f38381ef85160fcedbbb5b29dd2744766a84d947 100644 (file)
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Data.h>
+#include <ModelAPI_Session.h>
 
 #include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
 
 #include <XGUI_MainWindow.h>
 #include <XGUI_Displayer.h>
 #include <XGUI_Viewer.h>
 #include <XGUI_Workshop.h>
 #include <XGUI_OperationMgr.h>
-#include <XGUI_SelectionMgr.h>
-#include <XGUI_Selection.h>
 #include <XGUI_ViewPort.h>
 #include <XGUI_ActionsMgr.h>
 #include <XGUI_ViewerProxy.h>
 #include <XGUI_Tools.h>
 
 #include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
 
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
 #include <Config_WidgetReader.h>
 #include <Events_Loop.h>
-#include <Events_Message.h>
-#include <Events_Error.h>
+//#include <Events_Message.h>
+//#include <Events_Error.h>
 
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_AISObject.h>
 #include <AIS_Shape.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
 
-#include <StdSelect_FaceFilter.hxx>
 #include <StdSelect_TypeOfFace.hxx>
 
 #include <QObject>
 #endif
 
 /*!Create and return new instance of XGUI_Module*/
-extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(XGUI_Workshop* theWshop)
+extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
 {
   return new PartSet_Module(theWshop);
 }
 
-PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
+PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
+  : ModuleBase_IModule(theWshop)
 {
-  myWorkshop = theWshop;
+  //myWorkshop = theWshop;
   myListener = new PartSet_Listener(this);
 
-  XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
-
-  connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
+  connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)), 
+    this, SLOT(onOperationStarted(ModuleBase_Operation*)));
 
-  connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this,
+  connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)), this,
           SLOT(onOperationStopped(ModuleBase_Operation*)));
 
-  XGUI_ContextMenuMgr* aContextMenuMgr = myWorkshop->contextMenuMgr();
+  XGUI_Workshop* aXWshop = xWorkshop();
+  XGUI_ContextMenuMgr* aContextMenuMgr = aXWshop->contextMenuMgr();
   connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
           SLOT(onContextMenuCommand(const QString&, bool)));
 
-  connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
-          SLOT(onMousePressed(QMouseEvent*)));
-  connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
-          SLOT(onMouseReleased(QMouseEvent*)));
-  connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
-          SLOT(onMouseMoved(QMouseEvent*)));
-  connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
-          SLOT(onKeyRelease(QKeyEvent*)));
-  connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
-          SLOT(onMouseDoubleClick(QMouseEvent*)));
 }
 
 PartSet_Module::~PartSet_Module()
 {
 }
 
-XGUI_Workshop* PartSet_Module::workshop() const
-{
-  return myWorkshop;
-}
-
 void PartSet_Module::createFeatures()
 {
   //Registering of validators
@@ -137,11 +125,6 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId)
  */
 void PartSet_Module::onFeatureTriggered()
 {
-  //PartSet_TestOCC::local_selection_change_shape(myWorkshop->viewer()->AISContext(),
-  //                                   myWorkshop->viewer()->activeView());
-
-  //PartSet_TestOCC::local_selection_erase(myWorkshop->viewer()->AISContext(),
-  //                                       myWorkshop->viewer()->activeView());
   QAction* aCmd = dynamic_cast<QAction*>(sender());
   //Do nothing on uncheck
   if (aCmd->isCheckable() && !aCmd->isChecked())
@@ -149,31 +132,31 @@ void PartSet_Module::onFeatureTriggered()
   launchOperation(aCmd->data().toString());
 }
 
-void PartSet_Module::launchOperation(const QString& theCmdId)
-{
-  ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-  if (aPreviewOp) {
-    XGUI_Selection* aSelection = myWorkshop->selector()->selection();
-    // Initialise operation with preliminary selection
-    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-    aPreviewOp->initSelection(aSelected, aHighlighted);
-  }
-  sendOperation(anOperation);
-}
 
-void PartSet_Module::onOperationStarted()
+void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
 {
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
-      ->operationMgr()->currentOperation());
+  XGUI_Workshop* aXWshp = xWorkshop();
+  XGUI_Displayer* aDisplayer = aXWshp->displayer();
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
   if (aPreviewOp) {
-    XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
+    XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
     connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
             SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection);
-    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-    aDisplayer->openLocalContext();
-    aDisplayer->deactivateObjectsOutOfContext();
+
+    //aDisplayer->deactivateObjectsOutOfContext();
+    PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+    if (aSketchOp) {
+      if (aSketchOp->isEditOperation()) {
+        setSketchingMode(getSketchPlane(aSketchOp->feature()));
+      } else {
+        aDisplayer->openLocalContext();
+        aDisplayer->activateObjectsOutOfContext(QIntList());
+        myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane);
+        aDisplayer->addSelectionFilter(myPlaneFilter);
+        QIntList aModes = sketchSelectionModes(aPreviewOp->feature());
+        aDisplayer->setSelectionModes(aModes);
+      } 
+    }
   }
 }
 
@@ -181,26 +164,45 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
 {
   if (!theOperation)
     return;
+  XGUI_Workshop* aXWshp = xWorkshop();
+  XGUI_Displayer* aDisplayer = aXWshp->displayer();
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
   if (aPreviewOp) {
-    XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
-    //disconnect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)),
-    //           this, SLOT(onStorePoint2D(ObjectPtr, const std::string&)));
-  } else {
-    // Activate results of current feature for selection
-    FeaturePtr aFeature = theOperation->feature();
-    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-    std::list<ResultPtr> aResults = aFeature->results();
-    std::list<ResultPtr>::const_iterator aIt;
-    for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
-      aDisplayer->activate(*aIt);
+    XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
+
+    PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+    if (aSketchOp) {
+      aDisplayer->closeLocalContexts();
+    } else {
+      PartSet_OperationFeatureCreate* aCreationOp = 
+        dynamic_cast<PartSet_OperationFeatureCreate*>(aPreviewOp);
+      if (aCreationOp) {
+        // Activate just created object for selection
+        FeaturePtr aFeature = aCreationOp->feature();
+        QIntList aModes = sketchSelectionModes(aFeature);
+        const std::list<ResultPtr>& aResults = aFeature->results();
+        std::list<ResultPtr>::const_iterator anIt, aLast = aResults.end();
+        for (anIt = aResults.begin(); anIt != aLast; anIt++) {
+          aDisplayer->activate(*anIt, aModes);
+        }
+        aDisplayer->activate(aFeature, aModes);
+      }
     }
-  }
+  }// else {
+    // Activate results of current feature for selection
+    //FeaturePtr aFeature = theOperation->feature();
+    //XGUI_Displayer* aDisplayer = aXWshp->displayer();
+    //std::list<ResultPtr> aResults = aFeature->results();
+    //std::list<ResultPtr>::const_iterator aIt;
+    //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+    //  aDisplayer->activate(*aIt);
+    //}    
+  //}
 }
 
 void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
 {
-  QList<ObjectPtr> aFeatures = myWorkshop->selector()->selection()->selectedObjects();
+  QList<ObjectPtr> aFeatures = workshop()->selection()->selectedObjects();
   if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
     FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
     if (aFeature)
@@ -210,46 +212,55 @@ void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
 
 void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
 {
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
-      ->operationMgr()->currentOperation());
-  Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
-  if (aPreviewOp && (!aView.IsNull())) {
-    XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+  XGUI_Workshop* aXWshp = xWorkshop();
+  PartSet_OperationSketchBase* aPreviewOp = 
+    dynamic_cast<PartSet_OperationSketchBase*>(workshop()->currentOperation());
+  if (aPreviewOp) {
+    ModuleBase_ISelection* aSelection = workshop()->selection();
     // Initialise operation with preliminary selection
-    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-
-    aPreviewOp->mousePressed(theEvent, aView, aSelected, aHighlighted);
+    //QList<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
+    //QList<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
+    //QList<ObjectPtr> aObjList;
+    //bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
+    //if (aHasShift) {
+    //  foreach(ModuleBase_ViewerPrs aPrs, aSelected)
+    //    aObjList.append(aPrs.object());
+
+    //  foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) {
+    //    if (!aObjList.contains(aPrs.object()))
+    //      aObjList.append(aPrs.object());
+    //  }
+    //} else {
+    //  foreach(ModuleBase_ViewerPrs aPrs, aHighlighted)
+    //    aObjList.append(aPrs.object());
+    //}
+    //onSetSelection(aObjList);
+    aPreviewOp->mousePressed(theEvent, myWorkshop->viewer(), aSelection);
   }
 }
 
 void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
 {
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
-      ->operationMgr()->currentOperation());
-  Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
-  if (aPreviewOp && (!aView.IsNull())) {
-    XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+  PartSet_OperationSketchBase* aPreviewOp = 
+    dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
+  if (aPreviewOp) {
+    ModuleBase_ISelection* aSelection = workshop()->selection();
     // Initialise operation with preliminary selection
-    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-
-    aPreviewOp->mouseReleased(theEvent, aView, aSelected, aHighlighted);
+    aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer(), aSelection);
   }
 }
 
 void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
 {
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
-      ->operationMgr()->currentOperation());
-  Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
-  if (aPreviewOp && (!aView.IsNull()))
-    aPreviewOp->mouseMoved(theEvent, aView);
+  PartSet_OperationSketchBase* aPreviewOp = 
+    dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
+  if (aPreviewOp)
+    aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer());
 }
 
 void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
 {
-  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+  ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp) {
     aPreviewOp->keyReleased(theEvent->key());
@@ -258,25 +269,24 @@ void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
 
 void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
 {
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
-      ->operationMgr()->currentOperation());
+  PartSet_OperationSketchBase* aPreviewOp = 
+    dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
   Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
   if (aPreviewOp && (!aView.IsNull())) {
-    XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+    ModuleBase_ISelection* aSelection = workshop()->selection();
     // Initialise operation with preliminary selection
-    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-    aPreviewOp->mouseDoubleClick(theEvent, aView, aSelected, aHighlighted);
+    aPreviewOp->mouseDoubleClick(theEvent, aView, aSelection);
   }
 }
 
 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
 {
-  //erasePlanes();
   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
-  myWorkshop->actionsMgr()->update();
-
-  //PartSet_TestOCC::testSelection(myWorkshop);
+  xWorkshop()->actionsMgr()->update();
+  // Set working plane
+  ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+  FeaturePtr aSketch = anOperation->feature();
+  setSketchingMode(getSketchPlane(aSketch));
 }
 
 void PartSet_Module::onFitAllView()
@@ -290,46 +300,49 @@ void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject
 
   std::string aKind = aFeature ? aFeature->getKind() : "";
   ModuleBase_Operation* anOperation = createOperation(theName, aKind);
+
   PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aSketchOp) {
-    XGUI_Selection* aSelection = myWorkshop->selector()->selection();
-    // Initialise operation with preliminary selection
-    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-    aSketchOp->initFeature(aFeature);
-    aSketchOp->initSelection(aSelected, aHighlighted);
-  } else if (aFeature) {
-    anOperation->setEditingFeature(aFeature);
-    //Deactivate result of current feature in order to avoid its selection
-    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-    std::list<ResultPtr> aResults = aFeature->results();
-    std::list<ResultPtr>::const_iterator aIt;
-    for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
-      aDisplayer->deactivate(*aIt);
+    PartSet_OperationFeatureCreate* aCreateOp = dynamic_cast<PartSet_OperationFeatureCreate*>(anOperation);
+    if (aCreateOp)
+      aCreateOp->initFeature(aFeature);
+    else {
+      anOperation->setFeature(aFeature);
     }
-  }
+    ModuleBase_ISelection* aSelection = workshop()->selection();
+    // Initialise operation with preliminary selection
+    aSketchOp->initSelection(aSelection);
+  } //else if (aFeature) {
+    //anOperation->setFeature(aFeature);
+    ////Deactivate result of current feature in order to avoid its selection
+    //XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
+    //std::list<ResultPtr> aResults = aFeature->results();
+    //std::list<ResultPtr>::const_iterator aIt;
+    //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+    //  aDisplayer->deactivate(*aIt);
+    //}
+  //}
   sendOperation(anOperation);
-  myWorkshop->actionsMgr()->updateCheckState();
+  xWorkshop()->actionsMgr()->updateCheckState();
 }
 
 void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
 {
-  XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
+  ModuleBase_IViewer* aViewer = myWorkshop->viewer();
   aViewer->enableMultiselection(theEnabled);
 }
 
 void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
 {
-  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-  if (!isStop) {
-    foreach(ObjectPtr aObject, theFeatures)
-    {
-      activateFeature(aObject, false);
-    }
-  }
+  XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
+  //if (!isStop) {
+  //  foreach(ObjectPtr aObject, theFeatures) {
+  //    activateFeature(aObject);
+  //  }
+  //}
   aDisplayer->stopSelection(theFeatures, isStop, false);
 
-  XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
+  ModuleBase_IViewer* aViewer = myWorkshop->viewer();
   aViewer->enableSelection(!isStop);
 
   aDisplayer->updateViewer();
@@ -337,41 +350,53 @@ void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const
 
 void PartSet_Module::onSetSelection(const QList<ObjectPtr>& theFeatures)
 {
-  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
   aDisplayer->setSelected(theFeatures, false);
   aDisplayer->updateViewer();
 }
 
-void PartSet_Module::onCloseLocalContext()
+void PartSet_Module::setSketchingMode(const gp_Pln& thePln)
 {
-  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-  aDisplayer->deactivateObjectsOutOfContext();
-  aDisplayer->closeLocalContexts();
+  XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
+  if (!myPlaneFilter.IsNull()) {
+    aDisplayer->removeSelectionFilter(myPlaneFilter);
+    myPlaneFilter.Nullify();
+  }
+  QIntList aModes;
+  // Clear standard selection modes
+  aDisplayer->setSelectionModes(aModes);
+  aDisplayer->openLocalContext();
+
+  // Set filter
+  mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln);
+  aDisplayer->addSelectionFilter(mySketchFilter);
+
+  // Get default selection modes
+  aModes = sketchSelectionModes(ObjectPtr());
+  aDisplayer->activateObjectsOutOfContext(aModes);
 }
 
 void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
 {
   bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
-  ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
+  ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
   PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
   if (aPrevOp) {
     std::list<FeaturePtr> aList = aPrevOp->subFeatures();
-    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-    std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
+    XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
+    QIntList aModes = sketchSelectionModes(aPrevOp->feature());
     std::list<FeaturePtr>::iterator aSFIt;
     for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
       std::list<ResultPtr> aResults = (*aSFIt)->results();
       std::list<ResultPtr>::iterator aIt;
       for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
-        if (isDisplay)
-          aDisplayer->activateInLocalContext((*aIt), aModes, false);
-        else
+        if (!isDisplay)
           aDisplayer->erase((*aIt), false);
       }
       if (!isDisplay)
         aDisplayer->erase((*aSFIt), false);
     }
-    aDisplayer->deactivateObjectsOutOfContext();
+    //aDisplayer->deactivateObjectsOutOfContext();
   }
   if (isDisplay)
     ModelAPI_EventCreator::get()->sendUpdated(
@@ -386,8 +411,8 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   if (theCmdId == PartSet_OperationSketch::Type()) {
     anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
   } else {
-    ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
-    FeaturePtr aSketch;
+    ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
+    CompositeFeaturePtr aSketch;
     PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
     if (aPrevOp) {
       aSketch = aPrevOp->sketch();
@@ -414,18 +439,9 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
   std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
 
-  //QString aXmlRepr = QString::fromStdString(aXmlCfg);
-  //ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
-  //                                                             myWorkshop->moduleConnector());
-  //QWidget* aContent = myWorkshop->propertyPanel()->contentWidget();
-  //qDeleteAll(aContent->children());
-  //aFactory.createWidget(aContent);
-
   anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
   anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
 
-  //anOperation->setModelWidgets(aXmlRepr.toStdString(), aFactory.getModelWidgets());
-
   // connect the operation
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp) {
@@ -433,16 +449,16 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
             SLOT(onFeatureConstructed(ObjectPtr, int)));
     connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this,
             SLOT(onRestartOperation(std::string, ObjectPtr)));
-    connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
-            SLOT(onMultiSelectionEnabled(bool)));
+    // If manage multi selection the it will be impossible to select more then one
+    // object under operation Edit
+//    connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
+//            SLOT(onMultiSelectionEnabled(bool)));
 
     connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)), this,
             SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
     connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)), this,
             SLOT(onSetSelection(const QList<ObjectPtr>&)));
 
-    connect(aPreviewOp, SIGNAL(closeLocalContext()), this, SLOT(onCloseLocalContext()));
-
     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
     if (aSketchOp) {
       connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
@@ -454,38 +470,10 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   return anOperation;
 }
 
-void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
-{
-  static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
-  boost::shared_ptr<Config_PointerMessage> aMessage =
-      boost::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
-  aMessage->setPointer(theOperation);
-  Events_Loop::loop()->send(aMessage);
-}
-
-void PartSet_Module::activateFeature(ObjectPtr theFeature, const bool isUpdateViewer)
-{
-  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-  if (aPreviewOp) {
-    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-    std::list<int> aModes = aPreviewOp->getSelectionModes(theFeature);
-    aDisplayer->activateInLocalContext(theFeature, aModes, isUpdateViewer);
-
-    // If this is a Sketcher then activate objects (planar faces) outside of context
-    PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
-    if (aSketchOp) {
-      Handle(StdSelect_FaceFilter) aFilter = new StdSelect_FaceFilter(StdSelect_Plane);
-      aDisplayer->activateObjectsOutOfContext(aModes, aFilter);
-    } else {
-      aDisplayer->deactivateObjectsOutOfContext();
-    }
-  }
-}
 
 void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
 {
-  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+  ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
   if (!anOperation)
     return;
 
@@ -497,7 +485,7 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
   if (!aFeature || aFeature->getKind() != theCmdId)
     return;
 
-  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
   // Hide result of sketch
   std::list<ResultPtr> aResults = aFeature->results();
   std::list<ResultPtr>::const_iterator aIt;
@@ -505,7 +493,6 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
     aDisplayer->erase(*aIt, false);
 
   std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
-  std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
 
   std::list<FeaturePtr>::const_iterator anIt = aList.begin(), aLast = aList.end();
   for (; anIt != aLast; anIt++) {
@@ -517,10 +504,10 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
     std::list<ResultPtr>::const_iterator aRIt;
     for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) {
       aDisplayer->display((*aRIt), false);
-      aDisplayer->activateInLocalContext((*aRIt), aModes, false);
+      aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt)));
     }
     aDisplayer->display(aSPFeature, false);
-    aDisplayer->activateInLocalContext(aSPFeature, aModes, false);
+    aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature));
   }
   aDisplayer->updateViewer();
 }
@@ -548,8 +535,8 @@ void PartSet_Module::onStorePoint2D(ObjectPtr theFeature, const std::string& the
 {
   FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
 
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
-      ->operationMgr()->currentOperation());
+  PartSet_OperationSketchBase* aPreviewOp = 
+    dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
   if (!aPreviewOp)
     return;
 
@@ -566,9 +553,73 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
 {
   if (theType == "sketch-start-label") {
     PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, "");
-    aWgt->setOperationsMgr(myWorkshop->operationMgr());
+    aWgt->setOperationsMgr(xWorkshop()->operationMgr());
     theModelWidgets.append(aWgt);
     return aWgt->getControl();
   } else
     return 0;
 }
+
+
+XGUI_Workshop* PartSet_Module::xWorkshop() const
+{
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
+  if (aConnector) {
+    return aConnector->workshop();
+  }
+  return 0;
+}
+
+
+QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature)
+{
+  QIntList aModes;
+  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
+  if (aFeature) {
+    if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
+      aModes.append(TopAbs_FACE);
+      return aModes;
+    } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
+      aModes.append(AIS_DSM_Text);
+      aModes.append(AIS_DSM_Line);
+      return aModes;
+    }
+  } 
+  aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
+  aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
+  return aModes;
+}
+
+
+gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const
+{
+  DataPtr aData = theSketch->data();
+  boost::shared_ptr<GeomDataAPI_Point> anOrigin = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
+      aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+  boost::shared_ptr<GeomDataAPI_Dir> aNorm = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+  gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z());
+  gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z());
+  return gp_Pln(aOrig, aDir);
+}
+
+
+void PartSet_Module::onSelectionChanged()
+{
+  ModuleBase_ISelection* aSelect = myWorkshop->selection();
+  QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
+  // We need to stop edit operation if selection is cleared
+  if (aSelected.size() == 0) {
+    PartSet_OperationFeatureEdit* anEditOp = 
+      dynamic_cast<PartSet_OperationFeatureEdit*>(myWorkshop->currentOperation());
+    if (!anEditOp)
+      return;
+    anEditOp->commit();
+  } else {
+    PartSet_OperationSketchBase* aSketchOp = 
+      dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
+    if (aSketchOp) {
+      aSketchOp->selectionChanged(aSelect);
+    }
+  }
+}
index 803015f38786d38701b1e26281598b8d4c960464..f5851100ce749aa309c4dd6dc8367c7d74f60aee 100644 (file)
@@ -5,8 +5,10 @@
 
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_Definitions.h>
+#include <ModuleBase_ViewerFilters.h>
 #include <XGUI_Command.h>
 #include <ModelAPI_Feature.h>
+#include <StdSelect_FaceFilter.hxx>
 
 #include <QMap>
 #include <QObject>
 
 #include <boost/shared_ptr.hpp>
 
-class QMouseEvent;
-class QKeyEvent;
 class PartSet_Listener;
 class ModelAPI_Feature;
 class XGUI_ViewerPrs;
+class XGUI_Workshop;
 class ModuleBase_Operation;
 class GeomAPI_AISObject;
 
@@ -28,13 +29,9 @@ class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule
 Q_OBJECT
 
  public:
-  PartSet_Module(XGUI_Workshop* theWshop);
+  PartSet_Module(ModuleBase_IWorkshop* theWshop);
   virtual ~PartSet_Module();
 
-  /// Returns the module workshop
-  /// \returns a workshop instance
-  XGUI_Workshop* workshop() const;
-
   /// Reads description of features from XML file 
   virtual void createFeatures();
 
@@ -45,22 +42,7 @@ Q_OBJECT
 
   /// Creates an operation and send it to loop
   /// \param theCmdId the operation name
-  virtual void launchOperation(const QString& theCmdId);
-
-  /// Called when it is necessary to update a command state (enable or disable it)
-  //virtual bool isFeatureEnabled(const QString& theCmdId) const;
-
-  /// Displays or erase the current operation preview, if it has it.
-  /// \param theFeature the feature instance to be displayed
-  /// \param isDisplay the state whether the presentation should be displayed or erased
-  /// \param isUpdateViewer the flag whether the viewer should be updated
-  //void visualizePreview(FeaturePtr theFeature, bool isDisplay,
-  //                      const bool isUpdateViewer = true);
-
-  /// Activates the feature in the displayer
-  /// \param theFeature the feature instance to be displayed
-  /// \param isUpdateViewer the flag whether the viewer should be updated
-  void activateFeature(ObjectPtr theFeature, const bool isUpdateViewer);
+  //virtual void launchOperation(const QString& theCmdId);
 
   /// Updates current operation preview, if it has it.
   /// \param theCmdId the operation name
@@ -71,35 +53,21 @@ Q_OBJECT
                                       Config_WidgetAPI* theWidgetApi,
                                       QList<ModuleBase_ModelWidget*>& theModelWidgets);
 
+  XGUI_Workshop* xWorkshop() const;
+
+
+  /// Returns list of selection modes for the given object for sketch operation
+  static QIntList sketchSelectionModes(ObjectPtr theFeature);
+
  public slots:
   void onFeatureTriggered();
   /// SLOT, that is called after the operation is started. Connect on the focus activated signal
-  void onOperationStarted();
+  void onOperationStarted(ModuleBase_Operation* theOperation);
   /// SLOT, that is called after the operation is stopped. Switched off the modfications performed
   /// by the operation start
   void onOperationStopped(ModuleBase_Operation* theOperation);
   /// SLOT, that is called afetr the popup menu action clicked.
   void onContextMenuCommand(const QString& theId, bool isChecked);
-  /// SLOT, that is called by mouse press in the viewer.
-  /// The mouse released point is sent to the current operation to be processed.
-  /// \param theEvent the mouse event
-  void onMousePressed(QMouseEvent* theEvent);
-  /// SLOT, that is called by mouse release in the viewer.
-  /// The mouse released point is sent to the current operation to be processed.
-  /// \param theEvent the mouse event
-  void onMouseReleased(QMouseEvent* theEvent);
-  /// SLOT, that is called by mouse move in the viewer.
-  /// The mouse moved point is sent to the current operation to be processed.
-  /// \param theEvent the mouse event
-  void onMouseMoved(QMouseEvent* theEvent);
-
-  /// SLOT, that is called by the key in the viewer is clicked.
-  /// \param theEvent the mouse event
-  void onKeyRelease(QKeyEvent* theEvent);
-
-  /// SLOT, that is called by the mouse double click in the viewer.
-  /// \param theEvent the mouse event
-  void onMouseDoubleClick(QMouseEvent* theEvent);
 
   /// SLOT, to apply to the current viewer the operation
   /// \param theX the X projection value
@@ -125,8 +93,9 @@ Q_OBJECT
   /// \param theFeatures a list of features to be selected
   void onSetSelection(const QList<ObjectPtr>& theFeatures);
 
-  /// SLOT, to close the viewer local context
-  void onCloseLocalContext();
+  /// SLOT, Defines Sketch editing mode
+  /// \param thePln - plane of current sketch
+  void setSketchingMode(const gp_Pln& thePln);
 
   /// SLOT, to visualize the feature in another local context mode
   /// \param theFeature the feature to be put in another local context mode
@@ -138,6 +107,33 @@ Q_OBJECT
   /// \param the attribute of the feature
   void onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute);
 
+protected slots:
+  /// Called on selection changed event
+  virtual void onSelectionChanged();
+
+  /// SLOT, that is called by mouse press in the viewer.
+  /// The mouse released point is sent to the current operation to be processed.
+  /// \param theEvent the mouse event
+  virtual void onMousePressed(QMouseEvent* theEvent);
+
+  /// SLOT, that is called by mouse release in the viewer.
+  /// The mouse released point is sent to the current operation to be processed.
+  /// \param theEvent the mouse event
+  virtual void onMouseReleased(QMouseEvent* theEvent);
+  
+  /// SLOT, that is called by mouse move in the viewer.
+  /// The mouse moved point is sent to the current operation to be processed.
+  /// \param theEvent the mouse event
+  virtual void onMouseMoved(QMouseEvent* theEvent);
+
+  /// SLOT, that is called by the mouse double click in the viewer.
+  /// \param theEvent the mouse event
+  virtual void onMouseDoubleClick(QMouseEvent* theEvent);
+
+  /// SLOT, that is called by the key in the viewer is clicked.
+  /// \param theEvent the mouse event
+  virtual void onKeyRelease(QKeyEvent* theEvent);
+
  protected:
   /// Creates a new operation
   /// \param theCmdId the operation name
@@ -145,19 +141,21 @@ Q_OBJECT
   ModuleBase_Operation* createOperation(const std::string& theCmdId,
                                         const std::string& theFeatureKind = "");
 
-  /// Sends the operation
-  /// \param theOperation the operation
-  void sendOperation(ModuleBase_Operation* theOperation);
 
  protected:
   //! Edits the feature
   void editFeature(FeaturePtr theFeature);
 
+  gp_Pln getSketchPlane(FeaturePtr theSketch) const;
+
  private:
-  XGUI_Workshop* myWorkshop;
+  //XGUI_Workshop* myWorkshop;
   PartSet_Listener* myListener;
 
   std::map<std::string, std::string> myFeaturesInFiles;
+
+  Handle(StdSelect_FaceFilter) myPlaneFilter;
+  Handle(ModuleBase_ShapeInPlaneFilter) mySketchFilter;
 };
 
 #endif
index c1da278fa020868570d496073c97f06c748d4924..458410aba5f87f446abc99c8d228e1a6a1b5f9bd 100644 (file)
@@ -24,7 +24,9 @@
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_WidgetPoint2D.h>
 #include <ModuleBase_WidgetValueFeature.h>
-#include <ModuleBase_ViewerPrs.h>
+#include "ModuleBase_IPropertyPanel.h"
+#include "ModuleBase_ISelection.h"
+#include "ModuleBase_IViewer.h"
 
 #include <XGUI_Constants.h>
 
@@ -44,10 +46,9 @@ using namespace std;
 
 PartSet_OperationFeatureBase::PartSet_OperationFeatureBase(const QString& theId,
                                                                QObject* theParent,
-                                                               FeaturePtr theFeature)
+                                                               CompositeFeaturePtr theFeature)
     : PartSet_OperationSketchBase(theId, theParent),
-      mySketch(theFeature),
-      myActiveWidget(NULL)
+      mySketch(theFeature)
 {
 }
 
@@ -55,51 +56,41 @@ PartSet_OperationFeatureBase::~PartSet_OperationFeatureBase()
 {
 }
 
-void PartSet_OperationFeatureBase::initSelection(
-    const std::list<ModuleBase_ViewerPrs>& theSelected,
-    const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
-{
-  myPreSelection = theSelected;
-}
-
-void PartSet_OperationFeatureBase::initFeature(FeaturePtr theFeature)
-{
-  myInitFeature = theFeature;
-}
-
-FeaturePtr PartSet_OperationFeatureBase::sketch() const
+CompositeFeaturePtr PartSet_OperationFeatureBase::sketch() const
 {
   return mySketch;
 }
 
-void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                                 const std::list<ModuleBase_ViewerPrs>& theSelected,
-                                                 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
+void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+                                                 ModuleBase_ISelection* theSelection)
 {
-  gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+  Handle(V3d_View) aView = theViewer->activeView();
+  gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
   double aX = aPoint.X(), anY = aPoint.Y();
+  QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
 
-  if (theSelected.empty()) {
-    PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+  if (aSelected.empty()) {
+    PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
   } else {
-    ModuleBase_ViewerPrs aPrs = theSelected.front();
+    ModuleBase_ViewerPrs aPrs = aSelected.first();
     const TopoDS_Shape& aShape = aPrs.shape();
     if (!aShape.IsNull()) {
       if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
         const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
         if (!aVertex.IsNull()) {
           aPoint = BRep_Tool::Pnt(aVertex);
-          PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
-          PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(), aX, anY);
+          PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
+          ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+          PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
         }
       } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
-        PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+        PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
       }
     }
   }
   ObjectPtr aFeature;
-  if (!theSelected.empty()) {
-    ModuleBase_ViewerPrs aPrs = theSelected.front();
+  if (!aSelected.empty()) {
+    ModuleBase_ViewerPrs aPrs = aSelected.first();
     aFeature = aPrs.object();
   } else {
     aFeature = feature();  // for the widget distance only
@@ -108,53 +99,22 @@ void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, Handle(V
   bool isApplyed = setWidgetValue(aFeature, aX, anY);
   if (isApplyed) {
     flushUpdated();
-    emit activateNextWidget(myActiveWidget);
+    myPropertyPanel->activateNextWidget();
   }
   commit();
 }
 
-void PartSet_OperationFeatureBase::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
-{
-  myActiveWidget = theWidget;
-  activateByPreselection();
-  if (myInitFeature && myActiveWidget) {
-    ModuleBase_WidgetPoint2D* aWgt = dynamic_cast<ModuleBase_WidgetPoint2D*>(myActiveWidget);
-    if (aWgt && aWgt->initFromPrevious(myInitFeature)) {
-      myInitFeature = FeaturePtr();
-      emit activateNextWidget(myActiveWidget);
-    }
-  }
-}
-
-void PartSet_OperationFeatureBase::activateByPreselection()
+/*bool PartSet_OperationFeatureBase::setWidgetValue(ObjectPtr theFeature, double theX, double theY)
 {
-  if ((myPreSelection.size() > 0) && myActiveWidget) {
-    const ModuleBase_ViewerPrs& aPrs = myPreSelection.front();
-    ModuleBase_WidgetValueFeature aValue;
-    aValue.setObject(aPrs.object());
-    if (myActiveWidget->setValue(&aValue)) {
-      myPreSelection.remove(aPrs);
-      if(isValid()) {
-        myActiveWidget = NULL;
-        commit();
-      } else {
-        emit activateNextWidget(myActiveWidget);
-      }
-    }
-    // If preselection is enough to make a valid feature - apply it immediately
-  }
-}
-
-bool PartSet_OperationFeatureBase::setWidgetValue(ObjectPtr theFeature, double theX, double theY)
-{
-  if (!myActiveWidget)
+  ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+  if (!aActiveWgt)
     return false;
   ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
   aValue->setObject(theFeature);
   aValue->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
-  bool isApplyed = myActiveWidget->setValue(aValue);
+  bool isApplyed = aActiveWgt->setValue(aValue);
 
   delete aValue;
   myIsModified = (myIsModified || isApplyed);
   return isApplyed;
-}
+}*/
index 5a0c66bf0fbcd6e22d0f3d47666c61c41c3c31f9..cde5fb6756674e736437cfc49e2bb817d5ccc6db 100644 (file)
@@ -29,55 +29,33 @@ Q_OBJECT
   /// \param theId the feature identifier
   /// \param theParent the operation parent
   /// \param theSketch the parent feature
-  PartSet_OperationFeatureBase(const QString& theId, QObject* theParent, FeaturePtr theSketch);
+  PartSet_OperationFeatureBase(const QString& theId, QObject* theParent, CompositeFeaturePtr theSketch);
   /// Destructor
   virtual ~PartSet_OperationFeatureBase();
 
-  /// Initialisation of operation with preliminary selection
-  /// \param theSelected the list of selected presentations
-  /// \param theHighlighted the list of highlighted presentations
-  virtual void initSelection(const std::list<ModuleBase_ViewerPrs>& theSelected,
-                             const std::list<ModuleBase_ViewerPrs>& theHighlighted);
-
-  /// Initializes the operation with previously created feature. It is used in sequental operations
-  virtual void initFeature(FeaturePtr theFeature);
-
   /// Returns the operation sketch feature
   /// \returns the sketch instance
-  virtual FeaturePtr sketch() const;
+  virtual CompositeFeaturePtr sketch() const;
 
   /// Gives the current selected objects to be processed by the operation
   /// \param theEvent the mouse event
   /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
-  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                             const std::list<ModuleBase_ViewerPrs>& theSelected,
-                             const std::list<ModuleBase_ViewerPrs>& theHighlighted);
-
+  virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+                             ModuleBase_ISelection* theSelection);
 
- public slots:
-  /// Slots which listen the mode widget activation
-  /// \param theWidget the model widget
-  virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
 
  protected:
-  ///
- void activateByPreselection();
   /// Set value to the active widget
   /// \param theFeature the feature
   /// \param theX the horizontal coordinate
   /// \param theY the vertical coordinate
   /// \return true if the point is set
-  bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
+  //bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
 
  protected:
-  FeaturePtr myInitFeature;  ///< the initial feature
-  FeaturePtr mySketch;  ///< the sketch of the feature
-  
-  ModuleBase_ModelWidget* myActiveWidget;  ///< the active widget
-
-  std::list<ModuleBase_ViewerPrs> myPreSelection;
+  CompositeFeaturePtr mySketch;  ///< the sketch of the feature
 };
 
 #endif
index 1e7e3468b2796b014ee8412ce0650632b65c437b..c2780006535a3cc6645a7c75db092c66c516f3a2 100644 (file)
@@ -18,6 +18,7 @@
 #include <SketchPlugin_ConstraintParallel.h>
 #include <SketchPlugin_ConstraintPerpendicular.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintRigid.h>
 
 #include <GeomAPI_Pnt2d.h>
 
@@ -25,6 +26,9 @@
 #include <ModuleBase_WidgetPoint2D.h>
 #include <ModuleBase_WidgetValueFeature.h>
 #include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IViewer.h>
 
 #include <XGUI_Constants.h>
 
@@ -44,7 +48,7 @@ using namespace std;
 
 PartSet_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId,
                                                                QObject* theParent,
-                                                               FeaturePtr theFeature)
+                                                               CompositeFeaturePtr theFeature)
     : PartSet_OperationFeatureBase(theId, theParent, theFeature)
 {
 }
@@ -62,29 +66,25 @@ bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId)
       || theId == SketchPlugin_ConstraintRadius::ID()
       || theId == SketchPlugin_ConstraintParallel::ID()
       || theId == SketchPlugin_ConstraintPerpendicular::ID()
-      || theId == SketchPlugin_ConstraintCoincidence::ID();
+      || theId == SketchPlugin_ConstraintCoincidence::ID()
+      || theId == SketchPlugin_ConstraintRigid::ID();
 }
 
 bool PartSet_OperationFeatureCreate::canBeCommitted() const
 {
-  if (PartSet_OperationSketchBase::canBeCommitted())
-    return !myActiveWidget;
+  if (PartSet_OperationSketchBase::canBeCommitted()) {
+    //if(myActiveWidget && !myActiveWidget->isComputedDefault()) {
+    return isValid();
+  }
   return false;
 }
 
-std::list<int> PartSet_OperationFeatureCreate::getSelectionModes(ObjectPtr theFeature) const
-{
-  std::list<int> aModes;
-  if (theFeature != feature())
-    aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
-  return aModes;
-}
-
-void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
 {
     double aX, anY;
-    gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
-    PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+    Handle(V3d_View) aView = theViewer->activeView();
+    gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
+    PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
     setWidgetValue(feature(), aX, anY);
     flushUpdated();
 }
@@ -104,36 +104,39 @@ void PartSet_OperationFeatureCreate::keyReleased(const int theKey)
   }
 }
 
-void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                                 const std::list<ModuleBase_ViewerPrs>& theSelected,
-                                                 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
+void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+                                                   ModuleBase_ISelection* theSelection)
 {
-  gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+  Handle(V3d_View) aView = theViewer->activeView();
+  gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
   double aX = aPoint.X(), anY = aPoint.Y();
   bool isClosedContour = false;
 
-  if (theSelected.empty()) {
-    PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+  QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+
+  if (aSelected.empty()) {
+    PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
   } else {
-    ModuleBase_ViewerPrs aPrs = theSelected.front();
+    ModuleBase_ViewerPrs aPrs = aSelected.first();
     const TopoDS_Shape& aShape = aPrs.shape();
     if (!aShape.IsNull()) {
       if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
         const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
         if (!aVertex.IsNull()) {
           aPoint = BRep_Tool::Pnt(aVertex);
-          PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
-          PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(), aX, anY);
+          PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
+          ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+          PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
           isClosedContour = true;
         }
       } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
-        PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+        PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
       }
     }
   }
   ObjectPtr aFeature;
-  if (!theSelected.empty()) {
-    ModuleBase_ViewerPrs aPrs = theSelected.front();
+  if (!aSelected.empty()) {
+    ModuleBase_ViewerPrs aPrs = aSelected.first();
     aFeature = aPrs.object();
   } else {
     aFeature = feature();  // for the widget distance only
@@ -142,26 +145,22 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle
   bool isApplyed = setWidgetValue(aFeature, aX, anY);
   if (isApplyed) {
     flushUpdated();
-    emit activateNextWidget(myActiveWidget);
+    myPropertyPanel->activateNextWidget();
   }
 
-  if (commit() && !isClosedContour) {
-    // if the point creation is finished, the next mouse release should commit the modification
-    // the next release can happens by double click in the viewer
-    restartOperation(feature()->getKind(), feature());
-    return;
+  if (!myPropertyPanel->activeWidget()) {
+    if(commit() && !isClosedContour) {
+      // if the point creation is finished, the next mouse release should commit the modification
+      // the next release can happens by double click in the viewer
+      restartOperation(feature()->getKind(), feature());
+    }
   }
 }
 
-void PartSet_OperationFeatureCreate::activateNextToCurrentWidget()
-{
-  emit activateNextWidget(myActiveWidget);
-}
-
 void PartSet_OperationFeatureCreate::startOperation()
 {
   PartSet_OperationSketchBase::startOperation();
-  emit multiSelectionEnabled(false);
+  //emit multiSelectionEnabled(false);
 }
 
 void PartSet_OperationFeatureCreate::abortOperation()
@@ -173,7 +172,7 @@ void PartSet_OperationFeatureCreate::abortOperation()
 void PartSet_OperationFeatureCreate::stopOperation()
 {
   PartSet_OperationSketchBase::stopOperation();
-  emit multiSelectionEnabled(true);
+  //emit multiSelectionEnabled(true);
 }
 
 void PartSet_OperationFeatureCreate::afterCommitOperation()
@@ -182,20 +181,26 @@ void PartSet_OperationFeatureCreate::afterCommitOperation()
   emit featureConstructed(feature(), FM_Deactivation);
 }
 
-FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage)
+FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage,
+  CompositeFeaturePtr theCompositeFeature)
 {
-  FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false);
-  if (sketch()) {
-    boost::shared_ptr<SketchPlugin_Feature> aFeature = boost::dynamic_pointer_cast<
-        SketchPlugin_Feature>(sketch());
+  FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false, sketch());
 
-    aFeature->addSub(aNewFeature);
-  }
-  //myFeaturePrs->init(aNewFeature);
-  //myFeaturePrs->setFeature(myInitFeature, SM_FirstPoint);
-
-//TODO  emit featureConstructed(aNewFeature, FM_Activation);
   if (theFlushMessage)
     flushCreated();
   return aNewFeature;
 }
+
+
+void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
+{
+  PartSet_OperationFeatureBase::onWidgetActivated(theWidget);
+  if (myInitFeature && theWidget) {
+    ModuleBase_WidgetPoint2D* aWgt = dynamic_cast<ModuleBase_WidgetPoint2D*>(theWidget);
+    if (aWgt && aWgt->initFromPrevious(myInitFeature)) {
+      myInitFeature = FeaturePtr();
+      if (myPropertyPanel)
+        myPropertyPanel->activateNextWidget();
+    }
+  }
+}
index f254b713a0f7c21ee5ab0f5bfc6a0b2e1c680235..bbc83f5007c9143d6b61abfac82c4eae195c9870 100644 (file)
@@ -34,34 +34,34 @@ Q_OBJECT
   /// \param theId the feature identifier
   /// \param theParent the operation parent
   /// \param theSketch the parent feature
-  PartSet_OperationFeatureCreate(const QString& theId, QObject* theParent, FeaturePtr theSketch);
+  PartSet_OperationFeatureCreate(
+    const QString& theId, QObject* theParent, CompositeFeaturePtr theSketch);
   /// Destructor
   virtual ~PartSet_OperationFeatureCreate();
 
-  /// Returns the operation local selection mode
-  /// \param theFeature the feature object to get the selection mode
-  /// \return the selection mode
-  virtual std::list<int> getSelectionModes(ObjectPtr theFeature) const;
-
   /// Gives the current mouse point in the viewer
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
-  virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+  virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer);
 
   /// Gives the current selected objects to be processed by the operation
   /// \param theEvent the mouse event
   /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
-  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                             const std::list<ModuleBase_ViewerPrs>& theSelected,
-                             const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+  virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+                             ModuleBase_ISelection* theSelection);
   /// Processes the key pressed in the view
   /// \param theKey a key value
   virtual void keyReleased(const int theKey);
 
-  /// alias for activateNextWidget(myActiveWidget);
-  virtual void activateNextToCurrentWidget();
+  /// Initializes the operation with previously created feature. It is used in sequental operations
+  void initFeature(FeaturePtr theFeature) { myInitFeature = theFeature; }
+
+ public slots:
+  /// Slots which listen the mode widget activation
+  /// \param theWidget the model widget
+  virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
 
  protected:
   /// \brief Virtual method called when operation is started
@@ -85,11 +85,16 @@ Q_OBJECT
   /// the sketch feature
   /// \param theFlushMessage the flag whether the create message should be flushed
   /// \returns the created feature
-  virtual FeaturePtr createFeature(const bool theFlushMessage = true);
+  virtual FeaturePtr createFeature(const bool theFlushMessage = true,
+    CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
 
   /// Verifies whether this operator can be commited.
   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
   virtual bool canBeCommitted() const;
+
+protected:
+  /// Feature of previous operation (for sequintal operations)
+  FeaturePtr myInitFeature;
 };
 
 #endif
index 2036d55760d69e3bf540dd47eef848aafea8f1a8..f84466fe2e4261ff5f6613e2ac569d574659d31e 100644 (file)
@@ -5,12 +5,16 @@
 #include <PartSet_OperationFeatureEdit.h>
 #include <PartSet_Tools.h>
 #include <PartSet_OperationSketch.h>
+#include <PartSet_OperationFeatureEditMulti.h>
 
 #include <SketchPlugin_Constraint.h>
 
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_WidgetEditor.h>
 #include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IViewer.h>
 
 #include <ModelAPI_Events.h>
 
@@ -39,84 +43,106 @@ using namespace std;
 
 PartSet_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId,
                                                            QObject* theParent,
-                                                           FeaturePtr theFeature)
+                                                           CompositeFeaturePtr theFeature)
     : PartSet_OperationFeatureBase(theId, theParent, theFeature),
       myIsBlockedSelection(false)
 {
+  myIsEditing = true;
 }
 
 PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit()
 {
 }
 
-void PartSet_OperationFeatureEdit::initFeature(FeaturePtr theFeature)
-{
-  setEditingFeature(theFeature);
-}
 
-void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                                const std::list<ModuleBase_ViewerPrs>& theSelected,
-                                                const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection)
 {
-  if(myActiveWidget && myActiveWidget->isViewerSelector()) {
+  ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+  if(aActiveWgt && aActiveWgt->isViewerSelector()) {
     // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
-    PartSet_OperationFeatureBase::mousePressed(theEvent, theView, theSelected, theHighlighted);
+    PartSet_OperationFeatureBase::mousePressed(theEvent, theViewer, theSelection);
     return;
   }
+  QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+  QList<ModuleBase_ViewerPrs> aHighlighted = theSelection->getHighlighted();
+  bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
+  if (aHasShift && !aHighlighted.empty()) {
+    foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) {
+      aSelected.append(aPrs);
+    }
+  }
   ObjectPtr aObject;
-  if (!theHighlighted.empty())
-    aObject = theHighlighted.front().object();
-  if (!aObject && !theSelected.empty())  // changed for a constrain
-    aObject = theSelected.front().object();
+  if (!aSelected.empty()) {
+    aObject = aSelected.first().object();
+  } else {   
+    if (!aHighlighted.empty())
+      aObject = aHighlighted.first().object();
+  }
+  //if (!theHighlighted.empty())
+  //  aObject = theHighlighted.front().object();
+  //if (!aObject && !theSelected.empty())  // changed for a constrain
+  //  aObject = theSelected.front().object();
 
   FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
-  if (!aFeature || aFeature != feature()) {
+  if (!aFeature || aFeature != feature() || (aSelected.size() > 1)) {
     if (commit()) {
+      theViewer->enableSelection(true);
       emit featureConstructed(feature(), FM_Deactivation);
 
-      bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
-      if (aHasShift && !theHighlighted.empty()) {
-        QList<ObjectPtr> aSelected;
-        std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
-        for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
-          aSelected.append((*aIt).object());
-        /*for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
-         if (!aSelected.contains((*aIt).object()))
-         aSelected.append((*aIt).object());
-         }*/
-        //aSelected.push_back(feature());
-        //aSelected.push_back(theHighlighted.front().object());
-        emit setSelection(aSelected);
-      } else if (aFeature) {
-        restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
+      // If we have selection and prehilighting with shift pressed 
+      // Then we have to select all these objects and restart as multi edit operfation
+      //bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
+      //if (aHasShift && !theHighlighted.empty()) {
+      //  QList<ObjectPtr> aSelected;
+      //  std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
+      //  for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
+      //    aSelected.append((*aIt).object());
+
+      //  for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
+      //    if (!aSelected.contains((*aIt).object()))
+      //      aSelected.append((*aIt).object());
+      //  }
+      //  emit setSelection(aSelected);
+      //} else 
+      if (aFeature) {
+        std::string anOperationType =
+            (aSelected.size() > 1) ?
+                PartSet_OperationFeatureEditMulti::Type() : PartSet_OperationFeatureEdit::Type();
+        restartOperation(anOperationType, aFeature);
       }
+      //}
     }
   }
 }
 
-void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
 {
   if (!(theEvent->buttons() & Qt::LeftButton))
     return;
+  Handle(V3d_View) aView = theViewer->activeView();
+  gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
 
-  gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+  theViewer->enableSelection(false);
 
-  blockSelection(true);
+  //blockSelection(true);
   if (myCurPoint.myIsInitialized) {
     double aCurX, aCurY;
-    PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
+    PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), aView, aCurX, aCurY);
 
     double aX, anY;
-    PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+    PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
 
     double aDeltaX = aX - aCurX;
     double aDeltaY = anY - aCurY;
 
     boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
         SketchPlugin_Feature>(feature());
-    aSketchFeature->move(aDeltaX, aDeltaY);
-    static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
-    ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
+    // MPV: added condition because it could be external edge of some object, not sketch
+    if (aSketchFeature && aSketchFeature->sketch() == sketch().get()) {
+      aSketchFeature->move(aDeltaX, aDeltaY);
+      static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+      ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
+    }
   }
   sendFeatures();
 
@@ -124,26 +150,29 @@ void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_
 }
 
 void PartSet_OperationFeatureEdit::mouseReleased(
-    QMouseEvent* theEvent, Handle(V3d_View) theView,
-    const std::list<ModuleBase_ViewerPrs>& theSelected,
-    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+    QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+    ModuleBase_ISelection* theSelection)
 {
-  if(myActiveWidget && myActiveWidget->isViewerSelector()) {
+  theViewer->enableSelection(true);
+  ModuleBase_ModelWidget* aActiveWgt = 0;
+  if (myPropertyPanel)
+    aActiveWgt = myPropertyPanel->activeWidget();
+  if(aActiveWgt && aActiveWgt->isViewerSelector()) {
     // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
-    PartSet_OperationFeatureBase::mouseReleased(theEvent, theView, theSelected, theHighlighted);
-  } else {
-    blockSelection(false);
-  }
+    PartSet_OperationFeatureBase::mouseReleased(theEvent, theViewer, theSelection);
+  }// else {
+    //blockSelection(false);
+  //}
 }
 
 void PartSet_OperationFeatureEdit::mouseDoubleClick(
     QMouseEvent* theEvent, Handle_V3d_View theView,
-    const std::list<ModuleBase_ViewerPrs>& theSelected,
-    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+    ModuleBase_ISelection* theSelection)
 {
   // TODO the functionality is important only for constraint feature. Should be moved in another place
-  if (!theSelected.empty()) {
-    ModuleBase_ViewerPrs aFeaturePrs = theSelected.front();
+  QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+  if (!aSelected.empty()) {
+    ModuleBase_ViewerPrs aFeaturePrs = aSelected.first();
     if (!aFeaturePrs.owner().IsNull()) {
       Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(
           aFeaturePrs.owner());
@@ -163,38 +192,39 @@ void PartSet_OperationFeatureEdit::mouseDoubleClick(
 void PartSet_OperationFeatureEdit::startOperation()
 {
   PartSet_OperationSketchBase::startOperation();
-  emit multiSelectionEnabled(false);
+  //emit multiSelectionEnabled(false);
 
   myCurPoint.clear();
 }
 
 void PartSet_OperationFeatureEdit::stopOperation()
 {
-  emit multiSelectionEnabled(true);
+  //emit multiSelectionEnabled(true);
 
-  blockSelection(false, false);
-}
-
-void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
-{
-  if (myIsBlockedSelection == isBlocked)
-    return;
-
-  myIsBlockedSelection = isBlocked;
-  QList<ObjectPtr> aFeatureList;
-  aFeatureList.append(feature());
-
-  if (isBlocked) {
-    emit setSelection(QList<ObjectPtr>());
-    emit stopSelection(aFeatureList, true);
-  } else {
-    emit stopSelection(aFeatureList, false);
-    if (isRestoreSelection)
-      emit setSelection(aFeatureList);
-  }
+  //blockSelection(false, false);
 }
 
-FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
+//void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
+//{
+//  if (myIsBlockedSelection == isBlocked)
+//    return;
+//
+//  myIsBlockedSelection = isBlocked;
+//  QList<ObjectPtr> aFeatureList;
+//  aFeatureList.append(feature());
+//
+//  //if (isBlocked) {
+//  //  emit setSelection(QList<ObjectPtr>());
+//  //  emit stopSelection(aFeatureList, true);
+//  //} else {
+//  //  emit stopSelection(aFeatureList, false);
+//  //  if (isRestoreSelection)
+//  //    emit setSelection(aFeatureList);
+//  //}
+//}
+
+FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool theFlushMessage,
+  CompositeFeaturePtr theCompositeFeature)
 {
   // do nothing in order to do not create a new feature
   return FeaturePtr();
index 2082258b0257000b6c3d867f7bbf7d861ca00445..293c63d952fd60f68267e7d34dafd04fc3d808bf 100644 (file)
@@ -11,6 +11,7 @@
 #include <QObject>
 
 class QMouseEvent;
+class ModuleBase_ISelection;
 
 /*!
  \class PartSet_OperationFeatureEdit
@@ -66,33 +67,28 @@ Q_OBJECT
   /// \param theId the feature identifier
   /// \param theParent the operation parent
   /// \param theFeature the parent feature
-  PartSet_OperationFeatureEdit(const QString& theId, QObject* theParent, FeaturePtr theFeature);
+  PartSet_OperationFeatureEdit(const QString& theId, QObject* theParent, CompositeFeaturePtr theFeature);
   /// Destructor
   virtual ~PartSet_OperationFeatureEdit();
 
-  /// Initializes the operation with previously created feature. It is used in sequental operations
-  virtual void initFeature(FeaturePtr theFeature);
-
   /// Processes the mouse pressed in the point
   /// \param theEvent the mouse event
   /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
-  virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
-                            const std::list<ModuleBase_ViewerPrs>& theSelected,
-                            const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+  virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection);
+
   /// Gives the current mouse point in the viewer
   /// \param theEvent the mouse event
   /// \param theView a viewer to have the viewer the eye position
-  virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+  virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer);
   /// Gives the current selected objects to be processed by the operation
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
-  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                             const std::list<ModuleBase_ViewerPrs>& theSelected,
-                             const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+  virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+                             ModuleBase_ISelection* theSelection);
 
   /// Processes the mouse double click in the point
   /// \param theEvent the mouse event
@@ -100,8 +96,7 @@ Q_OBJECT
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
   virtual void mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                const std::list<ModuleBase_ViewerPrs>& theSelected,
-                                const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+                                ModuleBase_ISelection* theSelection);
 
  protected:
   /// \brief Virtual method called when operation is started
@@ -117,7 +112,8 @@ Q_OBJECT
   /// Returns NULL feature. This is an operation of edition, not creation.
   /// \param theFlushMessage the flag whether the create message should be flushed
   /// \returns the created feature
-  virtual FeaturePtr createFeature(const bool theFlushMessage = true);
+  virtual FeaturePtr createFeature(const bool theFlushMessage = true, 
+    CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
 
  protected:
   /// Emits a signal about the selection blocking. Emits a signal to change the selection.
@@ -125,7 +121,7 @@ Q_OBJECT
   /// the internal operation features are to be selected
   /// \param isBlocked the state whether the operation is blocked or unblocked
   /// \param isRestoreSelection the state whether the selected objects should be reselected
-  void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
+  //void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
 
   /// Sends the features
   void sendFeatures();
index cd0de892541cc01ab7374816c9431d9f165cf55a..4b10858a0bc40ff31371022d816479a616c610e3 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_IViewer.h>
+#include <ModuleBase_ISelection.h>
 
 #include <ModelAPI_Events.h>
 
 
 #include <V3d_View.hxx>
 
+#include <QMouseEvent>
 #ifdef _DEBUG
 #include <QDebug>
 #endif
 
-#include <QMouseEvent>
-
-using namespace std;
+//using namespace std;
 
 PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QString& theId,
                                                                      QObject* theParent,
-                                                                     FeaturePtr theFeature)
+                                                                     CompositeFeaturePtr theFeature)
     : PartSet_OperationSketchBase(theId, theParent),
       mySketch(theFeature),
       myIsBlockedSelection(false)
 {
+  myIsEditing = true;
 }
 
 PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti()
@@ -46,60 +48,78 @@ PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti()
 }
 
 
-void PartSet_OperationFeatureEditMulti::initSelection(
-    const std::list<ModuleBase_ViewerPrs>& theSelected,
-    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+bool isContains(const QList<ModuleBase_ViewerPrs>& theSelected, const ModuleBase_ViewerPrs& thePrs)
 {
-  if (!theHighlighted.empty()) {
-    // if there is highlighted object, we check whether it is in the list of selected objects
-    // in that case this object is a handle of the moved lines. If there no such object in the selection,
-    // the hightlighted object should moved and the selection is skipped. The skipped selection will be
-    // deselected in the viewer by blockSelection signal in the startOperation method.
-    bool isSelected = false;
-    std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected
-        .end();
-    for (; anIt != aLast && !isSelected; anIt++) {
-      isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
-    }
-    if (!isSelected)
-      myFeatures = theHighlighted;
-    else
-      myFeatures = theSelected;
-  } else
-    myFeatures = theSelected;
+  foreach (ModuleBase_ViewerPrs aPrs, theSelected) {
+    if (aPrs.object() == thePrs.object())
+      return true;
+  }
+  return false;
 }
 
-void PartSet_OperationFeatureEditMulti::initFeature(FeaturePtr theFeature)
+
+void PartSet_OperationFeatureEditMulti::initSelection(ModuleBase_ISelection* theSelection)
 {
-  setEditingFeature(theFeature);
+  //if (!theHighlighted.empty()) {
+  //  // if there is highlighted object, we check whether it is in the list of selected objects
+  //  // in that case this object is a handle of the moved lines. If there no such object in the selection,
+  //  // the hightlighted object should moved and the selection is skipped. The skipped selection will be
+  //  // deselected in the viewer by blockSelection signal in the startOperation method.
+  //  bool isSelected = false;
+  //  std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(), 
+  //    aLast = theSelected.end();
+  //  for (; anIt != aLast && !isSelected; anIt++) {
+  //    isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
+  //  }
+  //  if (!isSelected)
+  //    myFeatures = theHighlighted;
+  //  else
+  //    myFeatures = theSelected;
+  //} else
+  myFeatures = theSelection->getSelected();
+  QList<ModuleBase_ViewerPrs> aHighlighted = theSelection->getHighlighted();
+  // add highlighted elements if they are not selected
+  foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) {
+    if (!isContains(myFeatures, aPrs))
+      myFeatures.append(aPrs);
+  }
+  // Remove current feature if it is in the list (it will be moved as main feature)
+  foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
+    FeaturePtr aF = ModelAPI_Feature::feature(aPrs.object());
+    if (ModelAPI_Feature::feature(aPrs.object()) == feature()) {
+      myFeatures.removeOne(aPrs);
+      break;
+    }
+  }
 }
 
-FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
+CompositeFeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
 {
   return mySketch;
 }
 
-void PartSet_OperationFeatureEditMulti::mousePressed(
-    QMouseEvent* theEvent, Handle(V3d_View) theView,
-    const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
-    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
-{
-}
+//void PartSet_OperationFeatureEditMulti::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection)
+//{
+//}
 
-void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
 {
   if (!(theEvent->buttons() & Qt::LeftButton))
     return;
 
-  gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+  if (theViewer->isSelectionEnabled())
+    theViewer->enableSelection(false);
+
+  Handle(V3d_View) aView = theViewer->activeView();
+  gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
 
-  blockSelection(true);
+  //blockSelection(true);
   if (myCurPoint.myIsInitialized) {
     double aCurX, aCurY;
-    PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
+    PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), aView, aCurX, aCurY);
 
     double aX, anY;
-    PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+    PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
 
     double aDeltaX = aX - aCurX;
     double aDeltaY = anY - aCurY;
@@ -108,10 +128,8 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle
         SketchPlugin_Feature>(feature());
     aSketchFeature->move(aDeltaX, aDeltaY);
 
-    std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures
-        .end();
-    for (; anIt != aLast; anIt++) {
-      ObjectPtr aObject = (*anIt).object();
+    foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
+      ObjectPtr aObject = aPrs.object();
       if (!aObject || aObject == feature())
         continue;
       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
@@ -128,16 +146,13 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle
 }
 
 void PartSet_OperationFeatureEditMulti::mouseReleased(
-    QMouseEvent* theEvent, Handle(V3d_View) theView,
-    const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
-    const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
+    QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+    ModuleBase_ISelection* theSelection)
 {
+  theViewer->enableSelection(true);
   if (commit()) {
-    std::list<ModuleBase_ViewerPrs> aFeatures = myFeatures;
-    std::list<ModuleBase_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast =
-        aFeatures.end();
-    for (; anIt != aLast; anIt++) {
-      ObjectPtr aFeature = (*anIt).object();
+    foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
+      ObjectPtr aFeature = aPrs.object();
       if (aFeature) {
         emit featureConstructed(aFeature, FM_Deactivation);
       }
@@ -148,54 +163,51 @@ void PartSet_OperationFeatureEditMulti::mouseReleased(
 void PartSet_OperationFeatureEditMulti::startOperation()
 {
   PartSet_OperationSketchBase::startOperation();
-  emit multiSelectionEnabled(false);
+  //emit multiSelectionEnabled(false);
 
-  blockSelection(true);
+  //blockSelection(true);
 
   myCurPoint.clear();
 }
 
 void PartSet_OperationFeatureEditMulti::stopOperation()
 {
-  emit multiSelectionEnabled(true);
+  //emit multiSelectionEnabled(true);
 
-  blockSelection(false, true);
+  //blockSelection(false, true);
 
   myFeatures.clear();
 }
 
-void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked,
-                                                       const bool isRestoreSelection)
-{
-  if (myIsBlockedSelection == isBlocked)
-    return;
-
-  myIsBlockedSelection = isBlocked;
-  QList<ObjectPtr> aFeatureList;
-  std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
-      myFeatures.end();
-  /*for(; anIt != aLast; anIt++)
-   aFeatureList.append((*anIt).feature());*/
-  if (isBlocked) {
-    emit setSelection(QList<ObjectPtr>());
-    emit stopSelection(aFeatureList, true);
-  } else {
-    emit stopSelection(aFeatureList, false);
-    if (isRestoreSelection) {
-      emit setSelection(aFeatureList);
-    }
-  }
-}
+//void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked,
+//                                                       const bool isRestoreSelection)
+//{
+//  if (myIsBlockedSelection == isBlocked)
+//    return;
+//
+//  myIsBlockedSelection = isBlocked;
+//  QList<ObjectPtr> aFeatureList;
+////  std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
+////      myFeatures.end();
+//  /*for(; anIt != aLast; anIt++)
+//   aFeatureList.append((*anIt).feature());*/
+//  //if (isBlocked) {
+//  //  emit setSelection(QList<ObjectPtr>());
+//  //  emit stopSelection(aFeatureList, true);
+//  //} else {
+//  //  emit stopSelection(aFeatureList, false);
+//  //  if (isRestoreSelection) {
+//  //    emit setSelection(aFeatureList);
+//  //  }
+//  //}
+//}
 
 void PartSet_OperationFeatureEditMulti::sendFeatures()
 {
   static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
 
-  std::list<FeaturePtr> aFeatures;
-  std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
-      myFeatures.end();
-  for (; anIt != aLast; anIt++) {
-    ObjectPtr aFeature = (*anIt).object();
+  foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
+    ObjectPtr aFeature = aPrs.object();
     if (!aFeature)
       continue;
 
index 0f21f34ab0dd099c7b432dde41526778fc3919b8..77a9dbb5408916e6bc38c7300a677213d99f7801 100644 (file)
@@ -9,6 +9,9 @@
 
 #include <PartSet_OperationSketchBase.h>
 #include <QObject>
+#include <QList>
+
+#include <list>
 
 class QMouseEvent;
 
@@ -66,43 +69,39 @@ Q_OBJECT
   /// \param theParent the operation parent
   /// \param theFeature the parent feature
   PartSet_OperationFeatureEditMulti(const QString& theId, QObject* theParent,
-                                    FeaturePtr theFeature);
+                                    CompositeFeaturePtr theFeature);
   /// Destructor
   virtual ~PartSet_OperationFeatureEditMulti();
 
-  /// Initializes the operation with previously created feature. It is used in sequental operations
-  virtual void initFeature(FeaturePtr theFeature);
-
   /// Initialisation of operation with preliminary selection
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
-  virtual void initSelection(const std::list<ModuleBase_ViewerPrs>& theSelected,
-                             const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+  virtual void initSelection(ModuleBase_ISelection* theSelection);
 
   /// Returns the operation sketch feature
   /// \returns the sketch instance
-  virtual FeaturePtr sketch() const;
+  virtual CompositeFeaturePtr sketch() const;
 
   /// Processes the mouse pressed in the point
   /// \param theEvent the mouse event
   /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
-  virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
-                            const std::list<ModuleBase_ViewerPrs>& theSelected,
-                            const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+  //virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection);
+
   /// Gives the current mouse point in the viewer
   /// \param theEvent the mouse event
   /// \param theView a viewer to have the viewer the eye position
-  virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+  virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer);
+
   /// Gives the current selected objects to be processed by the operation
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
-  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                             const std::list<ModuleBase_ViewerPrs>& theSelected,
-                             const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+  virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, 
+                             ModuleBase_ISelection* theSelection);
+
  protected:
   /// \brief Virtual method called when operation is started
   /// Virtual method called when operation started (see start() method for more description)
@@ -119,14 +118,14 @@ Q_OBJECT
   /// the internal operation features are to be selected
   /// \param isBlocked the state whether the operation is blocked or unblocked
   /// \param isRestoreSelection the state whether the selected objects should be reselected
-  void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
+  //void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
 
   /// Sends the features
   void sendFeatures();
 
  private:
-  FeaturePtr mySketch;  ///< the sketch feature
-  std::list<ModuleBase_ViewerPrs> myFeatures;  ///< the features to apply the edit operation
+  CompositeFeaturePtr mySketch;  ///< the sketch feature
+  QList<ModuleBase_ViewerPrs> myFeatures;  ///< the features to apply the edit operation
   Point myCurPoint;  ///< the current 3D point clicked or moved
   bool myIsBlockedSelection;  ///< the state of the last state of selection blocked signal
 };
index 72338efffb68d0017d4fde211a7b2bd4cdc3d84c..331f7e63e24b2ea1b26a17e99d3870b7bf353cfc 100644 (file)
@@ -22,6 +22,8 @@
 #include <GeomAPI_XYZ.h>
 
 #include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IViewer.h>
 #include <Events_Loop.h>
 
 #include <AIS_Shape.hxx>
@@ -48,72 +50,68 @@ PartSet_OperationSketch::~PartSet_OperationSketch()
 {
 }
 
-std::list<int> PartSet_OperationSketch::getSelectionModes(ObjectPtr theFeature) const
+CompositeFeaturePtr PartSet_OperationSketch::sketch() const
 {
-  std::list<int> aModes;
-  if (!hasSketchPlane())
-    aModes.push_back(TopAbs_FACE);
-  else
-    aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
-
-  return aModes;
-}
-
-/// Initializes the operation with previously created feature. It is used in sequental operations
-void PartSet_OperationSketch::initFeature(FeaturePtr theFeature)
-{
-  if (theFeature)
-    setEditingFeature(theFeature);
-}
-
-FeaturePtr PartSet_OperationSketch::sketch() const
-{
-  return feature();
+  return boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
 }
 
-void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                           const std::list<ModuleBase_ViewerPrs>& theSelected,
-                                           const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection)
 {
   if (hasSketchPlane()) {
     // if shift button is pressed and there are some already selected objects, the operation should
     // not be started. We just want to combine some selected objects.
     bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
-    if (aHasShift && theSelected.size() > 0)
-      return;
-
-    if (theHighlighted.size() == 1) {
-      ObjectPtr aFeature = theHighlighted.front().object();
+    QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+    QList<ModuleBase_ViewerPrs> aHighlighted = theSelection->getHighlighted();
+    //if (aHasShift && (aSelected.size() > 0)) {
+      foreach(ModuleBase_ViewerPrs aPrs, aHighlighted)
+        aSelected.append(aPrs);
+    //}
+    //if (aHasShift && aSelected.size() > 0)
+    //  return;
+
+    if (aSelected.size() > 0) {
+      ObjectPtr aFeature = aSelected.first().object();
       if (aFeature) {
         std::string anOperationType =
-            (theSelected.size() > 1) ?
+            (aSelected.size() > 1) ?
                 PartSet_OperationFeatureEditMulti::Type() : PartSet_OperationFeatureEdit::Type();
         restartOperation(anOperationType, aFeature);
       }
-    } else
-      myFeatures = theHighlighted;
-
-  } else {
-    if (!theHighlighted.empty()) {
-      ModuleBase_ViewerPrs aPrs = theHighlighted.front();
-      const TopoDS_Shape& aShape = aPrs.shape();
-      if (!aShape.IsNull())
-        setSketchPlane(aShape);
-    }
+    } //else
+    //myFeatures = aSelected;
+
+  } 
+}
+
+
+void PartSet_OperationSketch::selectionChanged(ModuleBase_ISelection* theSelection)
+{
+  if (hasSketchPlane()) 
+    return;
+
+  QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+  if (!aSelected.empty()) {
+    ModuleBase_ViewerPrs aPrs = aSelected.first();
+    // We have to select a plane before any operation
+    const TopoDS_Shape& aShape = aPrs.shape();
+    if (!aShape.IsNull())
+      setSketchPlane(aShape);
   }
 }
 
-void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                            const std::list<ModuleBase_ViewerPrs>& theSelected,
-                                            const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+
+void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+                                            ModuleBase_ISelection* theSelection)
 {
+  QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
   if (hasSketchPlane()) {
     /// TODO: OCC bug: 25034 - the highlighted list should be filled not only for AIS_Shape
     /// but for other IO, for example constraint dimensions.
     /// It is empty and we have to use the process mouse release to start edition operation
     /// for these objects
-    if (theSelected.size() == 1) {
-      ObjectPtr aObject = theSelected.front().object();
+    if (aSelected.size() == 1) {
+      ObjectPtr aObject = aSelected.first().object();
       if (aObject) {
         restartOperation(PartSet_OperationFeatureEdit::Type(), aObject);
       }
@@ -121,13 +119,14 @@ void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_Vi
   }
 }
 
-void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
 {
   if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty())
     return;
 
   if (myFeatures.size() != 1) {
-    FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), theView, feature(),
+    Handle(V3d_View) aView = theViewer->activeView();
+    FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), aView, feature(),
                                                         myFeatures);
     if (aFeature)
       restartOperation(PartSet_OperationFeatureEditMulti::Type(), aFeature);
@@ -161,8 +160,10 @@ void PartSet_OperationSketch::stopOperation()
 {
   PartSet_OperationSketchBase::stopOperation();
   emit featureConstructed(feature(), FM_Hide);
-  emit closeLocalContext();
+}
 
+void PartSet_OperationSketch::afterCommitOperation()
+{
   FeaturePtr aFeature = feature();
   std::list<ResultPtr> aResults = aFeature->results();
   std::list<ResultPtr>::const_iterator aIt;
@@ -247,12 +248,11 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
   flushUpdated();
 
   emit featureConstructed(feature(), FM_Hide);
-  emit closeLocalContext();
   emit planeSelected(aDir->x(), aDir->y(), aDir->z());
 }
 
 
-bool PartSet_OperationSketch::isGranted(ModuleBase_IOperation* theOperation) const
+bool PartSet_OperationSketch::isGranted(ModuleBase_Operation* theOperation) const
 {
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
   return aPreviewOp != NULL;
index 862c6a4bf3ab7a9e5907074a441cb2b7fd67c929..47601096f7b1af293facbb3c9fd3e2daf98aeb70 100644 (file)
@@ -12,6 +12,7 @@
 #include <SketchPlugin_Sketch.h>
 
 #include <QObject>
+#include <QList>
 
 class Handle_AIS_InteractiveObject;
 
@@ -38,42 +39,32 @@ Q_OBJECT
   virtual ~PartSet_OperationSketch();
 
   /// Returns True if the given operation is a Sketcher operation
-  virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
+  virtual bool isGranted(ModuleBase_Operation* theOperation) const;
 
 
-  /// Returns the operation local selection mode
-  /// \param theFeature the feature object to get the selection mode
-  /// \return the selection mode
-  virtual std::list<int> getSelectionModes(ObjectPtr theFeature) const;
-
-  /// Initializes the operation with previously created feature. It is used in sequental operations
-  virtual void initFeature(FeaturePtr theFeature);
-
   /// Returns the operation sketch feature
   /// \returns the sketch instance
-  virtual FeaturePtr sketch() const;
+  virtual CompositeFeaturePtr sketch() const;
 
   /// Processes the mouse pressed in the point
   /// \param theEvent the mouse event
   /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
-  virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
-                            const std::list<ModuleBase_ViewerPrs>& theSelected,
-                            const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+  virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection);
+
   /// Processes the mouse release in the point
   /// \param theEvent the mouse event
   /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
-  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                             const std::list<ModuleBase_ViewerPrs>& theSelected,
-                             const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+  virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+                             ModuleBase_ISelection* theSelection);
 
   /// Gives the current mouse point in the viewer
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
-  virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+  virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer);
 
   /// Returns the list of the nested features
   /// \return the list of subfeatures
@@ -96,6 +87,9 @@ Q_OBJECT
   /// Set the plane to the current sketch
   /// \param theShape the shape
   void setSketchPlane(const TopoDS_Shape& theShape);
+  
+  /// Called on selection changed when the operation is active
+  virtual void selectionChanged(ModuleBase_ISelection* theSelection);
 
   /// If operation needs to redisplay its result during operation
   /// then this method has to return True
@@ -115,8 +109,11 @@ signals:
   /// Default impl calls corresponding slot and commits immediately.
   virtual void startOperation();
 
+  /// Virtual method called after operation committed (see commit() method for more description)
+  virtual void afterCommitOperation();
+
  private:
-  std::list<ModuleBase_ViewerPrs> myFeatures;  ///< the features to apply the edit operation
+  QList<ModuleBase_ViewerPrs> myFeatures;  ///< the features to apply the edit operation
 };
 
 #endif
index 9dd3141eb50135b8836616dde205871b20884857..1f7550403123cabec03ac0a7ad79dacf3d6a482b 100644 (file)
@@ -6,6 +6,11 @@
 #include <PartSet_Tools.h>
 #include <ModelAPI_ResultBody.h>
 
+#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_IViewer.h>
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_WidgetValueFeature.h>
+
 #include <SketchPlugin_Feature.h>
 #include <V3d_View.hxx>
 #include <AIS_Shape.hxx>
@@ -48,20 +53,6 @@ std::list<FeaturePtr> PartSet_OperationSketchBase::subFeatures() const
   return std::list<FeaturePtr>();
 }
 
-std::list<int> PartSet_OperationSketchBase::getSelectionModes(ObjectPtr theFeature) const
-{
-  //TODO: Define position of selection modes definition
-  std::list<int> aModes;
-  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
-  if (aFeature && PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
-    aModes.push_back(AIS_DSM_Text);
-    aModes.push_back(AIS_DSM_Line);
-  } else {
-    aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
-    aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
-  }
-  return aModes;
-}
 FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
 {
   ModuleBase_Operation::createFeature(theFlushMessage);
@@ -70,25 +61,24 @@ FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage
   return myFeature;
 }
 
-void PartSet_OperationSketchBase::mousePressed(
-    QMouseEvent* theEvent, Handle_V3d_View theView,
-    const std::list<ModuleBase_ViewerPrs>& theSelected,
-    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection)
 {
 }
 void PartSet_OperationSketchBase::mouseReleased(
-    QMouseEvent* theEvent, Handle_V3d_View theView,
-    const std::list<ModuleBase_ViewerPrs>& theSelected,
-    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+    QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+    ModuleBase_ISelection* theSelection)
 {
 }
-void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
 {
 }
 void PartSet_OperationSketchBase::mouseDoubleClick(
     QMouseEvent* theEvent, Handle_V3d_View theView,
-    const std::list<ModuleBase_ViewerPrs>& theSelected,
-    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+    ModuleBase_ISelection* theSelection)
+{
+}
+
+void PartSet_OperationSketchBase::selectionChanged(ModuleBase_ISelection* theSelection)
 {
 }
 
@@ -98,11 +88,11 @@ void PartSet_OperationSketchBase::restartOperation(const std::string& theType, O
   if (aFeature) {
     QStringList aNested = this->nestedFeatures();
     if (!aNested.isEmpty()) {
-      if (aNested.contains(QString(aFeature->getKind().c_str()))) 
-        emit restartRequired(theType, theFeature);
-      else
+      if (!aNested.contains(QString(aFeature->getKind().c_str())))
         return;
     }
   }
   emit restartRequired(theType, theFeature);
 }
+
+
index 9b43039eaeff0754ec8f71daee153722f56a92f8..ef3991a9a1710c0557e48c23b3f22d77d44c7830 100644 (file)
@@ -27,6 +27,8 @@ class Handle_V3d_View;
 class QMouseEvent;
 class GeomAPI_Shape;
 class ModuleBase_ViewerPrs;
+class ModuleBase_ISelection;
+class ModuleBase_IViewer;
 
 /*!
  \class PartSet_OperationSketchBase
@@ -60,50 +62,29 @@ Q_OBJECT
   /// \return the list of subfeatures
   virtual std::list<FeaturePtr> subFeatures() const;
 
-  /// Returns the operation local selection mode
-  /// \param theFeature the feature object to get the selection mode
-  /// \return the selection mode
-  virtual std::list<int> getSelectionModes(ObjectPtr theFeature) const;
-
-  /// Initializes the operation with previously created feature. It is used in sequental operations
-  virtual void initFeature(FeaturePtr theFeature)
-  {
-  }
-
-  /// Initialisation of operation with preliminary selection
-  /// \param theSelected the list of selected presentations
-  /// \param theHighlighted the list of highlighted presentations
-  virtual void initSelection(const std::list<ModuleBase_ViewerPrs>& theSelected,
-                             const std::list<ModuleBase_ViewerPrs>& theHighlighted)
-  {
-  }
-
   /// Returns the operation sketch feature
   /// \returns the sketch instance
-  virtual FeaturePtr sketch() const = 0;
+  virtual CompositeFeaturePtr sketch() const = 0;
 
   /// Processes the mouse pressed in the point
   /// \param theEvent the mouse event
   /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
-  virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
-                            const std::list<ModuleBase_ViewerPrs>& theSelected,
-                            const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+  virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection);
 
   /// Processes the mouse release in the point
   /// \param theEvent the mouse event
   /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
-  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                             const std::list<ModuleBase_ViewerPrs>& theSelected,
-                             const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+  virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+                             ModuleBase_ISelection* theSelection);
 
   /// Processes the mouse move in the point
   /// \param theEvent the mouse event
   /// \param theView a viewer to have the viewer the eye position
-  virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+  virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer);
 
   /// Processes the mouse double click in the point
   /// \param theEvent the mouse event
@@ -111,8 +92,11 @@ Q_OBJECT
   /// \param theSelected the list of selected presentations
   /// \param theHighlighted the list of highlighted presentations
   virtual void mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                const std::list<ModuleBase_ViewerPrs>& theSelected,
-                                const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+                                ModuleBase_ISelection* theSelection);
+
+  
+  /// Called on selection changed when the operation is active
+  virtual void selectionChanged(ModuleBase_ISelection* theSelection);
 
   /// Emits a signal about the operation start. This signal has an information about the feature.
   /// If the provided feature is empty, the current operation feature is used.
@@ -141,7 +125,7 @@ signals:
 
   /// signal to enable/disable multi selection in the viewer
   /// \param theEnabled the boolean state
-  void multiSelectionEnabled(bool theEnabled);
+  //void multiSelectionEnabled(bool theEnabled);
 
   /// signal to enable/disable selection in the viewer
   /// \param theFeatures a list of features to be disabled
@@ -152,9 +136,6 @@ signals:
   /// \param theFeatures a list of features to be disabled
   void setSelection(const QList<ObjectPtr>& theFeatures);
 
-  /// signal to close the operation local context if it is opened
-  void closeLocalContext();
-
  protected:
   /// Creates an operation new feature
   /// In addition to the default realization it appends the created line feature to
index a52a43453679dade0c073386a9fe9516cf8948bc..dc4feb845df6099a441ecbec50a169b55709155c 100644 (file)
@@ -8,6 +8,7 @@
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Document.h>
+#include <ModelAPI_Session.h>
 
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Dir.h>
@@ -25,6 +26,7 @@
 #include <SketchPlugin_ConstraintDistance.h>
 #include <SketchPlugin_ConstraintLength.h>
 #include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_ConstraintRigid.h>
 #include <SketchPlugin_Constraint.h>
 
 #include <ModuleBase_ViewerPrs.h>
@@ -138,21 +140,17 @@ void PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr
 
 FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
                                          FeaturePtr theSketch,
-                                         const std::list<ModuleBase_ViewerPrs>& theFeatures)
+                                         const QList<ModuleBase_ViewerPrs>& theFeatures)
 {
   double aX, anY;
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView);
   PartSet_Tools::convertTo2D(aPoint, theSketch, theView, aX, anY);
 
   FeaturePtr aFeature;
-  std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures
-      .end();
-
   FeaturePtr aDeltaFeature;
   double aMinDelta = -1;
   ModuleBase_ViewerPrs aPrs;
-  for (; anIt != aLast; anIt++) {
-    aPrs = *anIt;
+  foreach (ModuleBase_ViewerPrs aPrs, theFeatures) {
     if (!aPrs.object())
       continue;
     boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
@@ -234,17 +232,16 @@ FeaturePtr PartSet_Tools::feature(FeaturePtr theFeature, const std::string& theA
   return aFeature;
 }
 
-void PartSet_Tools::createConstraint(FeaturePtr theSketch,
+void PartSet_Tools::createConstraint(CompositeFeaturePtr theSketch,
                                      boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
                                      boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
 {
-  boost::shared_ptr<ModelAPI_Document> aDoc = document();
-  FeaturePtr aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID());
-
+  FeaturePtr aFeature;
   if (theSketch) {
-    boost::shared_ptr<SketchPlugin_Feature> aSketch = boost::dynamic_pointer_cast<
-        SketchPlugin_Feature>(theSketch);
-    aSketch->addSub(aFeature);
+    aFeature = theSketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+  } else {
+    boost::shared_ptr<ModelAPI_Document> aDoc = document();
+    aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID());
   }
 
   boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
@@ -261,7 +258,7 @@ void PartSet_Tools::createConstraint(FeaturePtr theSketch,
     aFeature->execute();
 }
 
-void PartSet_Tools::setConstraints(FeaturePtr theSketch, FeaturePtr theFeature,
+void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
                                    const std::string& theAttribute, double theClickedX,
                                    double theClickedY)
 {
@@ -301,7 +298,7 @@ void PartSet_Tools::setConstraints(FeaturePtr theSketch, FeaturePtr theFeature,
   }
 }
 
-boost::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(FeaturePtr theSketch)
+boost::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
 {
   boost::shared_ptr<GeomAPI_Pln> aPlane;
   double aA, aB, aC, aD;
@@ -321,7 +318,7 @@ boost::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(FeaturePtr theSketch)
 }
 
 boost::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
-                                                      FeaturePtr theSketch)
+                                                      CompositeFeaturePtr theSketch)
 {
   boost::shared_ptr<GeomAPI_Pnt> aPoint;
   if (!theSketch || !thePoint2D)
@@ -341,5 +338,6 @@ bool PartSet_Tools::isConstraintFeature(const std::string& theKind)
 {
   return theKind == SketchPlugin_ConstraintDistance::ID()
       || theKind == SketchPlugin_ConstraintLength::ID()
-      || theKind == SketchPlugin_ConstraintRadius::ID();
+      || theKind == SketchPlugin_ConstraintRadius::ID()
+      || theKind == SketchPlugin_ConstraintRigid::ID();
 }
index d1b5b4d5cd9f4646495b0613cb4319a67da3ec59..872102d8b6d9022e9beea3a9cada4c2105cf5de3 100644 (file)
 #include <gp_Pnt.hxx>
 
 #include <QPoint>
+#include <QList>
 
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
 
 #include <boost/shared_ptr.hpp>
 
-#include <list>
-
 class Handle_V3d_View;
 class ModuleBase_ViewerPrs;
 class GeomDataAPI_Point2D;
@@ -59,7 +58,7 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theSketch the sketch feature
   /// \param theFeatures the list of selected presentations
   static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
-                                   const std::list<ModuleBase_ViewerPrs>& theFeatures);
+                                   const QList<ModuleBase_ViewerPrs>& theFeatures);
 
   /// Returns pointer to the root document.
   static boost::shared_ptr<ModelAPI_Document> document();
@@ -97,7 +96,7 @@ class PARTSET_EXPORT PartSet_Tools
   /// Creates a constraint on two points
   /// \param thePoint1 the first point
   /// \param thePoint1 the second point
-  static void createConstraint(FeaturePtr theSketch,
+  static void createConstraint(CompositeFeaturePtr theSketch,
                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
 
@@ -107,21 +106,21 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theAttribute a name of the requried attribute attribute
   /// \param theClickedX the horizontal coordnate of the point
   /// \param theClickedY the vertical coordnate of the point
-  static void setConstraints(FeaturePtr theSketch, FeaturePtr theFeature,
+  static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
                              const std::string& theAttribute, double theClickedX,
                              double theClickedY);
 
   /// Create a sketch plane instance
   /// \param theSketch a sketch feature
   /// \return API object of geom plane
-  static boost::shared_ptr<GeomAPI_Pln> sketchPlane(FeaturePtr theSketch);
+  static boost::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
 
   /// Create a point 3D on a basis of point 2D and sketch feature
   /// \param thePoint2D a point on a sketch
   /// \param theSketch a sketch feature
   /// \return API object of point 3D
   static boost::shared_ptr<GeomAPI_Pnt> point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
-                                                FeaturePtr theSketch);
+                                                CompositeFeaturePtr theSketch);
   /// Check whether there is a constraint with the feature kind given
   /// \param theKind a feature kind
   /// \return the boolean value
index d464e85ab1534fec6c88e9e2434f31ecb3e1990c..7a976bda33749c371cf392ef0478f5217e0edfc6 100644 (file)
@@ -9,17 +9,15 @@
 #include <BRep_Tool.hxx>
 #include <GeomAdaptor_Curve.hxx>
 #include <GeomAbs_CurveType.hxx>
+#include <ModuleBase_ISelection.h>
 
 #include <list>
 
 int shapesNbPoints(const ModuleBase_ISelection* theSelection)
 {
-  std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
-  std::list<ModuleBase_ViewerPrs>::iterator it;
-  ModuleBase_ViewerPrs aPrs;
+  QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();  
   int aCount = 0;
-  for (it = aList.begin(); it != aList.end(); ++it) {
-    aPrs = *it;
+  foreach (ModuleBase_ViewerPrs aPrs, aList) {
     const TopoDS_Shape& aShape = aPrs.shape();
     if (!aShape.IsNull()) {
       if (aShape.ShapeType() == TopAbs_VERTEX)
@@ -31,12 +29,9 @@ int shapesNbPoints(const ModuleBase_ISelection* theSelection)
 
 int shapesNbLines(const ModuleBase_ISelection* theSelection)
 {
-  std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
-  std::list<ModuleBase_ViewerPrs>::iterator it;
-  ModuleBase_ViewerPrs aPrs;
+  QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
   int aCount = 0;
-  for (it = aList.begin(); it != aList.end(); ++it) {
-    aPrs = *it;
+  foreach(ModuleBase_ViewerPrs aPrs, aList) {
     const TopoDS_Shape& aShape = aPrs.shape();
     if (!aShape.IsNull()) {
       if (aShape.ShapeType() == TopAbs_EDGE) {
@@ -78,12 +73,10 @@ bool PartSet_ParallelValidator::isValid(const ModuleBase_ISelection* theSelectio
 
 bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) const
 {
-  std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
-  std::list<ModuleBase_ViewerPrs>::iterator it;
+  QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
   ModuleBase_ViewerPrs aPrs;
   int aCount = 0;
-  for (it = aList.begin(); it != aList.end(); ++it) {
-    aPrs = *it;
+  foreach (ModuleBase_ViewerPrs aPrs, aList) {
     const TopoDS_Shape& aShape = aPrs.shape();
     if (!aShape.IsNull()) {
       if (aShape.ShapeType() == TopAbs_EDGE) {
index bbcd7c177a1f5b8b154502fe6f73ee1c784cda6f..0c4d5ccf5e158772760f62ea28fe2f8197f0c8cd 100644 (file)
@@ -22,6 +22,7 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
   myLabel->setWordWrap(true);
   myTooltip = QString::fromStdString(theData->getProperty("tooltip"));
   myLabel->setToolTip(myTooltip);
+  myLabel->setIndent(5);
 }
 
 QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
index 53d339a23a71308ab48aa25a50330c5b19fb8743..d0985d40c5d7573a235bb9a03823ae65bdd2bda7 100644 (file)
@@ -25,5 +25,7 @@
      <file>icons/length.png</file>
      <file>icons/distance.png</file>
      <file>icons/radius_constr.png</file>
+     <file>icons/shape_group.png</file>
+     <file>icons/fixed.png</file>
  </qresource>
  </RCC>
diff --git a/src/PartSet/icons/fixed.png b/src/PartSet/icons/fixed.png
new file mode 100644 (file)
index 0000000..0a64532
Binary files /dev/null and b/src/PartSet/icons/fixed.png differ
diff --git a/src/PartSet/icons/shape_group.png b/src/PartSet/icons/shape_group.png
new file mode 100644 (file)
index 0000000..bb2ff51
Binary files /dev/null and b/src/PartSet/icons/shape_group.png differ
index a2f006fa42880133ca20e36835d2a5f534517cf3..8c6e8cc0ae117285373734155090805ffa58069d 100644 (file)
@@ -8,6 +8,7 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
 
 using namespace std;
 
index 937820becdad0902bb4be7f36908548dc20d68f7..9c5e6e62a93e4ef8cb0956dd2fe4ffbb2716d6a0 100644 (file)
@@ -25,6 +25,7 @@ void PartSetPlugin_Part::execute()
   if (!aResult) {
     aResult = document()->createPart(data());
     setResult(aResult);
+    aResult->activate();
   }
   /*
   boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = aResult->data()->docRef(
index 5494949d8337448b660da84d563b46943b42ff1a..d459d9753a76aa8e4bb3176279b186e2c7f3e4ac 100644 (file)
@@ -8,6 +8,7 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
 
 void PartSetPlugin_Remove::execute()
 {
index d9b7328c2ea0732ddc0ad08055fe11ea30961433..4d4097d12ecef3780d3fab78a8ab6c7b8355c1b6 100644 (file)
@@ -18,6 +18,7 @@ SET(PROJECT_HEADERS
     SketchPlugin_ConstraintParallel.h
     SketchPlugin_ConstraintPerpendicular.h
     SketchPlugin_ConstraintRadius.h
+    SketchPlugin_ConstraintRigid.h
     SketchPlugin_Validators.h
     SketchPlugin_ResultValidators.h 
 )
@@ -37,6 +38,7 @@ SET(PROJECT_SOURCES
     SketchPlugin_ConstraintParallel.cpp
     SketchPlugin_ConstraintPerpendicular.cpp
     SketchPlugin_ConstraintRadius.cpp
+    SketchPlugin_ConstraintRigid.cpp
     SketchPlugin_Validators.cpp
     SketchPlugin_ResultValidators.cpp
 )
index 21e616aef9b61b0e7fc846ede607cab03787eac6..ae0b225ecb25e93cf741d734f4555bffa62c44ee 100644 (file)
@@ -6,6 +6,9 @@
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
 
 #include <GeomAPI_Circ2d.h>
 #include <GeomAPI_Pnt2d.h>
@@ -24,9 +27,11 @@ SketchPlugin_Arc::SketchPlugin_Arc()
 
 void SketchPlugin_Arc::initAttributes()
 {
-  data()->addAttribute(SketchPlugin_Arc::CENTER_ID(), GeomDataAPI_Point2D::type());
-  data()->addAttribute(SketchPlugin_Arc::START_ID(), GeomDataAPI_Point2D::type());
-  data()->addAttribute(SketchPlugin_Arc::END_ID(), GeomDataAPI_Point2D::type());
+  data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::type());
+  data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type());
+  data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type());
+  data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
 }
 
 void SketchPlugin_Arc::execute()
@@ -138,3 +143,7 @@ double SketchPlugin_Arc::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>&
 
   return aDelta;
 }
+
+bool SketchPlugin_Arc::isFixed() {
+  return data()->selection(EXTERNAL_ID())->context();
+}
index 00ada99b0c1f797dd497c6834a99521af2bf460d..3ee2ba8e714c0bfa2a271d89fea9ae1eb104d114 100644 (file)
@@ -50,6 +50,9 @@ class SketchPlugin_Arc : public SketchPlugin_Feature  //, public GeomAPI_IPresen
     return MY_KIND;
   }
 
+  /// Returns true is sketch element is under the rigid constraint
+  SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
   /// Creates an arc-shape
   SKETCHPLUGIN_EXPORT virtual void execute();
 
index 635214f42fa39c3b70a7b92fcc0ce11aee90397e..e4d9d8e94411e5185246105a54ee92cf61a1a975 100644 (file)
@@ -6,6 +6,10 @@
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Session.h>
 
 #include <GeomAPI_Pnt2d.h>
 #include <GeomDataAPI_Point2D.h>
@@ -13,7 +17,6 @@
 #include <GeomAlgoAPI_PointBuilder.h>
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
-#include <ModelAPI_AttributeDouble.h>
 
 SketchPlugin_Circle::SketchPlugin_Circle()
     : SketchPlugin_Feature()
@@ -24,6 +27,8 @@ void SketchPlugin_Circle::initAttributes()
 {
   data()->addAttribute(SketchPlugin_Circle::CENTER_ID(), GeomDataAPI_Point2D::type());
   data()->addAttribute(SketchPlugin_Circle::RADIUS_ID(), ModelAPI_AttributeDouble::type());
+  data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
 }
 
 void SketchPlugin_Circle::execute()
@@ -98,3 +103,7 @@ double SketchPlugin_Circle::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2
 
   return aPoint->pnt()->distance(thePoint);
 }
+
+bool SketchPlugin_Circle::isFixed() {
+  return data()->selection(EXTERNAL_ID())->context();
+}
index c489f1014c45c8c6c5ad7320881a717240c6ba51..11311dcb0da8c230e74ce32ee5623e8797ea2841 100644 (file)
@@ -45,6 +45,9 @@ class SketchPlugin_Circle : public SketchPlugin_Feature  //, public GeomAPI_IPre
     return MY_KIND;
   }
 
+  /// Returns true is sketch element is under the rigid constraint
+  SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
   /// Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();
 
index 78c580426a95c0db16fc7b301f30e6b2e86e4859..d14a4b6de371cc9b0c2e8b19926611f04b748828 100644 (file)
@@ -14,7 +14,7 @@
  *  \ingroup DataModel
  *  \brief Feature for creation of a new constraint which defines equivalence of two points
  *
- *  These constraint has two attributes:
+ *  This constraint has two attributes:
  *  SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
  */
 class SketchPlugin_ConstraintCoincidence : public SketchPlugin_ConstraintBase
index 69ff19762c8b16f380234c60c0f83f3ccd1fa93d..4f4fedc627765bc8c1c770cf9ba519e72ae6f84f 100644 (file)
@@ -22,7 +22,7 @@ class GeomDataAPI_Point2D;
  *  \brief Feature for creation of a new constraint which defines a distance
  *         between a point and another feature (point, line, plane or face)
  *
- *  These constraint has three attributes:
+ *  This constraint has three attributes:
  *  SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
  */
 class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase
index 456c0c27c15efc694225e514a52dfbfc79bd3b9c..5f3ae9aae121173e9897dbf8268c5bd2f178c845 100644 (file)
@@ -16,7 +16,7 @@
  *  \ingroup DataModel
  *  \brief Feature for creation of a new constraint which defines a length of a line segment
  *
- *  These constraint has two attributes:
+ *  This constraint has two attributes:
  *  SketchPlugin_Constraint::VALUE() (length) and SketchPlugin_Constraint::ENTITY_A() (segment),
  *  SketchPlugin_Constraint::FLYOUT_VALUE_PNT() (distance of a constraints handle)
  */
index 053fe5f36568d74d52bb78178e255de5b02f1a97..370ff6336997667535bae337433045080bb0af13 100644 (file)
@@ -15,7 +15,7 @@
  *  \ingroup DataModel
  *  \brief Feature for creation of a new constraint parallelism of two lines
  *
- *  These constraint has two attributes:
+ *  This constraint has two attributes:
  *  SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
  */
 class SketchPlugin_ConstraintParallel : public SketchPlugin_ConstraintBase
index 9b304c8d4ab813c75ac39122f92eb34e6db51402..7847bf4d64856fa284cab7d2b6faa48194476154 100644 (file)
@@ -15,7 +15,7 @@
  *  \ingroup DataModel
  *  \brief Feature for creation of a new constraint for perpendicularity of two lines
  *
- *  These constraint has two attributes:
+ *  This constraint has two attributes:
  *  SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
  */
 class SketchPlugin_ConstraintPerpendicular : public SketchPlugin_ConstraintBase
index eb96ef93d3eb485cb9f890f482e730c2eb9ee7d9..96e295e1b50f0227b3e4764061ff29d8fc441d29 100644 (file)
@@ -16,7 +16,7 @@
  *  \brief Feature for creation of a new constraint which defines 
  *         a radius of a circle or an arc of circle
  *
- *  These constraint has two attributes:
+ *  This constraint has two attributes:
  *  SketchPlugin_Constraint::VALUE() (radius), SketchPlugin_Constraint::ENTITY_A() (a circle)
  */
 class SketchPlugin_ConstraintRadius : public SketchPlugin_ConstraintBase
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp
new file mode 100644 (file)
index 0000000..c976332
--- /dev/null
@@ -0,0 +1,54 @@
+// File:    SketchPlugin_ConstraintRigid.cpp
+// Created: 13 Oct 2014
+// Author:  Artem ZHIDKOV
+
+#include "SketchPlugin_ConstraintRigid.h"
+
+#include <ModelAPI_ResultConstruction.h>
+
+SketchPlugin_ConstraintRigid::SketchPlugin_ConstraintRigid()
+{
+}
+
+void SketchPlugin_ConstraintRigid::initAttributes()
+{
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
+}
+
+void SketchPlugin_ConstraintRigid::execute()
+{
+}
+
+AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious)
+{
+  if (!sketch())
+    return thePrevious;
+
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = boost::dynamic_pointer_cast<
+      ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
+  if (!anAttr || !anAttr->isObject())
+    return thePrevious;
+
+  boost::shared_ptr<ModelAPI_ResultConstruction> aConst = 
+    boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
+  if (!aConst) 
+    return thePrevious;
+
+  boost::shared_ptr<GeomAPI_Shape> aShape;
+  aShape = aConst->shape();
+
+  AISObjectPtr anAIS = thePrevious;
+  if (!anAIS)
+    anAIS = AISObjectPtr(new GeomAPI_AISObject);
+
+  boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
+  anAIS->createFixed(aShape, aPlane);
+
+  // Set color from preferences
+  //std::vector<int> aRGB = Config_PropManager::color("Visualization", "perpendicular_color",
+  //                                                  PERPENDICULAR_COLOR);
+  //anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
+
+  return anAIS;
+}
\ No newline at end of file
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRigid.h b/src/SketchPlugin/SketchPlugin_ConstraintRigid.h
new file mode 100644 (file)
index 0000000..8816ea4
--- /dev/null
@@ -0,0 +1,49 @@
+// File:    SketchPlugin_ConstraintRigid.h
+// Created: 13 Oct 2014
+// Author:  Artem ZHIDKOV
+
+#ifndef SketchPlugin_ConstraintRigid_H_
+#define SketchPlugin_ConstraintRigid_H_
+
+#include "SketchPlugin.h"
+#include "SketchPlugin_ConstraintBase.h"
+#include <SketchPlugin_Sketch.h>
+#include <list>
+
+/** \class SketchPlugin_ConstraintRigid
+ *  \ingroup DataModel
+ *  \brief Feature for creation of a new constraint which defines immovable object
+ *
+ *  This constraint has one attribute:
+ *  SketchPlugin_Constraint::ENTITY_A() (any object, i.e. point, line, circle, arc)
+ */
+class SketchPlugin_ConstraintRigid : public SketchPlugin_ConstraintBase
+{
+ public:
+  /// Length constraint kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_CONSTRAINT_RIGID_ID("SketchConstraintRigid");
+    return MY_CONSTRAINT_RIGID_ID;
+  }
+  /// \brief Returns the kind of a feature
+  SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = SketchPlugin_ConstraintRigid::ID();
+    return MY_KIND;
+  }
+
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
+  /// \brief Creates a new part document if needed
+  SKETCHPLUGIN_EXPORT virtual void execute();
+
+  /// \brief Request for initialization of data model of the feature: adding all attributes
+  SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+  /// \brief Use plugin manager for features creation
+  SketchPlugin_ConstraintRigid();
+};
+
+#endif
index c3c800bd992ca865bfe4ec7ba0637964c8ac6cfb..da25c09994581e44f9153dc447b05979ad525c63 100644 (file)
@@ -11,14 +11,16 @@ SketchPlugin_Feature::SketchPlugin_Feature()
   mySketch = 0;
 }
 
+/*
 SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
 {
   if (!mySketch) {
     // find sketch that references to this feature
     int aSketches = document()->size(ModelAPI_Feature::group());
     for (int a = 0; a < aSketches && !mySketch; a++) {
-      boost::shared_ptr<SketchPlugin_Sketch> aSketch = boost::dynamic_pointer_cast<
-          SketchPlugin_Sketch>(document()->object(ModelAPI_Feature::group(), a));
+      ObjectPtr anObj = document()->object(ModelAPI_Feature::group(), a);
+      boost::shared_ptr<SketchPlugin_Sketch> aSketch = 
+        boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj);
       if (aSketch) {
         std::list<ObjectPtr> aList = aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())
             ->list();
@@ -33,7 +35,7 @@ SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
     }
   }
   return mySketch;
-}
+}*/
 
 AISObjectPtr SketchPlugin_Feature::simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
                                                    AISObjectPtr thePrevious)
index d51301880a14e01c6c9d345275f577a13dbbd88e..97a2d423bd605102a579461c1774ac305baff60e 100644 (file)
@@ -6,7 +6,7 @@
 #define SketchPlugin_Feature_H_
 
 #include "SketchPlugin.h"
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_AISObject.h>
 #include <ModelAPI_Document.h>
@@ -27,12 +27,12 @@ class SketchPlugin_Feature : public ModelAPI_Feature
   static AISObjectPtr simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
                                       AISObjectPtr thePrevious);
 
-  /// Adds sub-feature of the higher level feature (sub-element of the sketch)
-  /// \param theFeature sub-feature
-  SKETCHPLUGIN_EXPORT virtual const void addSub(const FeaturePtr& theFeature)
+  /// Reference to the external edge or vertex as a AttributeSelection
+  inline static const std::string& EXTERNAL_ID()
   {
+    static const std::string MY_EXTERNAL_ID("External");
+    return MY_EXTERNAL_ID;
   }
-  ;
 
   /// Returns true if this feature must be displayed in the history (top level of Part tree)
   SKETCHPLUGIN_EXPORT virtual bool isInHistory()
@@ -52,14 +52,17 @@ class SketchPlugin_Feature : public ModelAPI_Feature
   /// Construction result is allways recomuted on the fly
   SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
 
+  /// Returns true is sketch element is under the rigid constraint
+  SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
+
+  /// Returns the sketch of this feature
+  inline SketchPlugin_Sketch* sketch() {return mySketch;}
 protected:
   /// Sets the higher-level feature for the sub-feature (sketch for line)
   void setSketch(SketchPlugin_Sketch* theSketch)
   {
     mySketch = theSketch;
   }
-  /// Returns the sketch of this feature
-  SketchPlugin_Sketch* sketch();
   /// initializes mySketch
   SketchPlugin_Feature();
 
index 8ae5384bb42cbf8bf057472fe2e64534a6502ce1..ccefb4bec3aba9a144313b2a8842b55e11629a54 100644 (file)
@@ -6,6 +6,9 @@
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
 
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Lin2d.h>
@@ -25,6 +28,8 @@ void SketchPlugin_Line::initAttributes()
 {
   data()->addAttribute(SketchPlugin_Line::START_ID(), GeomDataAPI_Point2D::type());
   data()->addAttribute(SketchPlugin_Line::END_ID(), GeomDataAPI_Point2D::type());
+  data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
 }
 
 void SketchPlugin_Line::execute()
@@ -88,3 +93,7 @@ double SketchPlugin_Line::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>
 
   return aDelta;
 }
+
+bool SketchPlugin_Line::isFixed() {
+  return data()->selection(EXTERNAL_ID())->context();
+}
index d2656e5d83ec89dfaa0360aa6a2b618947a3b8c7..d24f1af52701f79fe25d0ee6b9f6136fcd033f92 100644 (file)
@@ -43,6 +43,9 @@ class SketchPlugin_Line : public SketchPlugin_Feature
     return MY_KIND;
   }
 
+  /// Returns true is sketch element is under the rigid constraint
+  SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
   /// Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();
 
index ba178fe6526935a58b93fa4a102ff5afdc7e398e..cf3cf283b9e6780efd3f882697d3a9c4182b00ef 100644 (file)
@@ -10,6 +10,7 @@
 #include "SketchPlugin_ConstraintParallel.h"
 #include "SketchPlugin_ConstraintPerpendicular.h"
 #include "SketchPlugin_ConstraintRadius.h"
+#include "SketchPlugin_ConstraintRigid.h"
 #include "SketchPlugin_Validators.h"
 #include "SketchPlugin_ResultValidators.h"
 #include <ModelAPI_Session.h>
@@ -28,7 +29,7 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
   SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   aFactory->registerValidator("SketchPlugin_DistanceAttr",
-                              new SketchPlugin_DistanceAttrValidator);
+                              new SketchPlugin_DistanceAttrValidator);  
   aFactory->registerValidator("SketchPlugin_DifferentObjects",
                               new SketchPlugin_DifferentObjectsValidator);
   aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator);
@@ -43,7 +44,7 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
                                    SKETCH_PLANE_COLOR);
   Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
                                    PLANE_SIZE);
-  Config_PropManager::registerProp("Sketch planes", "planes_thikness", "Thickness",
+  Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
                                    Config_Prop::Integer, SKETCH_WIDTH);
 
   Config_PropManager::registerProp("Visualization", "parallel_color", "Parallel constraint color",
@@ -83,6 +84,8 @@ FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID)
     return FeaturePtr(new SketchPlugin_ConstraintPerpendicular);
   } else if (theFeatureID == SketchPlugin_ConstraintRadius::ID()) {
     return FeaturePtr(new SketchPlugin_ConstraintRadius);
+  } else if (theFeatureID == SketchPlugin_ConstraintRigid::ID()) {
+    return FeaturePtr(new SketchPlugin_ConstraintRigid);
   }
   // feature of such kind is not found
   return FeaturePtr();
index 5e8f2a65ebd45761393ef070c5b0e8d4ef9c9410..1ad78684f8ab806ea8676054956b1083aac3aa47 100644 (file)
@@ -7,6 +7,9 @@
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
 
 #include <GeomAPI_Pnt2d.h>
 
@@ -22,6 +25,8 @@ SketchPlugin_Point::SketchPlugin_Point()
 void SketchPlugin_Point::initAttributes()
 {
   data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::type());
+  data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
 }
 
 void SketchPlugin_Point::execute()
@@ -61,3 +66,7 @@ double SketchPlugin_Point::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d
 
   return aPoint->pnt()->distance(thePoint);
 }
+
+bool SketchPlugin_Point::isFixed() {
+  return data()->selection(EXTERNAL_ID())->context();
+}
index 14f58740248eed1215cf5c980e688d4fa48483d8..48415b18ccf83a6b3592aa9c226b6b83c6f8dcb9 100644 (file)
@@ -36,6 +36,9 @@ class SketchPlugin_Point : public SketchPlugin_Feature
     return MY_KIND;
   }
 
+  /// Returns true is sketch element is under the rigid constraint
+  SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
   /// Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();
 
index 1bc1b469cce3187af65006bbb02a5aa1cbbf868e..5429b2b605668573097dbc9bd76ff09713971433 100644 (file)
@@ -2,19 +2,31 @@
 // Created:     27 Mar 2014
 // Author:      Mikhail PONIKAROV
 
-#include "SketchPlugin_Sketch.h"
-#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeRefList.h>
+#include <Config_PropManager.h>
+
+#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
+
 #include <GeomAPI_AISObject.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_PlanarEdges.h>
 #include <GeomAPI_XYZ.h>
+
 #include <GeomDataAPI_Dir.h>
 #include <GeomDataAPI_Point.h>
-#include <GeomAlgoAPI_FaceBuilder.h>
-#include <GeomAlgoAPI_CompoundBuilder.h>
-#include <GeomAlgoAPI_SketchBuilder.h>
+
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
 #include <ModelAPI_ResultConstruction.h>
 
-#include <Config_PropManager.h>
+#include <SketchPlugin_Sketch.h>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <vector>
 
 using namespace std;
 
@@ -74,22 +86,68 @@ void SketchPlugin_Sketch::execute()
 
   if (aFeaturesPreview.empty())
     return;
-  std::list<boost::shared_ptr<GeomAPI_Shape> > aLoops;
-  std::list<boost::shared_ptr<GeomAPI_Shape> > aWires;
-  GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(),
-                                         aFeaturesPreview, aLoops, aWires);
 
-  aLoops.insert(aLoops.end(), aWires.begin(), aWires.end());
-  boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aLoops);
+  // Collect all edges as one big wire
+  boost::shared_ptr<GeomAPI_PlanarEdges> aBigWire(new GeomAPI_PlanarEdges);
+  std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator aShapeIt = aFeaturesPreview.begin();
+  for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) {
+    aBigWire->addEdge(*aShapeIt);
+  }
+  aBigWire->setOrigin(anOrigin->pnt());
+  aBigWire->setDirX(aDirX->dir());
+  aBigWire->setDirY(aDirY->dir());
+  aBigWire->setNorm(aNorm->dir());
+
+//  GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(),
+//                                         aFeaturesPreview, aLoops, aWires);
   boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
-  aConstr->setShape(aCompound);
+  aConstr->setShape(aBigWire);
   setResult(aConstr);
 }
 
-const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature)
+boost::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::addFeature(std::string theID)
+{
+  boost::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID);
+  if (aNew) {
+    boost::dynamic_pointer_cast<SketchPlugin_Feature>(aNew)->setSketch(this);
+    data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(aNew);
+  }
+  return aNew;
+}
+
+int SketchPlugin_Sketch::numberOfSubs() const
 {
-  boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature)->setSketch(this);
-  data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(theFeature);
+  return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->size();
+}
+
+boost::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::subFeature(const int theIndex) const
+{
+  ObjectPtr anObj = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->object(theIndex);
+  return boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+}
+
+int SketchPlugin_Sketch::subFeatureId(const int theIndex) const
+{
+  return subFeature(theIndex)->data()->featureId();
+}
+
+bool SketchPlugin_Sketch::isSub(ObjectPtr theObject) const
+{
+  // check is this feature of result
+  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+  if (!aFeature) {
+    ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+    if (aRes)
+      aFeature = document()->feature(aRes);
+  }
+  if (aFeature) {
+    list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
+    for(list<ObjectPtr>::iterator aSubIt = aSubs.begin(); aSubIt != aSubs.end(); aSubIt++) {
+      if (*aSubIt == aFeature)
+        return true;
+    }
+  }
+  return false;
 }
 
 boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
@@ -160,7 +218,7 @@ AISObjectPtr SketchPlugin_Sketch::getAISObject(AISObjectPtr thePrevious)
       SKETCH_PLANE_COLOR);
       aAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
 
-      aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thikness",
+      aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness",
       SKETCH_WIDTH));
     }
     return aAIS;
@@ -181,5 +239,5 @@ void SketchPlugin_Sketch::erase()
       document()->removeFeature(aFeature, false);
     }
   }
-  SketchPlugin_Feature::erase();
+  ModelAPI_CompositeFeature::erase();
 }
index 07f8ae269ec8e34eee0af6f9a4559b15e9c61d7d..23147d97f612f11077809ff5b8b773ad7d7f2690 100644 (file)
@@ -25,7 +25,7 @@
  * \ingroup DataModel
  * \brief Feature for creation of the new part in PartSet.
  */
-class SketchPlugin_Sketch : public SketchPlugin_Feature, public GeomAPI_IPresentable
+class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_IPresentable
 {
  public:
   /// Sketch feature kind
@@ -78,10 +78,6 @@ class SketchPlugin_Sketch : public SketchPlugin_Feature, public GeomAPI_IPresent
   /// Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
-  /// Adds sub-feature of the higher level feature (sub-element of the sketch)
-  /// \param theFeature sub-feature
-  SKETCHPLUGIN_EXPORT virtual const void addSub(const FeaturePtr& theFeature);
-
   /// Moves the feature
   /// \param theDeltaX the delta for X coordinate is moved
   /// \param theDeltaY the delta for Y coordinate is moved
@@ -118,7 +114,25 @@ class SketchPlugin_Sketch : public SketchPlugin_Feature, public GeomAPI_IPresent
   /// removes also all sub-sketch elements
   SKETCHPLUGIN_EXPORT virtual void erase();
 
- protected:
+  SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
+
+  /// Returns the number of sub-elements
+  SKETCHPLUGIN_EXPORT virtual int numberOfSubs() const;
+
+  /// Returns the sub-feature by zero-base index
+  SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> 
+    subFeature(const int theIndex) const;
+
+  /// Returns the sub-feature unique identifier in this composite feature by zero-base index
+  SKETCHPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;
+
+  /// Returns true if feature or reuslt belong to this composite feature as subs
+  SKETCHPLUGIN_EXPORT virtual bool isSub(ObjectPtr theObject) const;
+
+  /// Construction result is allways recomuted on the fly
+  SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+
+protected:
   /// Creates a plane and append it to the list
   /// \param theX the X normal value
   /// \param theY the Y normal value
index 555f0abfeb50e3e2c0b05225e91e83e658fa2b93..b71d5adbd69b29d7baf6f03b3c0e9e924ebe2fc9 100644 (file)
@@ -9,6 +9,7 @@
 #include <ModelAPI_ResultValidator.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_Session.h>
 #include <GeomDataAPI_Point2D.h>
 
 bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
index da616ce62143c5b0bba43d69ce88657b0b1d66e7..dedb420a5d7d41bc0b34474d21a33d4e16c1381f 100644 (file)
@@ -22,7 +22,7 @@ from ModelAPI import *
 # Initialization of the test
 #=========================================================================
 
-__updated__ = "2014-07-28"
+__updated__ = "2014-10-28"
 
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
@@ -31,37 +31,34 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
 dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
 diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
 aSession.finishOperation()
 #=========================================================================
 # Create a line and an arc
 #=========================================================================
 aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
 aSketchArc = aDocument.addFeature("SketchArc")
 aSketchReflist.append(aSketchArc)
-aSketchArcData = aSketchArc.data()
-anArcCentr = geomDataAPI_Point2D(aSketchArcData.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
 anArcStartPoint = geomDataAPI_Point2D(
-    aSketchArcData.attribute("ArcStartPoint"))
-anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint"))
+    aSketchArc.attribute("ArcStartPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
 aSketchFeature = aDocument.addFeature("SketchConstraintCoincidence")
 anArcCentr.setValue(10., 10.)
 anArcStartPoint.setValue(0., 50.)
 anArcEndPoint.setValue(50., 0.)
 aSketchLine = aDocument.addFeature("SketchLine")
 aSketchReflist.append(aSketchLine)
-aSketchLineData = aSketchLine.data()
-aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
-aLineEndPoint = geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
 # Lets initialize line start at circle's end:
 aLineStartPoint.setValue(50., 0.)
 aLineEndPoint.setValue(100., 25.)
@@ -72,9 +69,8 @@ aSession.finishOperation()
 aSession.startOperation()
 aConstraint = aDocument.addFeature("SketchConstraintCoincidence")
 aSketchReflist.append(aConstraint)
-aConstraintData = aConstraint.data()
-reflistA = aConstraintData.refattr("ConstraintEntityA")
-reflistB = aConstraintData.refattr("ConstraintEntityB")
+reflistA = aConstraint.refattr("ConstraintEntityA")
+reflistB = aConstraint.refattr("ConstraintEntityB")
 reflistA.setAttr(anArcEndPoint)
 reflistB.setAttr(aLineStartPoint)
 aSession.finishOperation()
index 2d84321be0cf622a7f9d2b150233ed27e99138de..4c50263b2e1baf1ee85da7b24d4deffc29d85aee 100644 (file)
@@ -26,7 +26,7 @@ import math
 # Initialization of the test
 #=========================================================================
 
-__updated__ = "2014-07-29"
+__updated__ = "2014-10-28"
 
 
 def distance(pointA, pointB):
@@ -44,33 +44,28 @@ aDocument = aSession.moduleDocument()
 # Creation of a sketch
 #=========================================================================
 aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
 dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
 diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
 aSession.finishOperation()
 #=========================================================================
 # Create a point and a line
 #=========================================================================
 aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
-aSketchPoint = aDocument.addFeature("SketchPoint")
-aSketchReflist.append(aSketchPoint)
-aSketchPointData = aSketchPoint.data()
+aSketchPoint = aSketchFeature.addFeature("SketchPoint")
 aSketchPointCoords = geomDataAPI_Point2D(
-    aSketchPointData.attribute("PointCoordindates"))
+    aSketchPoint.attribute("PointCoordindates"))
 aSketchPointCoords.setValue(50., 50.)
-aSketchLine = aDocument.addFeature("SketchLine")
-aSketchReflist.append(aSketchLine)
-aLineAStartPoint = geomDataAPI_Point2D(
-    aSketchLine.data().attribute("StartPoint"))
-aLineAEndPoint = geomDataAPI_Point2D(aSketchLine.data().attribute("EndPoint"))
+aSketchLine = aSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
 aLineAStartPoint.setValue(0., 25.)
 aLineAEndPoint.setValue(100., 25.)
 aSession.finishOperation()
@@ -79,12 +74,10 @@ aSession.finishOperation()
 #=========================================================================
 assert (distance(aSketchPointCoords, aLineAStartPoint) != 25.)
 aSession.startOperation()
-aConstraint = aDocument.addFeature("SketchConstraintDistance")
-aSketchReflist.append(aConstraint)
-aConstraintData = aConstraint.data()
-aDistance = aConstraintData.real("ConstraintValue")
-refattrA = aConstraintData.refattr("ConstraintEntityA")
-refattrB = aConstraintData.refattr("ConstraintEntityB")
+aConstraint = aSketchFeature.addFeature("SketchConstraintDistance")
+aDistance = aConstraint.real("ConstraintValue")
+refattrA = aConstraint.refattr("ConstraintEntityA")
+refattrB = aConstraint.refattr("ConstraintEntityB")
 assert (not aDistance.isInitialized())
 assert (not refattrA.isInitialized())
 assert (not refattrB.isInitialized())
index 28f032e4ad309da415c1e6b4fd1ed1e5e25530cc..48acf2c6b612bc12b12749f1bd089b5c8025f7ca 100644 (file)
@@ -15,7 +15,7 @@ from ModelAPI import *
 # Initialization of the test
 #=========================================================================
 
-__updated__ = "2014-09-26"
+__updated__ = "2014-10-28"
 
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
@@ -23,27 +23,24 @@ aDocument = aSession.moduleDocument()
 # Creation of a sketch
 #=========================================================================
 aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
 dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
 diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
 aSession.finishOperation()
 #=========================================================================
 # Create a line with length 100
 #=========================================================================
 aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
-aSketchLineA = aDocument.addFeature("SketchLine")
-aSketchReflist.append(aSketchLineA)
-aLineAStartPoint = geomDataAPI_Point2D(
-    aSketchLineA.data().attribute("StartPoint"))
-aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.data().attribute("EndPoint"))
+aSketchLineA = aSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
 aLineAStartPoint.setValue(0., 25.)
 aLineAEndPoint.setValue(100., 25.)
 aSession.finishOperation()
@@ -51,11 +48,9 @@ aSession.finishOperation()
 # Make a constraint to keep the length
 #=========================================================================
 aSession.startOperation()
-aLengthConstraint = aDocument.addFeature("SketchConstraintLength")
-aSketchReflist.append(aLengthConstraint)
-aConstraintData = aLengthConstraint.data()
-refattrA = aConstraintData.refattr("ConstraintEntityA")
-aLength = aConstraintData.real("ConstraintValue")
+aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength")
+refattrA = aLengthConstraint.refattr("ConstraintEntityA")
+aLength = aLengthConstraint.real("ConstraintValue")
 assert (not refattrA.isInitialized())
 assert (not aLength.isInitialized())
 
index aa244cee7ab3d08a016b464dbf6cf6a4068d130d..18fbc6832dfbec36bc441442cdab8e6ff41163d4 100644 (file)
@@ -15,7 +15,7 @@ from ModelAPI import *
 # Initialization of the test
 #=========================================================================
 
-__updated__ = "2014-09-26"
+__updated__ = "2014-10-28"
 
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
@@ -23,38 +23,31 @@ aDocument = aSession.moduleDocument()
 # Creation of a sketch
 #=========================================================================
 aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
 dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
 diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
 aSession.finishOperation()
 #=========================================================================
 # Create two lines which are not parallel
 #=========================================================================
 aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
 # line A
-aSketchLineA = aDocument.addFeature("SketchLine")
-aSketchReflist.append(aSketchLineA)
-aLineAStartPoint = geomDataAPI_Point2D(
-    aSketchLineA.data().attribute("StartPoint"))
-aLineAEndPoint = geomDataAPI_Point2D(
-    aSketchLineA.data().attribute("EndPoint"))
-aSketchLineB = aDocument.addFeature("SketchLine")
+aSketchLineA = aSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
+aSketchLineB = aSketchFeature.addFeature("SketchLine")
 aLineAStartPoint.setValue(0., 25)
 aLineAEndPoint.setValue(85., 25)
 # line B
-aSketchReflist.append(aSketchLineB)
-aLineBStartPoint = geomDataAPI_Point2D(
-    aSketchLineB.data().attribute("StartPoint"))
-aLineBEndPoint = geomDataAPI_Point2D(
-    aSketchLineB.data().attribute("EndPoint"))
+aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
+aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
 aLineBStartPoint.setValue(0., 50)
 aLineBEndPoint.setValue(80., 75)
 aSession.finishOperation()
@@ -64,10 +57,8 @@ aSession.finishOperation()
 #=========================================================================
 for eachFeature in [aSketchLineA, aSketchLineB]:
     aSession.startOperation()
-    aLengthConstraint = aDocument.addFeature("SketchConstraintLength")
-    aSketchReflist.append(aLengthConstraint)
-    aLengthConstraintData = aLengthConstraint.data()
-    refattrA = aLengthConstraintData.refattr("ConstraintEntityA")
+    aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength")
+    refattrA = aLengthConstraint.refattr("ConstraintEntityA")
     aResultA = modelAPI_ResultConstruction(eachFeature.firstResult())
     assert (aResultA is not None)
     refattrA.setObject(aResultA)
@@ -86,11 +77,9 @@ assert (aLineBEndPoint.y() == 75)
 # Link lines with parallel constraint
 #=========================================================================
 aSession.startOperation()
-aParallelConstraint = aDocument.addFeature("SketchConstraintParallel")
-aSketchReflist.append(aParallelConstraint)
-aConstraintData = aParallelConstraint.data()
-refattrA = aConstraintData.refattr("ConstraintEntityA")
-refattrB = aConstraintData.refattr("ConstraintEntityB")
+aParallelConstraint = aSketchFeature.addFeature("SketchConstraintParallel")
+refattrA = aParallelConstraint.refattr("ConstraintEntityA")
+refattrB = aParallelConstraint.refattr("ConstraintEntityB")
 # aResultA is already defined for the length constraint
 aResultA = modelAPI_ResultConstruction(eachFeature.firstResult())
 aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult())
index 192f1d9ac12078f44d72a074f72b79d1157d54af..38b605f233f80cc82a0f393cd11cc87d36d26981 100644 (file)
@@ -22,7 +22,7 @@ from ModelAPI import *
 # Initialization of the test
 #=========================================================================
 
-__updated__ = "2014-09-26"
+__updated__ = "2014-10-28"
 
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
@@ -30,38 +30,31 @@ aDocument = aSession.moduleDocument()
 # Creation of a sketch
 #=========================================================================
 aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
 dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
 diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
 aSession.finishOperation()
 #=========================================================================
 # Create two lines which are already perpendicular
 #=========================================================================
 aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
 # line A
-aSketchLineA = aDocument.addFeature("SketchLine")
-aSketchReflist.append(aSketchLineA)
-aLineAStartPoint = geomDataAPI_Point2D(
-    aSketchLineA.data().attribute("StartPoint"))
-aLineAEndPoint = geomDataAPI_Point2D(
-    aSketchLineA.data().attribute("EndPoint"))
-aSketchLineB = aDocument.addFeature("SketchLine")
+aSketchLineA = aSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
+# line B
+aSketchLineB = aSketchFeature.addFeature("SketchLine")
 aLineAStartPoint.setValue(0., 25)
 aLineAEndPoint.setValue(85., 25)
-# line B
-aSketchReflist.append(aSketchLineB)
-aLineBStartPoint = geomDataAPI_Point2D(
-    aSketchLineB.data().attribute("StartPoint"))
-aLineBEndPoint = geomDataAPI_Point2D(
-    aSketchLineB.data().attribute("EndPoint"))
+aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
+aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
 aLineBStartPoint.setValue(25., 40.)
 aLineBEndPoint.setValue(25., 125.)
 aSession.finishOperation()
@@ -72,10 +65,8 @@ aSession.finishOperation()
 
 for eachFeature in [aSketchLineA, aSketchLineB]:
     aSession.startOperation()
-    aLengthConstraint = aDocument.addFeature("SketchConstraintLength")
-    aSketchReflist.append(aLengthConstraint)
-    aLengthConstraintData = aLengthConstraint.data()
-    refattrA = aLengthConstraintData.refattr("ConstraintEntityA")
+    aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength")
+    refattrA = aLengthConstraint.refattr("ConstraintEntityA")
     aResultA = modelAPI_ResultConstruction(eachFeature.firstResult())
     assert (aResultA is not None)
     refattrA.setObject(aResultA)
@@ -95,12 +86,10 @@ assert (aLineBEndPoint.y() == 125)
 # Link lines with perpendicular constraint
 #=========================================================================
 aSession.startOperation()
-aPerpendicularConstraint = aDocument.addFeature(
+aPerpendicularConstraint = aSketchFeature.addFeature(
     "SketchConstraintPerpendicular")
-aSketchReflist.append(aPerpendicularConstraint)
-aConstraintData = aPerpendicularConstraint.data()
-refattrA = aConstraintData.refattr("ConstraintEntityA")
-refattrB = aConstraintData.refattr("ConstraintEntityB")
+refattrA = aPerpendicularConstraint.refattr("ConstraintEntityA")
+refattrB = aPerpendicularConstraint.refattr("ConstraintEntityB")
 # aResultA is already defined for the length constraint
 aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult())
 assert (aResultB is not None)
index 630beb124a11f53709ffe9de1d9837628666e389..afe60ba4f4971bb09d57c0ea3e9d08f63e28533e 100644 (file)
@@ -24,7 +24,7 @@ import math
 # Initialization of the test
 #=========================================================================
 
-__updated__ = "2014-09-26"
+__updated__ = "2014-10-28"
 
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
@@ -32,41 +32,34 @@ aDocument = aSession.moduleDocument()
 # Creation of a sketch
 #=========================================================================
 aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
 dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
 diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
 aSession.finishOperation()
 #=========================================================================
 # Creation of an arc and a circle
 #=========================================================================
 aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
-aSketchArc = aDocument.addFeature("SketchArc")
-aSketchReflist.append(aSketchArc)
-aSketchArcData = aSketchArc.data()
-anArcCentr = geomDataAPI_Point2D(aSketchArcData.attribute("ArcCenter"))
+aSketchArc = aSketchFeature.addFeature("SketchArc")
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
 anArcCentr.setValue(10., 10.)
-anArcStartPoint = geomDataAPI_Point2D(
-    aSketchArcData.attribute("ArcStartPoint"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
 anArcStartPoint.setValue(0., 50.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
 anArcEndPoint.setValue(50., 0.)
 aSession.finishOperation()
 # Circle
 aSession.startOperation()
-aSketchCircle = aDocument.addFeature("SketchCircle")
-aSketchReflist.append(aSketchCircle)
-aSketchCircleData = aSketchCircle.data()
-anCircleCentr = geomDataAPI_Point2D(
-    aSketchCircleData.attribute("CircleCenter"))
-aCircleRadius = aSketchCircleData.real("CircleRadius")
+aSketchCircle = aSketchFeature.addFeature("SketchCircle")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
+aCircleRadius = aSketchCircle.real("CircleRadius")
 anCircleCentr.setValue(-25., -25)
 aCircleRadius.setValue(25.)
 aSession.finishOperation()
@@ -74,11 +67,9 @@ aSession.finishOperation()
 # Make a constraint to keep the radius of the arc
 #=========================================================================
 aSession.startOperation()
-aConstraint = aDocument.addFeature("SketchConstraintRadius")
-aSketchReflist.append(aConstraint)
-aConstraintData = aConstraint.data()
-aRadius = aConstraintData.real("ConstraintValue")
-aRefObject = aConstraintData.refattr("ConstraintEntityA")
+aConstraint = aSketchFeature.addFeature("SketchConstraintRadius")
+aRadius = aConstraint.real("ConstraintValue")
+aRefObject = aConstraint.refattr("ConstraintEntityA")
 aResult = aSketchArc.firstResult()
 assert (aResult is not None)
 aRefObject.setObject(modelAPI_ResultConstruction(aResult))
@@ -90,11 +81,9 @@ assert (aRefObject.isInitialized())
 # Make a constraint to keep the radius of the circle
 #=========================================================================
 aSession.startOperation()
-aConstraint = aDocument.addFeature("SketchConstraintRadius")
-aSketchReflist.append(aConstraint)
-aConstraintData = aConstraint.data()
-aRadius = aConstraintData.real("ConstraintValue")
-aRefObject = aConstraintData.refattr("ConstraintEntityA")
+aConstraint = aSketchFeature.addFeature("SketchConstraintRadius")
+aRadius = aConstraint.real("ConstraintValue")
+aRefObject = aConstraint.refattr("ConstraintEntityA")
 aResult = aSketchCircle.firstResult()
 assert (aResult is not None)
 aRefObject.setObject(modelAPI_ResultConstruction(aResult))
index 4223d5c35d104583365f346c354538e8d3a2a320..8ce7a3186b3bef32c439dceab06b871ab1098e45 100644 (file)
@@ -22,7 +22,7 @@
 from GeomDataAPI import *
 from ModelAPI import *
 
-__updated__ = "2014-07-25"
+__updated__ = "2014-10-28"
 
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
@@ -30,49 +30,49 @@ aDocument = aSession.moduleDocument()
 # Creation of a sketch
 #=========================================================================
 aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+#aSketchFeature = aDocument.addFeature("Sketch")
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
 dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
 diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
 aSession.finishOperation()
 #=========================================================================
 # Creation of an arc
 # 1. Test SketchPlugin_Arc attributes
-# 2. 
+# 2.
 #=========================================================================
 aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
 assert (not aSketchReflist.isInitialized())
 assert (aSketchReflist.size() == 0)
 assert (len(aSketchReflist.list()) == 0)
-aSketchArc = aDocument.addFeature("SketchArc")
+aSketchArc = aSketchFeature.addFeature("SketchArc")
 assert (aSketchArc.getKind() == "SketchArc")
-aSketchReflist.append(aSketchArc)
-aSketchArcData = aSketchArc.data()
-anArcCentr = geomDataAPI_Point2D(aSketchArcData.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
 assert (anArcCentr.x() == 0)
 assert (anArcCentr.y() == 0)
 assert (not anArcCentr.isInitialized())
-anArcCentr.setValue(10.,10.)
-anArcStartPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcStartPoint"))
+anArcCentr.setValue(10., 10.)
+anArcStartPoint = geomDataAPI_Point2D(
+    aSketchArc.attribute("ArcStartPoint"))
 assert (anArcStartPoint.x() == 0)
 assert (anArcStartPoint.y() == 0)
 assert (not anArcStartPoint.isInitialized())
 anArcStartPoint.setValue(0., 50.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
 assert (anArcEndPoint.x() == 0)
 assert (anArcEndPoint.y() == 0)
 assert (not anArcEndPoint.isInitialized())
 anArcEndPoint.setValue(50., 0.)
 aSession.finishOperation()
 # check that values have been changed
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
 assert (aSketchReflist.size() == 1)
 assert (len(aSketchReflist.list()) == 1)
 assert (anArcCentr.x() == 10.0)
@@ -81,15 +81,16 @@ assert (anArcStartPoint.x() == 0.0)
 assert (anArcStartPoint.y() == 50.0)
 assert (anArcEndPoint.x() == 50.0)
 assert (anArcEndPoint.y() == 0.0)
-#===============================================================================
+#=========================================================================
 # Edit the arc:
 # 1. Move whole arc
-# 2. Change the start point 
-#===============================================================================
+# 2. Change the start point
+#=========================================================================
 aSession.startOperation()
 deltaX, deltaY = 5., 10.
 anArcCentr.setValue(anArcCentr.x() + deltaX, anArcCentr.y() + deltaY)
-anArcStartPoint.setValue(anArcStartPoint.x() + deltaX, anArcStartPoint.y() + deltaY)
+anArcStartPoint.setValue(
+    anArcStartPoint.x() + deltaX, anArcStartPoint.y() + deltaY)
 anArcEndPoint.setValue(anArcEndPoint.x() + deltaX, anArcEndPoint.y() + deltaY)
 aSession.finishOperation()
 assert (anArcCentr.x() == 15)
@@ -111,32 +112,30 @@ assert (anArcStartPoint.y() == 60)
 assert (anArcEndPoint.x() != aPrevEndPointX)
 assert (anArcEndPoint.y() != aPrevEndPointY)
 #=========================================================================
-# Check results of the Arc 
+# Check results of the Arc
 #=========================================================================
 aResult = aSketchArc.firstResult()
 aResultConstruction = modelAPI_ResultConstruction(aResult)
 aShape = aResultConstruction.shape()
 assert (aShape is not None)
 assert (not aShape.isNull())
-#===============================================================================
+#=========================================================================
 # Create a circle
 # 1. Test SketchPlugin_Circle.h attributes
 # 2. ModelAPI_AttributeDouble attribute
-#===============================================================================
+#=========================================================================
 aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
 # Arc is already added
 assert (aSketchReflist.size() == 1)
 assert (len(aSketchReflist.list()) == 1)
-aSketchCircle = aDocument.addFeature("SketchCircle")
+aSketchCircle = aSketchFeature.addFeature("SketchCircle")
 assert (aSketchCircle.getKind() == "SketchCircle")
-aSketchReflist.append(aSketchCircle)
-aSketchCircleData = aSketchCircle.data()
-anCircleCentr = geomDataAPI_Point2D(aSketchCircleData.attribute("CircleCenter"))
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
 assert (anCircleCentr.x() == 0)
 assert (anCircleCentr.y() == 0)
 assert (not anCircleCentr.isInitialized())
-aCircleRadius = aSketchCircleData.real("CircleRadius");
+aCircleRadius = aSketchCircle.real("CircleRadius")
 assert (type(aCircleRadius) == ModelAPI_AttributeDouble)
 # ModelAPI_AttributeDouble.type() is checked in ModelAPI_TestConstants
 assert (aCircleRadius.attributeType() == ModelAPI_AttributeDouble.type())
@@ -147,11 +146,11 @@ assert (anCircleCentr.x() == -25)
 assert (anCircleCentr.y() == -25)
 assert (aCircleRadius.value() == 25)
 aSession.finishOperation()
-#===============================================================================
+#=========================================================================
 # Edit the Cricle
 # 1. Check that changing the centr of a circle does not affects radius
 # 2. and vise versa; also check that int is acceptable as well as a real
-#===============================================================================
+#=========================================================================
 aSession.startOperation()
 anCircleCentr.setValue(10, 60)
 aSession.finishOperation()
@@ -164,6 +163,6 @@ aSession.finishOperation()
 assert (anCircleCentr.x() == 10)
 assert (anCircleCentr.y() == 60)
 assert (aCircleRadius.value() == 20)
-#===============================================================================
+#=========================================================================
 # End of test
-#===============================================================================
+#=========================================================================
index dd90e27fd7df9ed05f8b921f913b93e5fb2b63da..df3f7cd64b6ab67a7ce2803a59d3c9409402f28a 100644 (file)
@@ -4,7 +4,7 @@
 from GeomDataAPI import *
 from ModelAPI import *
 
-__updated__ = "2014-07-24"
+__updated__ = "2014-10-28"
 
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
@@ -12,32 +12,32 @@ aDocument = aSession.moduleDocument()
 # Creation of a sketch
 #=========================================================================
 aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
 assert (aSketchFeature.getKind() == "Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
 dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
 diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
 aSession.finishOperation()
 # check that values have been changed
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 assert (origin.x() == 0)
 assert (origin.y() == 0)
 assert (origin.z() == 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
 assert (dirx.x() == 1)
 assert (dirx.y() == 0)
 assert (dirx.z() == 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
 assert (diry.x() == 0)
 assert (diry.y() == 1)
 assert (diry.z() == 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 assert (norm.x() == 0)
 assert (norm.y() == 0)
 assert (norm.z() == 1)
@@ -45,15 +45,14 @@ assert (norm.z() == 1)
 # Creation of a point
 #=========================================================================
 aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
 assert (not aSketchReflist.isInitialized())
 assert(aSketchReflist.size() == 0)
 assert (len(aSketchReflist.list()) == 0)
-aSketchPoint = aDocument.addFeature("SketchPoint")
+# aSketchPoint = aDocument.addFeature("SketchPoint")
+aSketchPoint = aSketchFeature.addFeature("SketchPoint")
 assert (aSketchPoint.getKind() == "SketchPoint")
-aSketchReflist.append(aSketchPoint)
-aSketchPointData = aSketchPoint.data()
-coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates"))
+coords = geomDataAPI_Point2D(aSketchPoint.attribute("PointCoordindates"))
 assert (coords.x() == 0)
 assert (coords.y() == 0)
 assert (not coords.isInitialized())
@@ -62,25 +61,23 @@ coords.setValue(10., 10.)
 assert (coords.isInitialized())
 aSession.finishOperation()
 # check that values have been changed
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
 assert (aSketchReflist.size() == 1)
 assert (len(aSketchReflist.list()) == 1)
-aSketchPointData = aSketchPoint.data()
-coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates"))
+coords = geomDataAPI_Point2D(aSketchPoint.attribute("PointCoordindates"))
 assert (coords.x() == 10.0)
 assert (coords.y() == 10.0)
-#===============================================================================
+#=========================================================================
 # Creation of a line
-#===============================================================================
+#=========================================================================
 aSession.startOperation()
-aSketchLine = aDocument.addFeature("SketchLine")
+# aSketchLine = aDocument.addFeature("SketchLine")
+aSketchLine = aSketchFeature.addFeature("SketchLine")
 assert (aSketchLine.getKind() == "SketchLine")
-aSketchReflist.append(aSketchLine)
 assert (aSketchReflist.size() == 2)
 assert (len(aSketchReflist.list()) == 2)
-aSketchLineData = aSketchLine.data()
-aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
-aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
 assert (aLineStartPoint.x() == 0)
 assert (aLineStartPoint.y() == 0)
 assert (not aLineStartPoint.isInitialized())
@@ -94,17 +91,17 @@ assert (aLineStartPoint.isInitialized())
 assert (aLineEndPoint.isInitialized())
 aSession.finishOperation()
 # check that values have been changed
-aSketchLineData = aSketchLine.data()
-aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
-aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
 assert (aLineStartPoint.x() == 50.0)
 assert (aLineStartPoint.y() == 50.0)
 assert (aLineEndPoint.x() == 60.0)
 assert (aLineEndPoint.y() == 60.0)
-#===============================================================================
+#=========================================================================
 # Check the results
-#===============================================================================
+#=========================================================================
 aResult = aSketchLine.firstResult()
+assert (aResult is not None)
 aResultConstruction = modelAPI_ResultConstruction(aResult)
 aShape = aResultConstruction.shape()
 assert (aShape is not None)
index e002f01088da13a68163c8ba9917de0370453c4f..9e212a4fabc9cd972e63e994dd1d87c288cc8685 100644 (file)
@@ -1,7 +1,7 @@
 <plugin>
   <workbench id="Sketch">
     <group id="Basic">
-      <feature id="Sketch" nested="SketchPoint SketchLine SketchCircle SketchArc SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+      <feature id="Sketch" nested="SketchPoint SketchLine SketchCircle SketchArc SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular SketchConstraintRigid" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
         <sketch-start-label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/> 
       <!--icon=":pictures/x_point.png"-->
       </feature>
         </feature_selector>
         <validator id="PartSet_PerpendicularValidator"/>
       </feature>
+
+      <feature id="SketchConstraintRigid" title="Fixed" tooltip="Create constraint defining fixed object" icon=":icons/fixed.png">
+        <feature_selector id="ConstraintEntityA" label="Object" tooltip="Select any object in the viewer">
+          <validator id="SketchPlugin_ResultPoint"/>
+          <validator id="SketchPlugin_ResultLine"/>
+          <validator id="SketchPlugin_ResultArc"/>
+        </feature_selector>
+      </feature>
     </group>
   </workbench>
 </plugin>
index 8360d0af506e3b6bba29f32b9ce5daf3c42e187b..6d4fdee3330506efff1dc38bb4618042a4428e81 100644 (file)
@@ -15,6 +15,7 @@
 #include <SketchPlugin_ConstraintParallel.h>
 #include <SketchPlugin_ConstraintPerpendicular.h>
 #include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_ConstraintRigid.h>
 
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_Data.h>
@@ -178,6 +179,22 @@ const int& SketchSolver_Constraint::getType(
     return getType();
   }
 
+  // Constraint for fixed entity
+  if (aConstraintKind.compare(SketchPlugin_ConstraintRigid::ID()) == 0) {
+    // Verify that only one entity is filled
+    int aNbAttrs = 0;
+    for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
+      boost::shared_ptr<ModelAPI_Attribute> anAttr = 
+          aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr));
+      AttrType aType = typeOfAttribute(anAttr);
+      if (aType != UNKNOWN)
+        myAttributesList[aNbAttrs++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
+    }
+    if (aNbAttrs == 1)
+      myType = SLVS_C_WHERE_DRAGGED;
+    return getType();
+  }
+
   /// \todo Implement other kind of constraints
 
   return getType();
index a7bffde09597e83ccf5f2528bc5dc4c0c5e41028..bfecae21d89bdf21d7eb3de3f3a88f791bf37400 100644 (file)
@@ -9,6 +9,7 @@
 #include <Events_Error.h>
 #include <Events_Loop.h>
 #include <GeomAPI_XY.h>
+#include <GeomAPI_Pnt2d.h>
 #include <GeomDataAPI_Dir.h>
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Point2D.h>
@@ -21,6 +22,7 @@
 #include <SketchPlugin_Constraint.h>
 #include <SketchPlugin_ConstraintLength.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintRigid.h>
 
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Circle.h>
@@ -66,7 +68,7 @@ static int Search(const uint32_t& theEntityID, const std::vector<T>& theEntities
 // ========================================================
 
 SketchSolver_ConstraintGroup::SketchSolver_ConstraintGroup(
-    boost::shared_ptr<SketchPlugin_Feature> theWorkplane)
+    boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane)
     : myID(++myGroupIndexer),
       myParamMaxID(0),
       myEntityMaxID(0),
@@ -114,7 +116,7 @@ SketchSolver_ConstraintGroup::~SketchSolver_ConstraintGroup()
 //  Purpose:  verify the group is based on the given workplane
 // ============================================================================
 bool SketchSolver_ConstraintGroup::isBaseWorkplane(
-    boost::shared_ptr<SketchPlugin_Feature> theWorkplane) const
+    boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane) const
 {
   return theWorkplane == mySketch;
 }
@@ -214,12 +216,14 @@ bool SketchSolver_ConstraintGroup::changeConstraint(
   if (myWorkplane.h == SLVS_E_UNKNOWN)
     return false;
 
+  if (theConstraint && theConstraint->getKind() == SketchPlugin_ConstraintRigid::ID())
+    return changeRigidConstraint(theConstraint);
+
   // Search this constraint in the current group to update it
-  std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator aConstrMapIter =
-      myConstraintMap.find(theConstraint);
+  ConstraintMap::const_iterator aConstrMapIter = myConstraintMap.find(theConstraint);
   std::vector<Slvs_Constraint>::iterator aConstrIter;
   if (aConstrMapIter != myConstraintMap.end()) {
-    int aConstrPos = Search(aConstrMapIter->second, myConstraints);
+    int aConstrPos = Search(aConstrMapIter->second.front(), myConstraints);
     aConstrIter = myConstraints.begin() + aConstrPos;
   }
 
@@ -247,6 +251,7 @@ bool SketchSolver_ConstraintGroup::changeConstraint(
     }
   }
 
+  size_t aNbTmpConstraints = myTempConstraints.size();
   Slvs_hEntity aConstrEnt[CONSTRAINT_ATTR_SIZE];  // parameters of the constraint
   for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
     aConstrEnt[indAttr] = SLVS_E_UNKNOWN;
@@ -293,6 +298,44 @@ bool SketchSolver_ConstraintGroup::changeConstraint(
         myExtraCoincidence.insert(theConstraint);  // the constraint is stored for further purposes
         return false;
       }
+      if (aNbTmpConstraints < myTempConstraints.size()) {
+        // There was added temporary constraint. Check that there is no coincident points which already rigid.
+
+        // Get list of already fixed points
+        std::set<Slvs_hEntity> anAlreadyFixed;
+        std::vector<Slvs_Constraint>::const_iterator aCIter = myConstraints.begin();
+        for (; aCIter != myConstraints.end(); aCIter++)
+          if (aCIter->type == SLVS_C_WHERE_DRAGGED) {
+            std::list<Slvs_hConstraint>::const_iterator aTmpIt = myTempConstraints.begin();
+            for (; aTmpIt != myTempConstraints.end(); aTmpIt++)
+              if (*aTmpIt == aCIter->h)
+                break;
+            if (aTmpIt == myTempConstraints.end())
+              anAlreadyFixed.insert(aCIter->ptA);
+          }
+
+        std::set<Slvs_hConstraint> aTmpConstrToDelete;
+        std::list<Slvs_hConstraint>::reverse_iterator aTmpIter = myTempConstraints.rbegin();
+        size_t aCurSize = myTempConstraints.size();
+        for (; aCurSize > aNbTmpConstraints && aTmpIter != myTempConstraints.rend();
+            aTmpIter++, aCurSize--) {
+          int aConstrPos = Search(*aTmpIter, myConstraints);
+          std::vector<std::set<Slvs_hEntity> >::const_iterator
+            aCoincIter = myCoincidentPoints.begin();
+          for (; aCoincIter != myCoincidentPoints.end(); aCoincIter++)
+            if (aCoincIter->find(myConstraints[aConstrPos].ptA) != aCoincIter->end()) {
+              std::set<Slvs_hEntity>::const_iterator anIt;
+              for (anIt = aCoincIter->begin(); anIt != aCoincIter->end(); anIt++)
+                if (anAlreadyFixed.find(*anIt) != anAlreadyFixed.end()) {
+                  aTmpConstrToDelete.insert(*aTmpIter);
+                  break;
+                }
+              break;
+            }
+        }
+        if (!aTmpConstrToDelete.empty())
+          removeTemporaryConstraints(aTmpConstrToDelete);
+      }
     }
 
     // Create SolveSpace constraint structure
@@ -300,7 +343,7 @@ bool SketchSolver_ConstraintGroup::changeConstraint(
                                                       myWorkplane.h, aDistance, aConstrEnt[0],
                                                       aConstrEnt[1], aConstrEnt[2], aConstrEnt[3]);
     myConstraints.push_back(aConstraint);
-    myConstraintMap[theConstraint] = aConstraint.h;
+    myConstraintMap[theConstraint] = std::vector<Slvs_hEntity>(1, aConstraint.h);
     int aConstrPos = Search(aConstraint.h, myConstraints);
     aConstrIter = myConstraints.begin() + aConstrPos;
     myNeedToSolve = true;
@@ -335,6 +378,154 @@ bool SketchSolver_ConstraintGroup::changeConstraint(
   return true;
 }
 
+// ============================================================================
+//  Function: changeRigidConstraint
+//  Class:    SketchSolver_ConstraintGroup
+//  Purpose:  create/update the "Rigid" constraint in the group
+// ============================================================================
+bool SketchSolver_ConstraintGroup::changeRigidConstraint(
+    boost::shared_ptr<SketchPlugin_Constraint> theConstraint)
+{
+  // Search this constraint in the current group to update it
+  ConstraintMap::const_iterator aConstrMapIter = myConstraintMap.find(theConstraint);
+  std::vector<Slvs_Constraint>::iterator aConstrIter;
+  if (aConstrMapIter != myConstraintMap.end()) {
+    int aConstrPos = Search(aConstrMapIter->second.front(), myConstraints);
+    aConstrIter = myConstraints.begin() + aConstrPos;
+  }
+
+  // Get constraint type and verify the constraint parameters are correct
+  SketchSolver_Constraint aConstraint(theConstraint);
+  int aConstrType = aConstraint.getType();
+  if (aConstrType == SLVS_C_UNKNOWN
+      || (aConstrMapIter != myConstraintMap.end() && aConstrIter->type != aConstrType))
+    return false;
+  const std::vector<std::string>& aConstraintAttributes = aConstraint.getAttributes();
+
+  Slvs_hEntity aConstrEnt = SLVS_E_UNKNOWN;
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> aConstrAttr = boost::dynamic_pointer_cast<
+      ModelAPI_AttributeRefAttr>(
+      theConstraint->data()->attribute(aConstraintAttributes[0]));
+  if (!aConstrAttr)
+    return false;
+
+  // Convert the object of the attribute to the feature
+  FeaturePtr aFeature;
+  if (aConstrAttr->isObject() && aConstrAttr->object()) {
+    ResultConstructionPtr aRC = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(
+        aConstrAttr->object());
+    if (!aRC)
+      return false;
+    boost::shared_ptr<ModelAPI_Document> aDoc = aRC->document();
+    aFeature = aDoc->feature(aRC);
+  }
+
+  aConstrEnt = aConstrAttr->isObject() ? changeEntity(aFeature) : changeEntity(aConstrAttr->attr());
+
+  if (aConstrMapIter == myConstraintMap.end()) { // Add new constraint
+    // Check the fixed entity is not a point.
+    boost::shared_ptr<ModelAPI_AttributeRefAttr> aConstrAttr = boost::dynamic_pointer_cast<
+        ModelAPI_AttributeRefAttr>(theConstraint->data()->attribute(aConstraintAttributes[0]));
+    boost::shared_ptr<GeomDataAPI_Point> aPoint =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point>(aConstrAttr->attr());
+    boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aConstrAttr->attr());
+    if (aPoint || aPoint2D) {
+      // Create SolveSpace constraint structure
+      Slvs_Constraint aConstraint = Slvs_MakeConstraint(
+          ++myConstrMaxID, myID, aConstrType, myWorkplane.h, 0.0,
+          aConstrEnt, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
+      myConstraints.push_back(aConstraint);
+      myConstraintMap[theConstraint] = std::vector<Slvs_hEntity>(1, aConstraint.h);
+      int aConstrPos = Search(aConstraint.h, myConstraints);
+      aConstrIter = myConstraints.begin() + aConstrPos;
+      myNeedToSolve = true;
+    } else {
+      myConstraintMap[theConstraint] = std::vector<Slvs_hEntity>();
+
+      // To avoid SolveSpace problems:
+      // * if the circle is rigid, we will fix its center and radius;
+      // * if the arc is rigid, we will fix its start and end points and radius.
+      double aRadius = 0.0;
+      bool isArc = false;
+      bool isCircle = false;
+      if (aFeature) {
+        if (aFeature->getKind() == SketchPlugin_Arc::ID()) {
+          boost::shared_ptr<GeomDataAPI_Point2D> aCenter =
+              boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+              aFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
+          boost::shared_ptr<GeomDataAPI_Point2D> aStart =
+              boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+              aFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
+          aRadius = aStart->pnt()->distance(aCenter->pnt());
+          isArc = true;
+        } else if (aFeature->getKind() == SketchPlugin_Circle::ID()) {
+          aRadius = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+              aFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID()))->value();
+          isCircle = true;
+        }
+      }
+
+      // Get list of already fixed points
+      std::set<Slvs_hEntity> anAlreadyFixed;
+      std::vector<Slvs_Constraint>::const_iterator aCIter = myConstraints.begin();
+      for (; aCIter != myConstraints.end(); aCIter++)
+        if (aCIter->type == SLVS_C_WHERE_DRAGGED)
+          anAlreadyFixed.insert(aCIter->ptA);
+
+      // Create constraints to fix the parameters of the entity
+      int aEntPos = Search(aConstrEnt, myEntities);
+      Slvs_hEntity* aPointsPtr = myEntities[aEntPos].point;
+      if (isArc) aPointsPtr++; // avoid to fix center of arc
+      while (*aPointsPtr != 0) {
+        // Avoid to create additional "Rigid" constraints for coincident points
+        bool isCoincAlreadyFixed = false;
+        if (!anAlreadyFixed.empty()) {
+          if (anAlreadyFixed.find(*aPointsPtr) != anAlreadyFixed.end())
+            isCoincAlreadyFixed = true;
+
+          std::vector<std::set<Slvs_hEntity> >::const_iterator aCoincIter =
+              myCoincidentPoints.begin();
+          for (; !isCoincAlreadyFixed && aCoincIter != myCoincidentPoints.end(); aCoincIter++) {
+            if (aCoincIter->find(*aPointsPtr) == aCoincIter->end())
+              continue;
+            std::set<Slvs_hEntity>::const_iterator anIter = anAlreadyFixed.begin();
+            for (; !isCoincAlreadyFixed && anIter != anAlreadyFixed.end(); anIter++)
+              if (aCoincIter->find(*anIter) != aCoincIter->end())
+                isCoincAlreadyFixed = true;
+          }
+        }
+
+        if (!isCoincAlreadyFixed) {
+          Slvs_Constraint aConstraint = Slvs_MakeConstraint(
+              ++myConstrMaxID, myID, aConstrType, myWorkplane.h, 0.0,
+              *aPointsPtr, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
+          myConstraints.push_back(aConstraint);
+          myConstraintMap[theConstraint].push_back(aConstraint.h);
+        }
+        aPointsPtr++;
+      }
+
+      if (isArc || isCircle) { // add radius constraint
+        Slvs_Constraint aConstraint = Slvs_MakeConstraint(
+            ++myConstrMaxID, myID, SLVS_C_DIAMETER, myWorkplane.h, 2.0 * aRadius,
+            SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, aConstrEnt, SLVS_E_UNKNOWN);
+        myConstraints.push_back(aConstraint);
+        myConstraintMap[theConstraint].push_back(aConstraint.h);
+      }
+
+      // The object is already rigid, so there is no constraints added
+      if (myConstraintMap[theConstraint].empty()) {
+        myConstraintMap.erase(theConstraint);
+        myNeedToSolve = false;
+      }
+      else
+        myNeedToSolve = true;
+    }
+  }
+  return true;
+}
+
 // ============================================================================
 //  Function: changeEntity
 //  Class:    SketchSolver_ConstraintGroup
@@ -359,6 +550,28 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
   const bool isNeedToSolve = myNeedToSolve;
   myNeedToSolve = false;
 
+  if (isEntExists) {
+    // Verify that the entity is not used by "Rigid" constraint.
+    // If it is used, the object should not move.
+    std::vector<std::set<Slvs_hEntity> >::iterator aCoincIter = myCoincidentPoints.begin();
+    for (; aCoincIter != myCoincidentPoints.end(); aCoincIter++)
+      if (aCoincIter->find(aEntIter->second) != aCoincIter->end())
+        break;
+    std::set<Slvs_hEntity> aCoincident;
+    if (aCoincIter != myCoincidentPoints.end())
+      aCoincident = *aCoincIter;
+    else
+      aCoincident.insert(aEntIter->second);
+
+    std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
+    for (; aConstrIter != myConstraints.end(); aConstrIter++)
+      if (aConstrIter->type == SLVS_C_WHERE_DRAGGED &&
+          aCoincident.find(aConstrIter->ptA) != aCoincident.end()) {
+        myNeedToSolve = true;
+        return aEntIter->second;
+      }
+  }
+
   // Look over supported types of entities
   Slvs_Entity aNewEntity;
   aNewEntity.h = SLVS_E_UNKNOWN;
@@ -397,23 +610,26 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
   }
   /// \todo Other types of entities
 
+  Slvs_hEntity aResult = SLVS_E_UNKNOWN; // Unsupported or wrong entity type
+
   if (isEntExists) {
     if (!myEntOfConstr[aEntPos]) // the entity is not used by constraints, no need to resolve them
       myNeedToSolve = isNeedToSolve;
     else
       myNeedToSolve = myNeedToSolve || isNeedToSolve;
-    return aEntIter->second;
-  }
-
-  if (aNewEntity.h != SLVS_E_UNKNOWN) {
+    aResult = aEntIter->second;
+  } else if (aNewEntity.h != SLVS_E_UNKNOWN) {
     myEntities.push_back(aNewEntity);
     myEntOfConstr.push_back(false);
     myEntityAttrMap[theEntity] = aNewEntity.h;
-    return aNewEntity.h;
+    aResult = aNewEntity.h;
   }
 
-  // Unsupported or wrong entity type
-  return SLVS_E_UNKNOWN;
+  // If the attribute was changed by the user, we need to fix it before solving
+  if (myNeedToSolve && theEntity->isImmutable())
+    addTemporaryConstraintWhereDragged(theEntity, false);
+
+  return aResult;
 }
 
 // ============================================================================
@@ -438,28 +654,30 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(FeaturePtr theEntity)
       SketchPlugin_Feature>(theEntity);
   if (aFeature) {  // Verify the feature by its kind
     const std::string& aFeatureKind = aFeature->getKind();
-
-    std::list<AttributePtr> anAttributes = aFeature->data()->attributes(std::string());
-    std::list<AttributePtr>::iterator anAttrIter = anAttributes.begin();
-    for ( ; anAttrIter != anAttributes.end(); anAttrIter++)
-      if (!(*anAttrIter)->isInitialized()) // the entity is not fully initialized, don't add it into solver
-        return SLVS_E_UNKNOWN;
+    AttributePtr anAttribute;
 
     // Line
     if (aFeatureKind.compare(SketchPlugin_Line::ID()) == 0) {
-      Slvs_hEntity aStart = changeEntity(
-          aFeature->data()->attribute(SketchPlugin_Line::START_ID()));
-      Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(SketchPlugin_Line::END_ID()));
+      anAttribute = aFeature->data()->attribute(SketchPlugin_Line::START_ID());
+      if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+      Slvs_hEntity aStart = changeEntity(anAttribute);
+
+      anAttribute = aFeature->data()->attribute(SketchPlugin_Line::END_ID());
+      if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+      Slvs_hEntity aEnd = changeEntity(anAttribute);
 
       if (!isEntExists) // New entity
         aNewEntity = Slvs_MakeLineSegment(++myEntityMaxID, myID, myWorkplane.h, aStart, aEnd);
     }
     // Circle
     else if (aFeatureKind.compare(SketchPlugin_Circle::ID()) == 0) {
-      Slvs_hEntity aCenter = changeEntity(
-          aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
-      Slvs_hEntity aRadius = changeEntity(
-          aFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID()));
+      anAttribute = aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID());
+      if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+      Slvs_hEntity aCenter = changeEntity(anAttribute);
+
+      anAttribute = aFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID());
+      if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+      Slvs_hEntity aRadius = changeEntity(anAttribute);
 
       if (!isEntExists) // New entity
         aNewEntity = Slvs_MakeCircle(++myEntityMaxID, myID, myWorkplane.h, aCenter,
@@ -467,10 +685,17 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(FeaturePtr theEntity)
     }
     // Arc
     else if (aFeatureKind.compare(SketchPlugin_Arc::ID()) == 0) {
-      Slvs_hEntity aCenter = changeEntity(
-          aFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
-      Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
-      Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
+      anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID());
+      if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+      Slvs_hEntity aCenter = changeEntity(anAttribute);
+
+      anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::START_ID());
+      if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+      Slvs_hEntity aStart = changeEntity(anAttribute);
+
+      anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::END_ID());
+      if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+      Slvs_hEntity aEnd = changeEntity(anAttribute);
 
       if (!isEntExists)
         aNewEntity = Slvs_MakeArcOfCircle(++myEntityMaxID, myID, myWorkplane.h,
@@ -478,8 +703,9 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(FeaturePtr theEntity)
     }
     // Point (it has low probability to be an attribute of constraint, so it is checked at the end)
     else if (aFeatureKind.compare(SketchPlugin_Point::ID()) == 0) {
-      Slvs_hEntity aPoint = changeEntity(
-          aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
+      anAttribute = aFeature->data()->attribute(SketchPlugin_Point::COORD_ID());
+      if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+      Slvs_hEntity aPoint = changeEntity(anAttribute);
 
       if (isEntExists)
         return aEntIter->second;
@@ -503,7 +729,6 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(FeaturePtr theEntity)
     return aNewEntity.h;
   }
 
-
   // Unsupported or wrong entity type
   return SLVS_E_UNKNOWN;
 }
@@ -563,7 +788,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeNormal(
 //  Class:    SketchSolver_ConstraintGroup
 //  Purpose:  create workplane for the group
 // ============================================================================
-bool SketchSolver_ConstraintGroup::addWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch)
+bool SketchSolver_ConstraintGroup::addWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theSketch)
 {
   if (myWorkplane.h || theSketch->getKind().compare(SketchPlugin_Sketch::ID()) != 0)
     return false;  // the workplane already exists or the function parameter is not Sketch
@@ -685,11 +910,10 @@ void SketchSolver_ConstraintGroup::mergeGroups(const SketchSolver_ConstraintGrou
   std::map<Slvs_hConstraint, Slvs_hConstraint> aConstrMap;
 
   // Add all constraints from theGroup to the current group
-  std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator aConstrIter =
-      theGroup.myConstraintMap.begin();
+  ConstraintMap::const_iterator aConstrIter = theGroup.myConstraintMap.begin();
   for (; aConstrIter != theGroup.myConstraintMap.end(); aConstrIter++)
     if (changeConstraint(aConstrIter->first))
-      aConstrMap[aConstrIter->second] = myConstrMaxID;  // the constraint was added => store its ID
+      aConstrMap[aConstrIter->second.back()] = myConstrMaxID;  // the constraint was added => store its ID
 
   // Add temporary constraints from theGroup
   std::list<Slvs_hConstraint>::const_iterator aTempConstrIter = theGroup.myTempConstraints.begin();
@@ -812,14 +1036,13 @@ void SketchSolver_ConstraintGroup::splitGroup(std::vector<SketchSolver_Constrain
     SketchSolver_ConstraintGroup* aG = new SketchSolver_ConstraintGroup(mySketch);
     aNewGroups.push_back(aG);
   }
-  std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator aConstrMapIter =
-      myConstraintMap.begin();
+  ConstraintMap::const_iterator aConstrMapIter = myConstraintMap.begin();
   int aConstrMapPos = 0;  // position of iterator in the map (used to restore iterator after removing constraint)
   while (aConstrMapIter != myConstraintMap.end()) {
     std::vector<std::set<Slvs_hConstraint> >::const_iterator aGIter = aGroupsConstr.begin();
     std::vector<SketchSolver_ConstraintGroup*>::iterator aGroup = aNewGroups.begin();
     for (; aGIter != aGroupsConstr.end(); aGIter++, aGroup++)
-      if (aGIter->find(aConstrMapIter->second) != aGIter->end()) {
+      if (aGIter->find(aConstrMapIter->second.front()) != aGIter->end()) {
         (*aGroup)->changeConstraint(aConstrMapIter->first);
         removeConstraint(aConstrMapIter->first);
         // restore iterator
@@ -844,8 +1067,7 @@ void SketchSolver_ConstraintGroup::splitGroup(std::vector<SketchSolver_Constrain
 // ============================================================================
 bool SketchSolver_ConstraintGroup::updateGroup()
 {
-  std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::reverse_iterator aConstrIter =
-      myConstraintMap.rbegin();
+  ConstraintMap::reverse_iterator aConstrIter = myConstraintMap.rbegin();
   bool isAllValid = true;
   bool isCCRemoved = false;  // indicates that at least one of coincidence constraints was removed
   int aConstrIndex = 0;
@@ -1007,7 +1229,8 @@ void SketchSolver_ConstraintGroup::updateEntityIfPossible(
 //            which was moved by user
 // ============================================================================
 void SketchSolver_ConstraintGroup::addTemporaryConstraintWhereDragged(
-    boost::shared_ptr<ModelAPI_Attribute> theEntity)
+    boost::shared_ptr<ModelAPI_Attribute> theEntity,
+    bool theAllowToFit)
 {
   // Find identifier of the entity
   std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator anEntIter =
@@ -1015,27 +1238,19 @@ void SketchSolver_ConstraintGroup::addTemporaryConstraintWhereDragged(
   if (anEntIter == myEntityAttrMap.end())
     return;
 
-  // If this is a first dragged point, its parameters should be placed 
-  // into Slvs_System::dragged field to avoid system inconsistense
-  if (myTempPointWhereDragged.empty()) {
-    int anEntPos = Search(anEntIter->second, myEntities);
-    Slvs_hParam* aDraggedParam = myEntities[anEntPos].param;
-    for (int i = 0; i < 4; i++, aDraggedParam++)
-      if (*aDraggedParam != 0)
-        myTempPointWhereDragged.push_back(*aDraggedParam);
-    myTempPointWDrgdID = myEntities[anEntPos].h;
-    return;
-  }
-
   // Get identifiers of all dragged points
   std::set<Slvs_hEntity> aDraggedPntID;
   aDraggedPntID.insert(myTempPointWDrgdID);
-  std::list<Slvs_hConstraint>::iterator aTmpCoIter = myTempConstraints.begin();
+  std::list<Slvs_hConstraint>::const_iterator aTmpCoIter = myTempConstraints.begin();
   for (; aTmpCoIter != myTempConstraints.end(); aTmpCoIter++) {
     unsigned int aConstrPos = Search(*aTmpCoIter, myConstraints);
     if (aConstrPos < myConstraints.size())
       aDraggedPntID.insert(myConstraints[aConstrPos].ptA);
   }
+  std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
+  for (; aConstrIter != myConstraints.end(); aConstrIter++)
+    if (aConstrIter->type == SLVS_C_WHERE_DRAGGED)
+      aDraggedPntID.insert(aConstrIter->ptA);
   // Find whether there is a point coincident with theEntity, which already has SLVS_C_WHERE_DRAGGED
   std::vector<std::set<Slvs_hEntity> >::iterator aCoPtIter = myCoincidentPoints.begin();
   for (; aCoPtIter != myCoincidentPoints.end(); aCoPtIter++) {
@@ -1048,6 +1263,20 @@ void SketchSolver_ConstraintGroup::addTemporaryConstraintWhereDragged(
       if (aCoPtIter->find(*aDrgIter) != aCoPtIter->end())
         return;  // the SLVS_C_WHERE_DRAGGED constraint already exists
   }
+  if (aDraggedPntID.find(anEntIter->second) != aDraggedPntID.end())
+    return;
+
+  // If this is a first dragged point, its parameters should be placed 
+  // into Slvs_System::dragged field to avoid system inconsistense
+  if (myTempPointWhereDragged.empty() && theAllowToFit) {
+    int anEntPos = Search(anEntIter->second, myEntities);
+    Slvs_hParam* aDraggedParam = myEntities[anEntPos].param;
+    for (int i = 0; i < 4; i++, aDraggedParam++)
+      if (*aDraggedParam != 0)
+        myTempPointWhereDragged.push_back(*aDraggedParam);
+    myTempPointWDrgdID = myEntities[anEntPos].h;
+    return;
+  }
 
   // Create additional SLVS_C_WHERE_DRAGGED constraint if myTempPointWhereDragged field is not empty
   Slvs_Constraint aWDConstr = Slvs_MakeConstraint(++myConstrMaxID, myID, SLVS_C_WHERE_DRAGGED,
@@ -1062,11 +1291,14 @@ void SketchSolver_ConstraintGroup::addTemporaryConstraintWhereDragged(
 //  Purpose:  remove all transient SLVS_C_WHERE_DRAGGED constraints after
 //            resolving the set of constraints
 // ============================================================================
-void SketchSolver_ConstraintGroup::removeTemporaryConstraints()
+void SketchSolver_ConstraintGroup::removeTemporaryConstraints(
+    const std::set<Slvs_hConstraint>& theRemoved)
 {
   std::list<Slvs_hConstraint>::reverse_iterator aTmpConstrIter;
   for (aTmpConstrIter = myTempConstraints.rbegin(); aTmpConstrIter != myTempConstraints.rend();
       aTmpConstrIter++) {
+    if (!theRemoved.empty() && theRemoved.find(*aTmpConstrIter) == theRemoved.end())
+      continue;
     unsigned int aConstrPos = Search(*aTmpConstrIter, myConstraints);
     if (aConstrPos >= myConstraints.size())
       continue;
@@ -1080,6 +1312,7 @@ void SketchSolver_ConstraintGroup::removeTemporaryConstraints()
 
   // Clear basic dragged point
   myTempPointWhereDragged.clear();
+  myTempPointWDrgdID = SLVS_E_UNKNOWN;
 }
 
 // ============================================================================
@@ -1090,26 +1323,29 @@ void SketchSolver_ConstraintGroup::removeTemporaryConstraints()
 void SketchSolver_ConstraintGroup::removeConstraint(
     boost::shared_ptr<SketchPlugin_Constraint> theConstraint)
 {
-  std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::iterator anIterToRemove =
-      myConstraintMap.find(theConstraint);
+  ConstraintMap::iterator anIterToRemove = myConstraintMap.find(theConstraint);
   if (anIterToRemove == myConstraintMap.end())
     return;
 
-  Slvs_hConstraint aCnstrToRemove = anIterToRemove->second;
+  std::vector<Slvs_hConstraint> aCnstrToRemove = anIterToRemove->second;
   // Remove constraint from the map
   myConstraintMap.erase(anIterToRemove);
 
-  // Find unused entities
-  int aConstrPos = Search(aCnstrToRemove, myConstraints);
   std::set<Slvs_hEntity> anEntToRemove;
-  Slvs_hEntity aCnstEnt[] = { myConstraints[aConstrPos].ptA, myConstraints[aConstrPos].ptB,
-      myConstraints[aConstrPos].entityA, myConstraints[aConstrPos].entityB };
-  for (int i = 0; i < 4; i++)
-    if (aCnstEnt[i] != 0)
-      anEntToRemove.insert(aCnstEnt[i]);
-  myConstraints.erase(myConstraints.begin() + aConstrPos);
-  if (aCnstrToRemove == myConstrMaxID)
-    myConstrMaxID--;
+  
+  // Find unused entities
+  std::vector<Slvs_hConstraint>::iterator aCnstrToRemoveIter = aCnstrToRemove.begin();
+  for (; aCnstrToRemoveIter != aCnstrToRemove.end(); aCnstrToRemoveIter++) {
+    int aConstrPos = Search(*aCnstrToRemoveIter, myConstraints);
+    Slvs_hEntity aCnstEnt[] = { myConstraints[aConstrPos].ptA, myConstraints[aConstrPos].ptB,
+        myConstraints[aConstrPos].entityA, myConstraints[aConstrPos].entityB };
+    for (int i = 0; i < 4; i++)
+      if (aCnstEnt[i] != 0)
+        anEntToRemove.insert(aCnstEnt[i]);
+    myConstraints.erase(myConstraints.begin() + aConstrPos);
+    if (*aCnstrToRemoveIter == myConstrMaxID)
+      myConstrMaxID--;
+  }
 
   // Find all entities which are based on these unused
   std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
@@ -1252,8 +1488,7 @@ bool SketchSolver_ConstraintGroup::addCoincidentPoints(const Slvs_hEntity& thePo
 void SketchSolver_ConstraintGroup::updateRelatedConstraints(
     boost::shared_ptr<ModelAPI_Attribute> theEntity) const
 {
-  std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator aConstrIter =
-      myConstraintMap.begin();
+  ConstraintMap::const_iterator aConstrIter = myConstraintMap.begin();
   for (; aConstrIter != myConstraintMap.end(); aConstrIter++) {
     std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttributes = aConstrIter->first->data()
         ->attributes(std::string());
@@ -1278,8 +1513,7 @@ void SketchSolver_ConstraintGroup::updateRelatedConstraints(
 void SketchSolver_ConstraintGroup::updateRelatedConstraints(
     boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
-  std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator aConstrIter =
-      myConstraintMap.begin();
+  ConstraintMap::const_iterator aConstrIter = myConstraintMap.begin();
   for (; aConstrIter != myConstraintMap.end(); aConstrIter++) {
     std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttributes = aConstrIter->first->data()
         ->attributes(std::string());
index 6024f8caecab8cebac7dd567d8d2ccb312531838..c8a673029e2ce047589e971d17e7cdb2b132dd70 100644 (file)
@@ -16,6 +16,9 @@
 #include <vector>
 #include <set>
 
+typedef std::map< boost::shared_ptr<SketchPlugin_Constraint>, std::vector<Slvs_hConstraint> >
+  ConstraintMap;
+
 /** \class   SketchSolver_ConstraintGroup
  *  \ingroup DataModel
  *  \brief   Keeps the group of constraints which based on the same entities
@@ -27,7 +30,7 @@ class SketchSolver_ConstraintGroup
    *         Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type
    *  \remark Type of theSketch is not verified inside
    */
-  SketchSolver_ConstraintGroup(boost::shared_ptr<SketchPlugin_Feature> theWorkplane);
+  SketchSolver_ConstraintGroup(boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane);
 
   ~SketchSolver_ConstraintGroup();
 
@@ -54,6 +57,7 @@ class SketchSolver_ConstraintGroup
    *  \return \c true if the constraint added or updated successfully
    */
   bool changeConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
+  bool changeRigidConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
 
   /** \brief Verifies the feature attributes are used in this group
    *  \param[in] theFeature constraint or any other object for verification of interaction
@@ -65,9 +69,9 @@ class SketchSolver_ConstraintGroup
    *  \param[in] theWorkplane the feature to be compared with base workplane
    *  \return \c true if workplanes are the same
    */
-  bool isBaseWorkplane(boost::shared_ptr<SketchPlugin_Feature> theWorkplane) const;
+  bool isBaseWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane) const;
 
-  boost::shared_ptr<SketchPlugin_Feature> getWorkplane() const
+  boost::shared_ptr<ModelAPI_CompositeFeature> getWorkplane() const
   {
     return mySketch;
   }
@@ -165,20 +169,26 @@ protected:
                        const Slvs_hEntity& theEntityID);
 
   /** \brief Adds a constraint for a point which should not be changed during computations
-   *  \param[in] theEntity the base for the constraint
+   *  \param[in] theEntity     the base for the constraint
+   *  \param[in] theAllowToFit this flag shows that the entity may be placed into 
+   *                           the 'dragged' field of SolveSpace solver, so this entity 
+   *                           may be changed a little during solution
    */
-  void addTemporaryConstraintWhereDragged(boost::shared_ptr<ModelAPI_Attribute> theEntity);
+  void addTemporaryConstraintWhereDragged(boost::shared_ptr<ModelAPI_Attribute> theEntity,
+                                          bool theAllowToFit = true);
 
   /** \brief Remove all temporary constraint after computation finished
+   *  \param[in] theRemoved  indexes of constraints to be removed. If empty, all temporary constraints should be deleted
    */
-  void removeTemporaryConstraints();
+  void removeTemporaryConstraints(const std::set<Slvs_hConstraint>& theRemoved =
+                                                                 std::set<Slvs_hConstraint>());
 
  private:
   /** \brief Creates a workplane from the sketch parameters
    *  \param[in] theSketch parameters of workplane are the attributes of this sketch
    *  \return \c true if success, \c false if workplane parameters are not consistent
    */
-  bool addWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch);
+  bool addWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theSketch);
 
   /** \brief Add the entities of constraint for points coincidence into the appropriate list
    *  \param[in] thePoint1 identifier of the first point
@@ -214,8 +224,8 @@ protected:
   std::list<Slvs_hConstraint> myTempConstraints;  ///< The list of identifiers of temporary constraints (SLVS_C_WHERE_DRAGGED) applied for all other points moved by user
 
   // SketchPlugin entities
-  boost::shared_ptr<SketchPlugin_Feature> mySketch;        ///< Equivalent to workplane
-  std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint> myConstraintMap;  ///< The map between SketchPlugin and SolveSpace constraints
+  boost::shared_ptr<ModelAPI_CompositeFeature> mySketch;        ///< Equivalent to workplane
+  ConstraintMap myConstraintMap;  ///< The map between SketchPlugin and SolveSpace constraints
   std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity> myEntityAttrMap;  ///< The map between "attribute" parameters of constraints and their equivalent SolveSpace entities
   std::map<FeaturePtr, Slvs_hEntity> myEntityFeatMap;  ///< The map between "feature" parameters of constraints and their equivalent SolveSpace entities
 
index c0ade33a73680d44350a1919be5ebe31baed40f0..ebc25b1fa35edf7dbbb20e78b976258937cd914c 100644 (file)
@@ -88,8 +88,8 @@ void SketchSolver_ConstraintManager::processEvent(
         // Only sketches and constraints can be added by Create event
         const std::string& aFeatureKind = aFeature->getKind();
         if (aFeatureKind.compare(SketchPlugin_Sketch::ID()) == 0) {
-          boost::shared_ptr<SketchPlugin_Feature> aSketch = boost::dynamic_pointer_cast<
-              SketchPlugin_Feature>(aFeature);
+          boost::shared_ptr<ModelAPI_CompositeFeature> aSketch = boost::dynamic_pointer_cast<
+              ModelAPI_CompositeFeature>(aFeature);
           if (aSketch)
             changeWorkplane(aSketch);
           continue;
@@ -144,7 +144,7 @@ void SketchSolver_ConstraintManager::processEvent(
 //  Purpose:  update workplane by given parameters of the sketch
 // ============================================================================
 bool SketchSolver_ConstraintManager::changeWorkplane(
-    boost::shared_ptr<SketchPlugin_Feature> theSketch)
+    boost::shared_ptr<ModelAPI_CompositeFeature> theSketch)
 {
   bool aResult = true;  // changed when a workplane wrongly updated
   bool isUpdated = false;
@@ -189,7 +189,7 @@ bool SketchSolver_ConstraintManager::changeConstraintOrEntity(
     // There are no groups applicable for this constraint => create new one
     // The group will be created only for constraints, not for features
     if (!aConstraint) return false;
-    boost::shared_ptr<SketchPlugin_Feature> aWP = findWorkplane(aConstraint);
+    boost::shared_ptr<ModelAPI_CompositeFeature> aWP = findWorkplane(aConstraint);
     if (!aWP)
       return false;
     SketchSolver_ConstraintGroup* aGroup = new SketchSolver_ConstraintGroup(aWP);
@@ -309,7 +309,7 @@ void SketchSolver_ConstraintManager::findGroups(
     boost::shared_ptr<SketchPlugin_Feature> theFeature,
     std::set<Slvs_hGroup>& theGroupIDs) const
 {
-  boost::shared_ptr<SketchPlugin_Feature> aWP = findWorkplane(theFeature);
+  boost::shared_ptr<ModelAPI_CompositeFeature> aWP = findWorkplane(theFeature);
 
   SketchSolver_ConstraintGroup* anEmptyGroup = 0;  // appropriate empty group for specified constraint
   std::vector<SketchSolver_ConstraintGroup*>::const_iterator aGroupIter;
@@ -331,15 +331,15 @@ void SketchSolver_ConstraintManager::findGroups(
 //  Class:    SketchSolver_Session
 //  Purpose:  search workplane containing given feature
 // ============================================================================
-boost::shared_ptr<SketchPlugin_Feature> SketchSolver_ConstraintManager::findWorkplane(
+boost::shared_ptr<ModelAPI_CompositeFeature> SketchSolver_ConstraintManager::findWorkplane(
     boost::shared_ptr<SketchPlugin_Feature> theFeature) const
 {
   // Already verified workplanes
-  std::set<boost::shared_ptr<SketchPlugin_Feature> > aVerified;
+  std::set<boost::shared_ptr<ModelAPI_CompositeFeature> > aVerified;
 
   std::vector<SketchSolver_ConstraintGroup*>::const_iterator aGroupIter;
   for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++) {
-    boost::shared_ptr<SketchPlugin_Feature> aWP = (*aGroupIter)->getWorkplane();
+    boost::shared_ptr<ModelAPI_CompositeFeature> aWP = (*aGroupIter)->getWorkplane();
     if (aVerified.find(aWP) != aVerified.end())
       continue;
 
@@ -353,7 +353,7 @@ boost::shared_ptr<SketchPlugin_Feature> SketchSolver_ConstraintManager::findWork
     aVerified.insert(aWP);
   }
 
-  return boost::shared_ptr<SketchPlugin_Feature>();
+  return boost::shared_ptr<ModelAPI_CompositeFeature>();
 }
 
 // ============================================================================
index b0aefd196ea3f8c9ddd8c36e09cd219e924a0d4e..b13a67182460bb373c4da9300f00f250415e16b5 100644 (file)
@@ -65,7 +65,7 @@ class SketchSolver_ConstraintManager : public Events_Listener
    *  \return \c true if the workplane changed successfully
    *  \remark Type of theSketch is not verified inside
    */
-  bool changeWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch);
+  bool changeWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theSketch);
 
   /** \brief Removes a workplane from the manager.
    *         All groups based on such workplane will be removed too.
@@ -95,7 +95,7 @@ class SketchSolver_ConstraintManager : public Events_Listener
    *  \param[in] theFeature object to be found
    *  \return workplane containing the feature
    */
-  boost::shared_ptr<SketchPlugin_Feature> findWorkplane(
+  boost::shared_ptr<ModelAPI_CompositeFeature> findWorkplane(
       boost::shared_ptr<SketchPlugin_Feature> theFeature) const;
 
  private:
index 2582013d59e19019d40c13f7e711a90ee34f1da9..5ceda79603cc6772b9892f5b90e4443776859be6 100644 (file)
@@ -25,7 +25,6 @@ SET(PROJECT_HEADERS
     XGUI_SalomeConnector.h
     XGUI_ActionsMgr.h
     XGUI_ErrorDialog.h
-    XGUI_SalomeViewer.h
     XGUI_ViewerProxy.h
     XGUI_PropertyPanel.h
     XGUI_ContextMenuMgr.h
@@ -125,6 +124,7 @@ INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Events
                                         ${PROJECT_SOURCE_DIR}/src/GeomAPI
                                         ${PROJECT_SOURCE_DIR}/src/ModuleBase
                                         ${PROJECT_SOURCE_DIR}/src/PartSetPlugin
+                                        ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
                                         ${CAS_INCLUDE_DIRS}
                                         ${SUIT_INCLUDE})
 
index c3a35fe7cbc534739d8db3a16a52ed3ed00ccef4..081ab537f9c7a6ab02e2b24ab4873b78388813f9 100644 (file)
@@ -129,14 +129,22 @@ void XGUI_ActionsMgr::updateByDocumentKind()
 {
   std::string aStdDocKind = ModelAPI_Session::get()->activeDocument()->kind();
   QString aDocKind = QString::fromStdString(aStdDocKind);
+  XGUI_Workshop* aWorkshop = static_cast<XGUI_Workshop*>(parent());
   foreach(QAction* eachAction, myActions.values()) {
     XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(eachAction);
+    QString aCmdDocKind;
     if(aCmd) {
-      QString aCmdDocKind = aCmd->documentKind();
-      if(!aCmdDocKind.isEmpty() && aCmdDocKind != aDocKind) {
-        eachAction->setEnabled(false);
+      aCmdDocKind = aCmd->documentKind();
+    }
+    else {
+      QString aId = eachAction->data().toString();
+      if (!aId.isEmpty()) {
+        aCmdDocKind = aWorkshop->salomeConnector()->documentKind(aId);
       }
     }
+    if(!aCmdDocKind.isEmpty() && aCmdDocKind != aDocKind) {
+      eachAction->setEnabled(false);
+    }
   }
 }
 
index 4f726ab5d442b62cc99675b5ffe0fc175ee138d4..1194dc4543785c84b0339555b385dab588506de9 100644 (file)
@@ -49,6 +49,7 @@ QWidget* XGUI_Command::createWidget(QWidget* theParent)
     QString aToolTip = toolTip();
     if (!aKeys.isEmpty()) {
       aToolTip = QString("%1 (%2)").arg(aToolTip).arg(aKeys.toString());
+      aButton->setShortcut(aKeys);
     }
     if (!aToolTip.isEmpty()) {
       aButton->setToolTip(aToolTip);
index 84bf0d7beaea67bbcafb0bb59a3ae0ea4f75740a..a9618988920f1a3df15eb3303d335e16bed1a827 100644 (file)
@@ -13,6 +13,7 @@
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
 
 #include <QAction>
 #include <QContextMenuEvent>
index 6ac7aca9a875a3d77fe8e5e1aaac85302ec4e01e..0bdf7633e70b7beec87742510e57237057f02272 100644 (file)
@@ -12,6 +12,8 @@
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Tools.h>
 
+#include <ModuleBase_ResultPrs.h>
+
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_IPresentable.h>
 
@@ -21,6 +23,8 @@
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <AIS_DimensionSelectionMode.hxx>
 #include <AIS_Shape.hxx>
+#include <AIS_Dimension.hxx>
+#include <TColStd_ListIteratorOfListOfInteger.hxx>
 
 #include <set>
 
@@ -45,19 +49,20 @@ void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
   if (isVisible(theObject)) {
     redisplay(theObject, isUpdateViewer);
   } else {
-    boost::shared_ptr<GeomAPI_AISObject> anAIS;
+    AISObjectPtr anAIS;
 
     GeomPresentablePtr aPrs = boost::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
     bool isShading = false;
     if (aPrs) {
-      anAIS = aPrs->getAISObject(boost::shared_ptr<GeomAPI_AISObject>());
+      anAIS = aPrs->getAISObject(AISObjectPtr());
     } else {
       ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
       if (aResult) {
         boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
         if (aShapePtr) {
-          anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
-          anAIS->createShape(aShapePtr);
+          anAIS = AISObjectPtr(new GeomAPI_AISObject());
+          anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
+          //anAIS->createShape(aShapePtr);
           isShading = true;
         }
       }
@@ -67,7 +72,7 @@ void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer)
   }
 }
 
-void XGUI_Displayer::display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS, 
+void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, 
                              bool isShading, bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
@@ -90,7 +95,7 @@ void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)
   Handle(AIS_InteractiveContext) aContext = AISContext();
   if (aContext.IsNull())
     return;
-  boost::shared_ptr<GeomAPI_AISObject> anObject = myResult2AISObjectMap[theObject];
+  AISObjectPtr anObject = myResult2AISObjectMap[theObject];
   if (anObject) {
     Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
     if (!anAIS.IsNull()) {
@@ -105,77 +110,28 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
   if (!isVisible(theObject))
     return;
 
-  Handle(AIS_InteractiveObject) aAISIO;
-  boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+  AISObjectPtr aAISObj = getAISObject(theObject);
+  Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+
   GeomPresentablePtr aPrs = boost::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
   if (aPrs) {
-    boost::shared_ptr<GeomAPI_AISObject> aAIS_Obj = aPrs->getAISObject(aAISObj);
-    if (aAISObj && !aAIS_Obj) {
+    AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
+    if (!aAIS_Obj) {
       erase(theObject, isUpdateViewer);
       return;
     }
-    aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
-  } else {
-    ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-    if (aResult) {
-      boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
-      if (aShapePtr) {
-        Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(
-            aAISObj->impl<Handle(AIS_InteractiveObject)>());
-        if (!aAISShape.IsNull()) {
-          aAISShape->Set(aShapePtr->impl<TopoDS_Shape>());
-          aAISIO = aAISShape;
-        }
-      }
+    if (aAIS_Obj != aAISObj) {
+      myResult2AISObjectMap[theObject] = aAIS_Obj;
     }
+    aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
   }
+
   if (!aAISIO.IsNull()) {
     Handle(AIS_InteractiveContext) aContext = AISContext();
     if (aContext.IsNull())
       return;
     aContext->Redisplay(aAISIO, isUpdateViewer);
-    //if (aContext->HasOpenedContext()) {
-    //  aContext->Load(aAISIO, -1, true/*allow decomposition*/);
-    //}
-  }
-}
-
-void XGUI_Displayer::activateInLocalContext(ObjectPtr theResult, const std::list<int>& theModes,
-                                            const bool isUpdateViewer)
-{
-  Handle(AIS_InteractiveContext) aContext = AISContext();
-  if (aContext.IsNull())
-    return;
-  // Open local context if there is no one
-  if (!aContext->HasOpenedContext()) {
-    aContext->ClearCurrents(false);
-    //aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
-    aContext->OpenLocalContext();
-    aContext->NotUseDisplayedObjects();
   }
-  // display or redisplay presentation
-  Handle(AIS_InteractiveObject) anAIS;
-  if (isVisible(theResult)) {
-    boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theResult];
-    if (anObj)
-      anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
-  }
-
-  // Activate selection of objects from prs
-  if (!anAIS.IsNull()) {
-    aContext->ClearSelected(false);  // ToCheck
-    //aContext->upClearSelected(false); // ToCheck
-    aContext->Load(anAIS, -1, true/*allow decomposition*/);
-    aContext->Deactivate(anAIS);
-
-    std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
-    for (; anIt != aLast; anIt++) {
-      aContext->Activate(anAIS, (*anIt));
-    }
-  }
-
-  if (isUpdateViewer)
-    updateViewer();
 }
 
 void XGUI_Displayer::deactivate(ObjectPtr theObject)
@@ -185,22 +141,30 @@ void XGUI_Displayer::deactivate(ObjectPtr theObject)
     if (aContext.IsNull())
       return;
 
-    boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theObject];
+    AISObjectPtr anObj = myResult2AISObjectMap[theObject];
     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
     aContext->Deactivate(anAIS);
   }
 }
 
-void XGUI_Displayer::activate(ObjectPtr theObject)
+void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
 {
   if (isVisible(theObject)) {
     Handle(AIS_InteractiveContext) aContext = AISContext();
     if (aContext.IsNull())
       return;
 
-    boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theObject];
+    AISObjectPtr anObj = myResult2AISObjectMap[theObject];
     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
-    aContext->Activate(anAIS);
+    if (aContext->HasOpenedContext()) {
+      aContext->Load(anAIS, -1, true);
+    }
+    if (theModes.size() > 0) {
+      foreach(int aMode, theModes) {
+        aContext->Activate(anAIS, aMode);
+      }
+    } else 
+      aContext->Activate(anAIS);
   }
 }
 
@@ -212,7 +176,7 @@ bool XGUI_Displayer::isActive(ObjectPtr theObject) const
   if (!isVisible(theObject))
     return false;
     
-  boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap.at(theObject);
+  AISObjectPtr anObj = myResult2AISObjectMap.at(theObject);
   Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
 
   TColStd_ListOfInteger aModes;
@@ -268,20 +232,27 @@ void XGUI_Displayer::setSelected(const QList<ObjectPtr>& theResults, const bool
   aContext->ClearSelected();
   foreach(ObjectPtr aResult, theResults)
   {
-    if (myResult2AISObjectMap.find(aResult) == myResult2AISObjectMap.end())
-      continue;
-
-    boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[aResult];
-    if (anObj) {
+    if (isVisible(aResult)) {
+      AISObjectPtr anObj = myResult2AISObjectMap[aResult];
       Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
       if (!anAIS.IsNull())
-        aContext->AddOrRemoveSelected(anAIS, false);
+        aContext->SetSelected(anAIS, false);
     }
   }
   if (isUpdateViewer)
     updateViewer();
 }
 
+
+void XGUI_Displayer::clearSelected()
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext) {
+    aContext->UnhilightCurrents(false);
+    aContext->ClearSelected();
+  }
+}
+
 void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) ic = AISContext();
@@ -291,7 +262,7 @@ void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
    ResultToAISMap::iterator aIt;
    for (aIt = myResult2AISObjectMap.begin(); aIt != myResult2AISObjectMap.end(); aIt++) {
      // erase an object
-     boost::shared_ptr<GeomAPI_AISObject> aAISObj = (*aIt).second;
+     AISObjectPtr aAISObj = (*aIt).second;
      Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
      if (!anIO.IsNull())
       ic->Remove(anIO, false);
@@ -313,7 +284,7 @@ void XGUI_Displayer::eraseDeletedResults(const bool isUpdateViewer)
   for (; aFIt != aFLast; aFIt++) {
     ObjectPtr aFeature = (*aFIt).first;
     if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) {
-      boost::shared_ptr<GeomAPI_AISObject> anObj = (*aFIt).second;
+      AISObjectPtr anObj = (*aFIt).second;
       if (!anObj)
         continue;
       Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
@@ -352,21 +323,27 @@ void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
   closeAllContexts(true);
 }
 
-boost::shared_ptr<GeomAPI_AISObject> XGUI_Displayer::getAISObject(ObjectPtr theObject) const
+AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
 {
-  boost::shared_ptr<GeomAPI_AISObject> anIO;
+  AISObjectPtr anIO;
   if (myResult2AISObjectMap.find(theObject) != myResult2AISObjectMap.end())
     anIO = (myResult2AISObjectMap.find(theObject))->second;
   return anIO;
 }
 
-ObjectPtr XGUI_Displayer::getObject(Handle(AIS_InteractiveObject) theIO) const
+ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
+{
+  Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
+  return getObject(aRefAIS);
+}
+
+ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
 {
   ObjectPtr aFeature;
   ResultToAISMap::const_iterator aFIt = myResult2AISObjectMap.begin(), aFLast =
       myResult2AISObjectMap.end();
   for (; aFIt != aFLast && !aFeature; aFIt++) {
-    boost::shared_ptr<GeomAPI_AISObject> anObj = (*aFIt).second;
+    AISObjectPtr anObj = (*aFIt).second;
     if (!anObj)
       continue;
     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
@@ -399,7 +376,7 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
   return myWorkshop->viewer()->AISContext();
 }
 
-void XGUI_Displayer::display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate)
+void XGUI_Displayer::display(AISObjectPtr theAIS, bool isUpdate)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
@@ -407,7 +384,7 @@ void XGUI_Displayer::display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool i
     aContext->Display(anAISIO, isUpdate);
 }
 
-void XGUI_Displayer::erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate)
+void XGUI_Displayer::erase(AISObjectPtr theAIS, const bool isUpdate)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
@@ -416,8 +393,7 @@ void XGUI_Displayer::erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bo
   }
 }
 
-void XGUI_Displayer::activateObjectsOutOfContext(const std::list<int>& theModes, 
-                                                 Handle(SelectMgr_Filter) theFilter)
+void XGUI_Displayer::activateObjectsOutOfContext(const QIntList& theModes)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
   // Open local context if there is no one
@@ -425,13 +401,19 @@ void XGUI_Displayer::activateObjectsOutOfContext(const std::list<int>& theModes,
     return;
 
   aContext->UseDisplayedObjects();
-  std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
-  for (; anIt != aLast; anIt++) {
-    aContext->ActivateStandardMode((TopAbs_ShapeEnum)(*anIt));
+  ResultToAISMap::iterator aIt;
+  Handle(AIS_InteractiveObject) anAISIO;
+  for (aIt = myResult2AISObjectMap.begin(); aIt != myResult2AISObjectMap.end(); aIt++) {
+    anAISIO = (*aIt).second->impl<Handle(AIS_InteractiveObject)>();
+    aContext->Load(anAISIO, -1, true);
+    if (theModes.size() == 0)
+      aContext->Activate(anAISIO);
+    else {
+      foreach(int aMode, theModes) {
+        aContext->Activate(anAISIO, aMode);
+      }
+    }
   }
-
-  if (!theFilter.IsNull())
-    aContext->AddFilter(theFilter);
 }
 
 
@@ -442,7 +424,6 @@ void XGUI_Displayer::deactivateObjectsOutOfContext()
   if (!aContext->HasOpenedContext()) 
     return;
 
-  aContext->RemoveFilters();
   aContext->NotUseDisplayedObjects();
 }
 
@@ -456,7 +437,7 @@ void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bo
   if (aContext.IsNull())
     return;
 
-  boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+  AISObjectPtr aAISObj = getAISObject(theObject);
   if (!aAISObj)
     return;
 
@@ -464,6 +445,27 @@ void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bo
   aContext->SetDisplayMode(aAISIO, theMode, toUpdate);
 }
 
+void XGUI_Displayer::setSelectionModes(const QIntList& theModes)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
+  if (!aContext->HasOpenedContext())
+    return;
+  // Clear previous mode
+  const TColStd_ListOfInteger& aModes = aContext->ActivatedStandardModes();
+  if (!aModes.IsEmpty()) {
+    TColStd_ListOfInteger aMModes;
+    aMModes.Assign(aModes);
+    TColStd_ListIteratorOfListOfInteger it(aMModes);
+    for(; it.More(); it.Next()) {
+      aContext->DeactivateStandardMode((TopAbs_ShapeEnum)it.Value());
+    }
+  }
+  foreach(int aMode, theModes) {
+    aContext->ActivateStandardMode((TopAbs_ShapeEnum)aMode);
+  }
+}
 
 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
 {
@@ -471,7 +473,7 @@ XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) con
   if (aContext.IsNull())
     return NoMode;
 
-  boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+  AISObjectPtr aAISObj = getAISObject(theObject);
   if (!aAISObj)
     return NoMode;
 
@@ -479,3 +481,18 @@ XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) con
   return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
 }
 
+void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
+  aContext->AddFilter(theFilter);
+}
+
+void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (aContext.IsNull())
+    return;
+  aContext->RemoveFilter(theFilter);
+}
index 9552fd6d365460379d36709319878e0b83dd3716..7f117fea5e0a586366f3423a7144b0cd4ba85f64 100644 (file)
@@ -45,10 +45,6 @@ class XGUI_EXPORT XGUI_Displayer
   /// Destructor
   virtual ~XGUI_Displayer();
 
-  /// Set AIS_InteractiveContext object in case if it was changed
-  /// or can not be initialized in constructor
-  void setAISContext(const Handle(AIS_InteractiveContext)& theAIS);
-
   /// Returns the feature visibility state.
   /// \param theFeature a feature instance
   bool isVisible(ObjectPtr theObject) const;
@@ -60,20 +56,7 @@ class XGUI_EXPORT XGUI_Displayer
   void display(ObjectPtr theObject, bool isUpdateViewer = true);
 
   /// Display the given AIS object. To hide this object use corresponde erase method
-  void display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate = true);
-
-  /// Redisplay the shape and activate selection of sub-shapes
-  /// \param theFeature a feature instance
-  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
-  //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
-
-  /// Display the shape and activate selection of sub-shapes
-  /// \param theFeature a feature instance
-  /// \param theShape a shape
-  /// \param theMode a list of local selection modes
-  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
-  void activateInLocalContext(ObjectPtr theFeature, const std::list<int>& theModes,
-                              const bool isUpdateViewer = true);
+  void display(AISObjectPtr theAIS, bool isUpdate = true);
 
   /// Stop the current selection and color the given features to the selection color
   /// \param theFeatures a list of features to be disabled
@@ -89,13 +72,17 @@ class XGUI_EXPORT XGUI_Displayer
    */
   void setSelected(const QList<ObjectPtr>& theFeatures, bool isUpdateViewer = true);
 
+
+  /// Un select all objects
+  void clearSelected();
+
   /// Erase the feature and a shape.
   /// \param theFeature a feature instance
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
 
   /// Erase the given AIS object displayed by corresponded display method
-  void erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate = true);
+  void erase(AISObjectPtr theAIS, const bool isUpdate = true);
 
   /// Erase all presentations
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
@@ -105,40 +92,53 @@ class XGUI_EXPORT XGUI_Displayer
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
   void eraseDeletedResults(const bool isUpdateViewer = true);
 
+  /// Opens local context. Does nothing if it is already opened.
   void openLocalContext();
 
   /// Deactivates selection of sub-shapes
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
   void closeLocalContexts(const bool isUpdateViewer = true);
 
+  /*
+  * Set modes of selections. Selection mode has to be defined by TopAbs_ShapeEnum.
+  * It doesn't manages a local context
+  * \param theModes - list of selection modes. If the list is empty then all selectoin modes will be cleared.
+  */
+  void setSelectionModes(const QIntList& theModes);
+
+  void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
+  void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
   /// Updates the viewer
   void updateViewer();
 
   /// Searches the interactive object by feature
   /// \param theFeature the feature or NULL if it not visualized
   /// \return theIO an interactive object
-  boost::shared_ptr<GeomAPI_AISObject> getAISObject(ObjectPtr theFeature) const;
+  AISObjectPtr getAISObject(ObjectPtr theFeature) const;
 
   /// Searches the feature by interactive object
   /// \param theIO an interactive object
   /// \return feature the feature or NULL if it not visualized
-  ObjectPtr getObject(Handle(AIS_InteractiveObject) theIO) const;
+  ObjectPtr getObject(const AISObjectPtr& theIO) const;
+  ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
 
   /// Deactivates the given object (not allow selection)
   void deactivate(ObjectPtr theFeature);
 
   /// Activates the given object (it can be selected)
-  void activate(ObjectPtr theFeature);
+  /// \param theModes - modes on which it has to be activated (can be empty)
+  void activate(ObjectPtr theFeature, const QIntList& theModes);
 
   /// Returns true if the given object can be selected
   bool isActive(ObjectPtr theObject) const;
 
   /// Activates in local context displayed outside of the context.
-  /// \param theModes - selection modes to activate
-  /// \param theFilter - filter for selection
-  void activateObjectsOutOfContext(const std::list<int>& theModes, 
-                                   Handle(SelectMgr_Filter) theFilter);
+  /// \param theModes - modes on which it has to be activated (can be empty)
+  void activateObjectsOutOfContext(const QIntList& theModes);
 
+  /// Activates in local context displayed outside of the context.
   void deactivateObjectsOutOfContext();
 
   /// Sets display mode for the given object if this object is displayed
@@ -164,7 +164,7 @@ class XGUI_EXPORT XGUI_Displayer
   /// \param theAIS AIS presentation
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
   /// Returns true if the Feature succesfully displayed
-  void display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isShading,
+  void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
                bool isUpdateViewer = true);
 
   /// Display the shape and activate selection of sub-shapes
@@ -173,7 +173,7 @@ class XGUI_EXPORT XGUI_Displayer
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
   /// \returns true if the presentation is created
   //bool redisplay(ObjectPtr theObject,
-  //               boost::shared_ptr<GeomAPI_AISObject> theAIS, 
+  //               AISObjectPtr theAIS, 
   //               const bool isUpdateViewer = true);
 
   /** Redisplay the shape if it was displayed
@@ -185,7 +185,7 @@ class XGUI_EXPORT XGUI_Displayer
  protected:
   XGUI_Workshop* myWorkshop;
 
-  typedef std::map<ObjectPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
+  typedef std::map<ObjectPtr, AISObjectPtr> ResultToAISMap;
   ResultToAISMap myResult2AISObjectMap;
 };
 
index 7e9694ebbbf1e74df9747fb2d0649abd067afe15..6a3c81a9f35b5ccda61750026914f4970ff75231 100644 (file)
@@ -7,6 +7,11 @@
 #include "XGUI_ViewerProxy.h"
 #include "XGUI_SelectionMgr.h"
 #include "XGUI_Selection.h"
+#include "XGUI_OperationMgr.h"
+#include "XGUI_Displayer.h"
+
+#include <AIS_Shape.hxx>
+
 
 XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
     : ModuleBase_IWorkshop(theWorkshop),
@@ -14,23 +19,79 @@ XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
 {
   XGUI_SelectionMgr* aSelector = myWorkshop->selector();
   connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
+  
+  XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
+
+  connect(anOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)), 
+    this, SIGNAL(operationStarted(ModuleBase_Operation*)));
+  connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), 
+    this, SIGNAL(operationStopped(ModuleBase_Operation*)));
+
+  myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(this);
 }
 
 XGUI_ModuleConnector::~XGUI_ModuleConnector()
 {
+  myDocumentShapeFilter.Nullify();
 }
 
-Handle(AIS_InteractiveContext) XGUI_ModuleConnector::AISContext() const
+ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
 {
-  return myWorkshop->viewer()->AISContext();
+  return myWorkshop->selector()->selection();
 }
 
-QList<ObjectPtr> XGUI_ModuleConnector::selectedObjects() const
+ModuleBase_IModule* XGUI_ModuleConnector::module() const
 {
-  return myWorkshop->selector()->selection()->selectedObjects();
+  return myWorkshop->module();
 }
 
-ModuleBase_IModule* XGUI_ModuleConnector::module() const
+ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
 {
-  return myWorkshop->module();
+  return myWorkshop->viewer();
+}
+
+ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
+{
+  return myWorkshop->operationMgr()->currentOperation();
+}
+
+
+void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
+{
+  XGUI_Displayer* aDisp = myWorkshop->displayer();
+  aDisp->openLocalContext();
+  // Convert shape types to selection types
+  QIntList aModes;
+  foreach(int aType, theTypes) {
+    aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
+  }
+  aDisp->activateObjectsOutOfContext(aModes);
+  //TODO: We have to open Local context because at neutral point filters don't work (bug 25340)
+  aDisp->addSelectionFilter(myDocumentShapeFilter);
 }
+
+void XGUI_ModuleConnector::deactivateSubShapesSelection()
+{
+  XGUI_Displayer* aDisp = myWorkshop->displayer();
+  // The document limitation selection has to be only during operation
+  aDisp->removeSelectionFilter(myDocumentShapeFilter);
+  aDisp->closeLocalContexts(false);
+}
+
+AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
+{
+  XGUI_Displayer* aDisp = myWorkshop->displayer();
+  return aDisp->getAISObject(theObject);
+}
+
+ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
+{
+  XGUI_Displayer* aDisp = myWorkshop->displayer();
+  return aDisp->getObject(theAIS);
+}
+
+void XGUI_ModuleConnector::setSelected(const QList<ObjectPtr>& theFeatures)
+{
+  XGUI_Displayer* aDisp = myWorkshop->displayer();
+  aDisp->setSelected(theFeatures);
+}
\ No newline at end of file
index 3423a55f0cf733c1779a075b64e44a4e03b59c87..8a869f1d0db026bc03fafe78162c78df67dad92e 100644 (file)
@@ -8,6 +8,7 @@
 #include "XGUI.h"
 #include <ModuleBase_Definitions.h>
 #include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_ViewerFilters.h>
 
 class Handle_AIS_InteractiveContext;
 class XGUI_Workshop;
@@ -24,17 +25,42 @@ Q_OBJECT
 
   virtual ~XGUI_ModuleConnector();
 
-  //! Returns AIS_InteractiveContext from current OCCViewer
-  virtual Handle(AIS_InteractiveContext) AISContext() const;
-
   //! Returns list of currently selected data objects
-  virtual QList<ObjectPtr> selectedObjects() const;
+  virtual ModuleBase_ISelection* selection() const;
+
+  /// Activate sub-shapes selection (opens local context if it was not opened)
+  /// Types has to be dined according to TopAbs_ShapeEnum
+  virtual void activateSubShapesSelection(const QIntList& theTypes);
+
+  /// Deactivate sub-shapes selection (closes local context)
+  virtual void deactivateSubShapesSelection();
 
   //! Returns instance of loaded module
   virtual ModuleBase_IModule* module() const;
 
- private:
+  //! Returns current viewer
+  virtual ModuleBase_IViewer* viewer() const;
+
+  //! Returns currently active operation
+  virtual ModuleBase_Operation* currentOperation() const;
+
+  //! Returns AIS opbject by data object
+  virtual AISObjectPtr findPresentation(const ObjectPtr& theObject) const;
+
+  //! Returns data object by AIS
+  virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
+
+  //! Select features clearing previous selection. 
+  //! If the list is empty then selection will be cleared
+  virtual void setSelected(const QList<ObjectPtr>& theFeatures);
+
+  XGUI_Workshop* workshop() const { return myWorkshop; }
+
+private:
   XGUI_Workshop* myWorkshop;
+
+  /// A filter which provides selection within a current document or whole PartSet
+  Handle(ModuleBase_ShapeDocumentFilter) myDocumentShapeFilter;
 };
 
 #endif
index 04559839683a23f29219419d68b8b5a8652acabe..f93cb6b6a22a0b2f74a10be0d71596484de0ac36 100644 (file)
@@ -13,8 +13,6 @@
 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent)
     : QObject(theParent)
 {
-  // listen to Escape signal to stop the current operation
-  qApp->installEventFilter(this);
 }
 
 XGUI_OperationMgr::~XGUI_OperationMgr()
@@ -68,8 +66,8 @@ bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent)
 {
   if (theEvent->type() == QEvent::KeyRelease) {
     QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
-    if(aKeyEvent && onKeyReleased(aKeyEvent)) {
-      return true;
+    if(aKeyEvent) {
+      return onKeyReleased(aKeyEvent);
     }
   }
   return QObject::eventFilter(theObject, theEvent);
@@ -83,10 +81,8 @@ bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
   myOperations.append(theOperation);
 
   connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
-  connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
+  connect(theOperation, SIGNAL(started()), this, SLOT(onOperationStarted()));
   connect(theOperation, SIGNAL(resumed()), this, SIGNAL(operationResumed()));
-  connect(theOperation, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), this,
-          SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)));
 
   theOperation->start();
   onValidateOperation();
@@ -187,6 +183,12 @@ bool XGUI_OperationMgr::canAbortOperation()
   return true;
 }
 
+void XGUI_OperationMgr::onOperationStarted()
+{
+  ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
+  emit operationStarted(aSenderOperation);
+}
+
 void XGUI_OperationMgr::onOperationStopped()
 {
   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
@@ -222,15 +224,8 @@ bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent)
   ModuleBase_Operation* anOperation = currentOperation();
   bool isAccepted = true;
   switch (theEvent->key()) {
-    case Qt::Key_Escape: {
-      onAbortOperation();
-    }
-      break;
     case Qt::Key_Return:
     case Qt::Key_Enter: {
-      if(anOperation) {
-         anOperation->activateNextToCurrentWidget();
-      }
       commitOperation();
     }
       break;
@@ -244,9 +239,3 @@ bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent)
   return isAccepted;
 }
 
-void XGUI_OperationMgr::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
-{
-  ModuleBase_Operation* anOperation = currentOperation();
-  if (anOperation)
-    anOperation->onWidgetActivated(theWidget);
-}
index ee8ff1f938643e9284d52e5e26c3aba0d87d8005..25a155617e1558996221e6e5c00facc2a590b954 100644 (file)
@@ -70,7 +70,7 @@ Q_OBJECT
 
 signals:
   /// Signal about an operation is started. It is emitted after the start() of operation is done.
-  void operationStarted();
+  void operationStarted(ModuleBase_Operation* theOperation);
   /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
   /// \param theOperation a stopped operation
   void operationStopped(ModuleBase_Operation* theOperation);
@@ -78,9 +78,6 @@ signals:
   void operationResumed();
   /// Signal is emitted after the validate methods calls.
   void operationValidated(bool);
-  /// Signal about the necessety of the next widget activating
-  /// \param theWidget the model widget
-  void activateNextWidget(ModuleBase_ModelWidget* theWidget);
 
  protected:
 
@@ -108,14 +105,11 @@ signals:
   /// \param theEvent the mouse event
   bool onKeyReleased(QKeyEvent* theEvent);
 
-  /// SLOT, that reacts to the widget activation
-  /// \param theWidget an activated widget
-  void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
-
   protected slots:
   /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
   /// If there is a suspended operation, restart it.
   void onOperationStopped();
+  void onOperationStarted();
 
  private:
   typedef QList<ModuleBase_Operation*> Operations;  ///< definition for a list of operations
index 81e0282ee7922bd0ac86aeb672517cf4e1abf85d..4d91ceb34f95f03fff27d739069b10f19ec2c060 100644 (file)
@@ -13,6 +13,7 @@
 #include <QLayout>
 #include <QApplication>
 #include <QDialogButtonBox>
+#include <QPushButton>
 
 const QString XGUI_Preferences::VIEWER_SECTION = "Viewer";
 const QString XGUI_Preferences::MENU_SECTION = "Menu";
@@ -40,7 +41,7 @@ bool XGUI_Preferences::editPreferences(XGUI_Prefs& theModified)
   return false;
 }
 
-void XGUI_Preferences::updateCustomProps()
+void XGUI_Preferences::updateConfigByResources()
 {
   Config_Properties aProps = Config_PropManager::getProperties();
   Config_Properties::iterator aIt;
@@ -48,8 +49,30 @@ void XGUI_Preferences::updateCustomProps()
     Config_Prop* aProp = (*aIt);
     QString aVal = myResourceMgr->stringValue(QString(aProp->section().c_str()),
                                               QString(aProp->name().c_str()));
-    if (!aVal.isNull())
+    if (!aVal.isEmpty()) {
       aProp->setValue(aVal.toStdString());
+    }
+  }
+}
+
+void XGUI_Preferences::updateResourcesByConfig()
+{
+  Config_Properties aProps = Config_PropManager::getProperties();
+  Config_Properties::iterator aIt;
+  for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
+    Config_Prop* aProp = (*aIt);
+    myResourceMgr->setValue(QString(aProp->section().c_str()), QString(aProp->name().c_str()),
+                            QString(aProp->value().c_str()));
+  }
+}
+
+void XGUI_Preferences::resetConfig()
+{
+  Config_Properties aProps = Config_PropManager::getProperties();
+  Config_Properties::iterator aIt;
+  for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
+    Config_Prop* aProp = (*aIt);
+    aProp->setValue(aProp->defaultValue());
   }
 }
 
@@ -63,9 +86,9 @@ void XGUI_Preferences::loadCustomProps()
     QStringList aParams = myResourceMgr->parameters(aSection);
     foreach (QString aParam, aParams)
     {
-      Config_PropManager::registerProp(aSection.toStdString(), aParam.toStdString(), "",
-                                       Config_Prop::Disabled,
-                                       myResourceMgr->stringValue(aSection, aParam).toStdString());
+      Config_Prop* aProp = Config_PropManager::registerProp(aSection.toStdString(),
+                                       aParam.toStdString(), "", Config_Prop::Disabled);
+      aProp->setValue(myResourceMgr->stringValue(aSection, aParam).toStdString());
     }
   }
 }
@@ -150,8 +173,13 @@ XGUI_PreferencesDlg::XGUI_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget*
   setFocusProxy(myPreferences);
   myPreferences->setFrameStyle(QFrame::Box | QFrame::Sunken);
 
-  QDialogButtonBox* aBtnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+  QDialogButtonBox* aBtnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
+                                                   QDialogButtonBox::Reset,
                                                    Qt::Horizontal, this);
+  QPushButton* aDefaultButton = aBtnBox->button(QDialogButtonBox::Reset);
+  aDefaultButton->setText(tr("Default"));
+  connect(aDefaultButton, SIGNAL(clicked()), this, SLOT(onDefault()));
+
   main->addWidget(aBtnBox);
   connect(aBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
   connect(aBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
@@ -230,7 +258,7 @@ void XGUI_PreferencesDlg::accept()
   myIsChanged = true;
 
   // Save custom properties
-  XGUI_Preferences::updateCustomProps();
+  XGUI_Preferences::updateConfigByResources();
   QDialog::accept();
 }
 
@@ -239,6 +267,22 @@ void XGUI_PreferencesDlg::modified(XGUI_Prefs& theModified) const
   theModified = myPreferences->modified();
 }
 
+void XGUI_PreferencesDlg::onDefault()
+{
+  // reset main resources
+#ifdef WIN32
+  QtxResourceMgr::WorkingMode aPrev =
+      myPreferences->resourceMgr()->setWorkingMode(QtxResourceMgr::IgnoreUserValues);
+  myPreferences->retrieve();
+  myPreferences->resourceMgr()->setWorkingMode(aPrev);
+#endif
+  // reset plugin's resources
+  XGUI_Preferences::resetConfig();
+  XGUI_Preferences::updateResourcesByConfig();
+
+  myPreferences->retrieve();
+}
+
 //**********************************************************
 //**********************************************************
 //**********************************************************
index a6fbc8a2b2faa2675bb944ff7506e5b531b43745..3241d41423675f2b423629db3e2b2b13be102c0c 100644 (file)
@@ -35,8 +35,15 @@ class XGUI_EXPORT XGUI_Preferences
   /// It is used in case of necessity to define external resource manager (not NewGeom)
   static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
 
-  /// Updates properties defined by module from SUIT_ResourceMgr to Config_PropManager
-  static void updateCustomProps();
+  /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
+  static void updateConfigByResources();
+
+  /// Updates SUIT_ResourceMgr values by Config_PropManager properties
+  /// \param theUpdateOnlyInvalid flag to update only invalid values, if it is false, all are updated
+  static void updateResourcesByConfig();
+
+  /// Set default values to the Config_PropManager properties
+  static void resetConfig();
 
   /// Loads properties defined by module to Config_PropManager
   static void loadCustomProps();
@@ -97,6 +104,9 @@ Q_OBJECT
  public slots:
   virtual void accept();
 
+protected slots:
+  void onDefault();
+
  private:
    /// Create editors for aplication properties
    void createEditors();
index 9a5877369ba5a51254ba151fc696429a48688a00..94712d811a10ed6f52df4a2fb43c0a8586d70d40 100644 (file)
@@ -23,7 +23,8 @@
 #endif
 
 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
-    : QDockWidget(theParent)
+    : ModuleBase_IPropertyPanel(theParent), 
+    myActiveWidget(NULL)
 {
   this->setWindowTitle(tr("Property Panel"));
   QAction* aViewAct = this->toggleViewAction();
@@ -56,6 +57,7 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
   aBtn->setToolTip(tr("Cancel"));
   aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
   aBtn->setFlat(true);
+  aBtn->setShortcut(QKeySequence(Qt::Key_Escape));
   aBtnLay->addWidget(aBtn);
 
   myCustomWidget = new QWidget(aContent);
@@ -71,11 +73,13 @@ void XGUI_PropertyPanel::cleanContent()
 {
   myWidgets.clear();
   qDeleteAll(myCustomWidget->children());
+  myActiveWidget = NULL;
 }
 
 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
 {
   myWidgets = theWidgets;
+  int aS = myWidgets.size();
   if (theWidgets.empty()) return;
 
   QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast =
@@ -84,9 +88,9 @@ void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& t
     connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
 
     connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this,
-            SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
+            SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
     connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
-            this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)));
+            this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
 
     ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
     if (aPointWidget)
@@ -125,11 +129,11 @@ void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
     eachWidget->setFeature(theFeature);
     eachWidget->restoreValue();
   }
-  // the repaint is used here to immediatelly react in GUI to the values change.
+  // the repaint is used here to immediately react in GUI to the values change.
   repaint();
 }
 
-void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
+void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
 {
   ModuleBase_ModelWidget* aNextWidget = 0;
   QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
@@ -142,7 +146,16 @@ void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
     }
     isFoundWidget = (*anIt) == theWidget;
   }
-  emit widgetActivated(aNextWidget);
+  // Normaly focusTo is enough to activate widget
+  // here is a special case on mouse click in the viewer
+  if(aNextWidget == NULL) {
+    activateWidget(NULL);
+  }
+}
+
+void XGUI_PropertyPanel::activateNextWidget()
+{
+  activateNextWidget(myActiveWidget);
 }
 
 void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
@@ -150,3 +163,15 @@ void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
   QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
   anOkBtn->setEnabled(isEnabled);
 }
+
+void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
+{
+  if(myActiveWidget) {
+    myActiveWidget->setHighlighted(false);
+  }
+  if(theWidget) {
+    theWidget->setHighlighted(true);
+  }
+  myActiveWidget = theWidget;
+  emit widgetActivated(theWidget);
+}
index a660b5484bf27c4a1bff6301da766f4f4ed39ced..04c4d1ed3c5521bfe40ab28368bc5de21968f906 100644 (file)
 #include "XGUI.h"
 
 #include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_IPropertyPanel.h>
 
-#include <QDockWidget>
 #include <QList>
 
 class QKeyEvent;
 class QVBoxLayout;
 
-class XGUI_EXPORT XGUI_PropertyPanel : public QDockWidget
+class XGUI_EXPORT XGUI_PropertyPanel : public ModuleBase_IPropertyPanel
 {
 Q_OBJECT
  public:
@@ -28,39 +28,50 @@ Q_OBJECT
   /// Returns main widget of the property panel, which children will be created
   /// by WidgetFactory using the XML definition
   QWidget* contentWidget();
+
   /// Brings back all widget created by widget factory for signal/slot
   /// connections and further processing
   void setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets);
+
   /// Returns all property panel's widget created by WidgetFactory
-  const QList<ModuleBase_ModelWidget*>& modelWidgets() const;
+  virtual const QList<ModuleBase_ModelWidget*>& modelWidgets() const;
+
   /// Removes all widgets in the widget area of the property panel
   void cleanContent();
 
+  /// Returns currently active widget
+  virtual ModuleBase_ModelWidget* activeWidget() const { return myActiveWidget; }
+
+  /// Activate the next widget in the property panel
+  /// \param theWidget a widget. The next widget should be activated
+  virtual void activateNextWidget(ModuleBase_ModelWidget* theWidget);
+
+  /// Activate the next from current widget in the property panel
+  virtual void activateNextWidget();
+
  public slots:
   void updateContentWidget(FeaturePtr theFeature);
-  /// slot to activate the next widget in the property panel
-  /// \param theWidget a widget. The next widget should be activated
-  void onActivateNextWidget(ModuleBase_ModelWidget* theWidget);
   // Enables / disables "ok" ("accept") button
   void setAcceptEnabled(bool);
 
-signals:
-  /// The signal about key release on the control, that corresponds to the attribute
-  /// \param theEvent key release event
-  void keyReleased(QKeyEvent* theEvent);
-  /// The signal about the widget activation
-  /// \param theWidget the activated widget
-  void widgetActivated(ModuleBase_ModelWidget* theWidget);
+ protected slots:
+  // Makes the given widget active, highlights it and removes
+  // highlighting from the previous active widget
+  // emits widgetActivated(theWidget) signal
+  void activateWidget(ModuleBase_ModelWidget* theWidget);
 
+ signals:
   /// Signal about the point 2d set to the feature
   /// \param the feature
   /// \param the attribute of the feature
   void storedPoint2D(ObjectPtr theFeature, const std::string& theAttribute);
 
+
  private:
   QWidget* myCustomWidget;
   QList<ModuleBase_ModelWidget*> myWidgets;
   QVBoxLayout* myMainLayout;
+  ModuleBase_ModelWidget* myActiveWidget;
 };
 
 #endif /* XGUI_PROPERTYPANEL_H_ */
index f6cf5857bf9b7d88aca08791ea7e0b7d3fd28469..1ed0d5f320cf419ca0258aecee3079c9096de4a8 100644 (file)
@@ -28,7 +28,11 @@ XGUI_AbstractRubberBand::XGUI_AbstractRubberBand(QWidget* theParent)
   setAttribute(Qt::WA_TransparentForMouseEvents);\r
 #ifndef WIN32\r
   setAttribute(Qt::WA_NoSystemBackground);\r
-#endif //WIN32\r  setAttribute(Qt::WA_WState_ExplicitShowHide);\r  setVisible(false);\r  theParent->installEventFilter(this);\r  setGeometry(QRect(QPoint(0, 0), theParent->size()));\r
+#endif //WIN32\r
+  setAttribute(Qt::WA_WState_ExplicitShowHide);\r
+  setVisible(false);\r
+  theParent->installEventFilter(this);\r
+  setGeometry(QRect(QPoint(0, 0), theParent->size()));\r
 }\r
 \r
 /*!\r
index 0055714b73e4078e6898804484a0bd727e4d6ad9..0c36dada2d5113a860c4ca6e388abb3b0bd2a4f5 100644 (file)
@@ -7,7 +7,7 @@
 #include <QStringList>
 
 class QMainWindow;
-class XGUI_SalomeViewer;
+class ModuleBase_IViewer;
 
 /**
  * An interface which provides a connection of XGUI functionality 
@@ -67,8 +67,16 @@ class XGUI_EXPORT XGUI_SalomeConnector
   //! Returns list of nested actions according to the given command ID
   virtual QStringList nestedActions(const QString& theId) const = 0;
 
+  //! Set the document kind of the action by the given command Id
+  //! \param theId - the command ID
+  //! \param theKind - the document kind
+  virtual void setDocumentKind(const QString& theId, const QString& theKind) = 0;
+
+  //! Returns the document kind of the action by the given command ID
+  virtual QString documentKind(const QString& theId) const = 0;
+
   //! Returns interface to Salome viewer
-  virtual XGUI_SalomeViewer* viewer() const = 0;
+  virtual ModuleBase_IViewer* viewer() const = 0;
 
   virtual void createPreferences() = 0;
 };
diff --git a/src/XGUI/XGUI_SalomeViewer.h b/src/XGUI/XGUI_SalomeViewer.h
deleted file mode 100644 (file)
index 1b3de1d..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-#ifndef XGUI_SALOMEVIEWER_H
-#define XGUI_SALOMEVIEWER_H
-
-#include "XGUI.h"
-
-#include <QObject>
-#include <AIS_InteractiveContext.hxx>
-#include <V3d_View.hxx>
-
-class QMouseEvent;
-class QKeyEvent;
-class QContextMenuEvent;
-
-/**
- * A Base object for definition of connector object to
- * Salome Viewer. Reimplemented in NewGeom_SalomeViewer class
- */
-class XGUI_EXPORT XGUI_SalomeViewer : public QObject
-{
-Q_OBJECT
- public:
-  XGUI_SalomeViewer(QObject* theParent)
-      : QObject(theParent)
-  {
-  }
-
-  //! Returns AIS_InteractiveContext from current OCCViewer
-  virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
-
-  //! Retrurns V3d_Vioewer from current viewer
-  virtual Handle(V3d_Viewer) v3dViewer() const = 0;
-
-  //! Returns Vsd_View object from currently active view window
-  virtual Handle(V3d_View) activeView() const = 0;
-
-  //! Enable or disable selection in the viewer
-  virtual void enableSelection(bool isEnabled) = 0;
-
-  //! Returns true if selection is enabled
-  virtual bool isSelectionEnabled() const = 0;
-
-  //! Enable or disable multiselection in the viewer
-  virtual void enableMultiselection(bool isEnable) = 0;
-
-  //! Returns true if multiselection is enabled
-  virtual bool isMultiSelectionEnabled() const = 0;
-
-  //! Perfroms the fit all for the active view
-  virtual void fitAll() = 0;
-
-signals:
-  void lastViewClosed();
-  void tryCloseView();
-  void deleteView();
-  void viewCreated();
-  void mousePress(QMouseEvent* theEvent);
-  void mouseRelease(QMouseEvent* theEvent);
-  void mouseDoubleClick(QMouseEvent* theEvent);
-  void mouseMove(QMouseEvent* theEvent);
-  void keyPress(QKeyEvent* theEvent);
-  void keyRelease(QKeyEvent* theEvent);
-  void activated();
-
-  void selectionChanged();
-  void contextMenuRequested(QContextMenuEvent*);
-};
-
-#endif
index d39e31359aff576cb559a684bc691afbb432a15c..7ef11f4f66cb2d08724364aaedf882d93e04fffa 100644 (file)
@@ -19,10 +19,10 @@ XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop)
 {
 }
 
-std::list<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
+QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
 {
   std::set<ObjectPtr> aPrsFeatures;
-  std::list<ModuleBase_ViewerPrs> aPresentations;
+  QList<ModuleBase_ViewerPrs> aPresentations;
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
 
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
@@ -44,15 +44,15 @@ std::list<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSk
     }
     Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
     aPrs.setOwner(anOwner);
-    aPresentations.push_back(aPrs);
+    aPresentations.append(aPrs);
   }
   return aPresentations;
 }
 
-std::list<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
+QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
 {
   std::set<ObjectPtr> aPrsFeatures;
-  std::list<ModuleBase_ViewerPrs> aPresentations;
+  QList<ModuleBase_ViewerPrs> aPresentations;
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
 
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
@@ -111,13 +111,20 @@ void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
 }
 
 //**************************************************************
-void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
+void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList, 
+                                    std::list<ObjectPtr>& theOwners) const
 {
   theList.Clear();
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
     TopoDS_Shape aShape = aContext->SelectedShape();
-    if (!aShape.IsNull())
+    if (!aShape.IsNull()) {
       theList.Append(aShape);
+      Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
+      Handle(AIS_InteractiveObject) anObj = 
+        Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
+      ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
+      theOwners.push_back(anObject);
+    }
   }
 }
index b67adbc52e34b5da5b71e46f1ea32eadae53d7de..4868a9a80f7ffad28785f15f05cc8d354a26d158 100644 (file)
@@ -16,8 +16,6 @@
 #include <NCollection_List.hxx>
 #include <TopoDS_Shape.hxx>
 
-#include <list>
-
 class XGUI_Workshop;
 
 class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection
@@ -28,12 +26,12 @@ class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection
   /// Returns a list of viewer selected presentations
   /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
   /// \return list of presentations
-  virtual std::list<ModuleBase_ViewerPrs> getSelected(int theShapeTypeToSkip = -1) const;
+  virtual QList<ModuleBase_ViewerPrs> getSelected(int theShapeTypeToSkip = -1) const;
 
   /// Returns a list of viewer highlited presentations
   /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
   /// \return list of presentations
-  virtual std::list<ModuleBase_ViewerPrs> getHighlighted(int theShapeTypeToSkip = -1) const;
+  virtual QList<ModuleBase_ViewerPrs> getHighlighted(int theShapeTypeToSkip = -1) const;
 
   /**
    * Returns list of currently selected objects
@@ -52,7 +50,8 @@ class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection
   virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const;
 
   //! Returns list of currently selected shapes
-  virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList) const;
+  virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theShapes, 
+    std::list<ObjectPtr>& theOwners) const;
 
  private:
   XGUI_Workshop* myWorkshop;
index 2d2b4cc1c0738208ae8e7777ead8350c0a7c844d..b64386288fe908cad45948a44f5f7a6d6599e46e 100644 (file)
@@ -175,7 +175,9 @@ XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
       myEventStarted(false),
       myIsActive(false),
       myLastState(WindowNormalState),
-      myOperation(NOTHING)
+      myOperation(NOTHING),
+      myGripWgt(0),
+      myPicture(0)
 {
   mySelectedPoint = gp_Pnt(0., 0., 0.);
   setFrameStyle(QFrame::Raised);
index a2864475b963179cd6ee7bed4b6ed4d94d89dbe6..3a81496155da40783e179953e8384d92d2cc0349 100644 (file)
@@ -551,10 +551,10 @@ void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEv
 
   if (myStartPnt == myEndPnt) {
     // the MoveTo is necessary for the second click in the same point. Otherwise the selection is lost.
-    Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
-    if (!aView3d.IsNull()) {
-      myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
-    }
+    //Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
+    //if (!aView3d.IsNull()) {
+    //  myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
+    //}
     if (aHasShift && myMultiSelectionEnabled)
       myAISContext->ShiftSelect();
     else
index ad1685d524130ac6a234703cbb5276c8f7aacf9e..fee0419ddd6dfb31fbd19fce786d7fceee121325 100644 (file)
@@ -7,7 +7,7 @@
 #include "XGUI_SalomeConnector.h"
 
 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
-    : XGUI_SalomeViewer(theParent),
+    : ModuleBase_IViewer(theParent),
       myWorkshop(theParent)
 {
 }
@@ -65,7 +65,7 @@ void XGUI_ViewerProxy::fitAll()
 void XGUI_ViewerProxy::connectToViewer()
 {
   if (myWorkshop->isSalomeMode()) {
-    XGUI_SalomeViewer* aViewer = myWorkshop->salomeConnector()->viewer();
+    ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
 
     connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
     connect(aViewer, SIGNAL(tryCloseView()), this, SIGNAL(tryCloseView()));
index 6bc769cdd196369ad6665a20152102e94170fdb9..9c39bdf20c9ef3549f8404b1fa614986e448bfcf 100644 (file)
@@ -2,7 +2,7 @@
 #define XGUI_VIEWERPROXY_H
 
 #include "XGUI.h"
-#include "XGUI_SalomeViewer.h"
+#include <ModuleBase_IViewer.h>
 
 class XGUI_Workshop;
 class XGUI_ViewWindow;
@@ -13,7 +13,7 @@ class XGUI_ViewWindow;
  * It is reccomennded to use this class in operation for accessing to viewer 
  * functionality instead of direct access to a viewer
  */
-class XGUI_EXPORT XGUI_ViewerProxy : public XGUI_SalomeViewer
+class XGUI_EXPORT XGUI_ViewerProxy : public ModuleBase_IViewer
 {
 Q_OBJECT
  public:
@@ -44,10 +44,10 @@ Q_OBJECT
   /// \param theX the X projection value
   /// \param theY the Y projection value
   /// \param theZ the Z projection value
-  void setViewProjection(double theX, double theY, double theZ);
+  virtual void setViewProjection(double theX, double theY, double theZ);
 
   //! Sets the view fitted all
-  void fitAll();
+  virtual void fitAll();
 
   /// Connects to a viewer according to current environment
   void connectToViewer();
index d36f3f6de5e4f35ced929d47535c22390da8f60e..22358aab96a01a69400684a6fc335bd2a2d5d9ed 100644 (file)
@@ -14,7 +14,6 @@
 #include "XGUI_Displayer.h"
 #include "XGUI_OperationMgr.h"
 #include "XGUI_SalomeConnector.h"
-#include "XGUI_SalomeViewer.h"
 #include "XGUI_ActionsMgr.h"
 #include "XGUI_ErrorDialog.h"
 #include "XGUI_ViewerProxy.h"
@@ -44,7 +43,9 @@
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_SelectionValidator.h>
-#include "ModuleBase_WidgetFactory.h"
+#include <ModuleBase_WidgetFactory.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_IViewer.h>
 
 #include <Config_Common.h>
 #include <Config_FeatureMessage.h>
@@ -112,7 +113,8 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
 
   myModuleConnector = new XGUI_ModuleConnector(this);
 
-  connect(myOperationMgr, SIGNAL(operationStarted()), SLOT(onOperationStarted()));
+  connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)), 
+          SLOT(onOperationStarted()));
   connect(myOperationMgr, SIGNAL(operationResumed()), SLOT(onOperationStarted()));
   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           SLOT(onOperationStopped(ModuleBase_Operation*)));
@@ -177,6 +179,11 @@ void XGUI_Workshop::initMenu()
                                                 false);
     connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
     salomeConnector()->addEditMenuSeparator();
+    aAction = salomeConnector()->addEditCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
+                                                QIcon(":pictures/rebuild.png"), QKeySequence(),
+                                                false);
+    connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
+    salomeConnector()->addEditMenuSeparator();
     return;
   }
   // File commands group
@@ -339,10 +346,10 @@ void XGUI_Workshop::processEvent(const boost::shared_ptr<Events_Message>& theMes
     }
   }
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName("CurrentDocumentChanged")) {
+    myActionsMgr->update();
     // Find and Activate active part
     if (myPartActivating)
       return;
-    myActionsMgr->update();
     SessionPtr aMgr = ModelAPI_Session::get();
     DocumentPtr aActiveDoc = aMgr->activeDocument();
     DocumentPtr aDoc = aMgr->moduleDocument();
@@ -409,9 +416,15 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const boost::shared_ptr<ModelAPI_Objec
 {
   std::set<ObjectPtr> aObjects = theMsg->objects();
   std::set<ObjectPtr>::const_iterator aIt;
+  QIntList aModes;
   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
     ObjectPtr aObj = (*aIt);
-    if (!aObj->data() || !aObj->data()->isValid() || aObj->document()->isConcealed(aObj))
+    bool aHide = !aObj->data() || !aObj->data()->isValid();
+    if (!aHide) { // check that this is not hidden result
+      ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+      aHide = aRes && aRes->isConcealed();
+    }
+    if (aHide)
       myDisplayer->erase(aObj, false);
     else {
       if (myDisplayer->isVisible(aObj))  {
@@ -420,7 +433,7 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const boost::shared_ptr<ModelAPI_Objec
           ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
           if (!aOperation->hasObject(aObj))
             if (!myDisplayer->isActive(aObj))
-              myDisplayer->activate(aObj);
+              myDisplayer->activate(aObj, aModes);
         }
       } else {
         if (myOperationMgr->hasOperation()) {
@@ -455,8 +468,7 @@ void XGUI_Workshop::onFeatureCreatedMsg(const boost::shared_ptr<ModelAPI_ObjectU
       // it doesn't stored in the operation mgr and doesn't displayed
     } else if (myOperationMgr->hasOperation()) {
       ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
-      if (!(*aIt)->document()->isConcealed(*aIt) &&
-          aOperation->hasObject(*aIt)) {  // Display only current operation results
+      if (aOperation->hasObject(*aIt)) {  // Display only current operation results
         myDisplayer->display(*aIt, false);
         isDisplayed = true;
       }
@@ -466,9 +478,9 @@ void XGUI_Workshop::onFeatureCreatedMsg(const boost::shared_ptr<ModelAPI_ObjectU
     myObjectBrowser->processEvent(theMsg);
   if (isDisplayed)
     myDisplayer->updateViewer();
-  if (aHasPart) {
-    activateLastPart();
-  }
+  //if (aHasPart) { // TODO: Avoid activate last part on loading of document
+  //  activateLastPart();
+  //}
 }
 
 //******************************************************
@@ -498,12 +510,10 @@ void XGUI_Workshop::onOperationStarted()
 
     myPropertyPanel->cleanContent();
     aFactory.createWidget(myPropertyPanel->contentWidget());
+    ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
 
     QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
-    QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
-    ModuleBase_ModelWidget* aWidget;
-    for (; anIt != aLast; anIt++) {
-      aWidget = *anIt;
+    foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
       aWidget->setFeature(aOperation->feature());
       aWidget->enableFocusProcessing();
       QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
@@ -513,8 +523,10 @@ void XGUI_Workshop::onOperationStarted()
       }
     }
 
+    aOperation->setPropertyPanel(myPropertyPanel);
     myPropertyPanel->setModelWidgets(aWidgets);
-    myPropertyPanel->onActivateNextWidget(NULL);
+    if (!aOperation->activateByPreselection())
+      myPropertyPanel->activateNextWidget(NULL);
     // Widget activation (from the previous method) may commit the current operation
     // if pre-selection is enougth for it. So we shouldn't update prop panel's title
     if(myOperationMgr->isCurrentOperation(aOperation)) {
@@ -571,6 +583,8 @@ void XGUI_Workshop::addFeature(const boost::shared_ptr<Config_FeatureMessage>& t
                                                      QKeySequence(),
                                                      isUsePropPanel);
     salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
+    salomeConnector()->setDocumentKind(aFeatureId, QString::fromStdString(theMessage->documentKind()));
+
     myActionsMgr->addCommand(aAction);
     myModule->featureCreated(aAction);
   } else {
@@ -879,7 +893,7 @@ ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
   }
 #endif
 
-  ModuleBase_IModule* aModule = crtInst ? crtInst(this) : 0;
+  ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
 
   if (!err.isEmpty()) {
     if (mainWindow()) {
@@ -994,6 +1008,7 @@ void XGUI_Workshop::createDockWidgets()
   hidePropertyPanel();  //<! Invisible by default
   hideObjectBrowser();
   aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
+  myPropertyPanel->installEventFilter(myOperationMgr);
 
   QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
   connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
@@ -1001,10 +1016,6 @@ void XGUI_Workshop::createDockWidgets()
   connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
   connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
           SLOT(onKeyReleased(QKeyEvent*)));
-  connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr,
-          SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
-  connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel,
-          SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
   connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel,
           SLOT(setAcceptEnabled(bool)));
 
@@ -1076,7 +1087,7 @@ void XGUI_Workshop::salomeViewerSelectionChanged()
 }
 
 //**************************************************************
-XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
+ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
 {
   return mySalomeConnector->viewer();
 }
index 5a557db2bc5ddeb883d478c46bdbf98291ec483a..d5159189aec9465cd207beae2dd10569b5746560 100644 (file)
@@ -31,6 +31,7 @@ class XGUI_ModuleConnector;
 
 class ModuleBase_Operation;
 class ModuleBase_IModule;
+class ModuleBase_IViewer;
 
 class Config_FeatureMessage;
 class Config_PointerMessage;
@@ -113,7 +114,7 @@ Q_OBJECT
   }
 
   //! Provides an object which provides interface to Salome Viewer
-  XGUI_SalomeViewer* salomeViewer() const;
+  ModuleBase_IViewer* salomeViewer() const;
 
   //! Returns true if the application works as SALOME module
   bool isSalomeMode() const