Salome HOME
Added groups results
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 30 Oct 2014 16:22:18 +0000 (19:22 +0300)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 30 Oct 2014 16:22:18 +0000 (19:22 +0300)
14 files changed:
src/FeaturesPlugin/FeaturesPlugin_Group.cpp
src/FeaturesPlugin/FeaturesPlugin_Group.h
src/Model/CMakeLists.txt
src/Model/Model_AttributeSelection.cpp
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/Model/Model_ResultGroup.cpp [new file with mode: 0644]
src/Model/Model_ResultGroup.h [new file with mode: 0644]
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_ResultGroup.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Line.cpp

index dad22dbf60b9ec8b537c3aa1b2bc2e2f82cc206d..e9ae74d59627fda00bc49c8bebdb64bed2021025 100644 (file)
@@ -25,10 +25,7 @@ void FeaturesPlugin_Group::initAttributes()
 
 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);
+  if (results().empty()) { // just create result if not exists
+    document()->createGroup(data());
+  }
 }
index 23078ae675c99b4b299724592b471d1930c182f3..7138c1241ca0a298c6199878f6e2b658a4ea5e4c 100644 (file)
@@ -44,6 +44,9 @@ class FeaturesPlugin_Group : public ModelAPI_Feature
   /// Request for initialization of data model of the feature: adding all attributes
   FEATURESPLUGIN_EXPORT virtual void initAttributes();
 
+  /// Result of groups is created on the fly and don't stored to the document
+  FEATURESPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+
   /// Use plugin manager for features creation
   FeaturesPlugin_Group();
 
index 1656a618f50738db0746fba46fc4ff0b86b23908..753fd7817bd14c5ae8a34540513e7a195f95a24a 100644 (file)
@@ -22,6 +22,7 @@ SET(PROJECT_HEADERS
     Model_ResultBody.h
     Model_ResultConstruction.h
     Model_ResultPart.h
+    Model_ResultGroup.h
     Model_FeatureValidator.h
 )
 
@@ -46,6 +47,7 @@ SET(PROJECT_SOURCES
     Model_ResultBody.cpp
     Model_ResultConstruction.cpp
     Model_ResultPart.cpp
+    Model_ResultGroup.cpp
     Model_FeatureValidator.cpp
 )
 
index f502aee03ba59f3ce286eebee36505058ad38da9..aac5c3f080dcb0df297b5ca736ac96ba4da31a5e 100644 (file)
@@ -91,8 +91,8 @@ bool Model_AttributeSelection::update()
     // body: just a named shape, use selection mechanism from OCCT
     TNaming_Selector aSelector(selectionLabel());
     TDF_LabelMap aScope; // empty means the whole document
+    owner()->data()->sendAttributeUpdated(this);
     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
@@ -171,6 +171,7 @@ bool Model_AttributeSelection::update()
       }
       if (aNewSelected) { // store this new selection
         selectConstruction(aContext, aNewSelected);
+        owner()->data()->sendAttributeUpdated(this);
         return true;
       }
     }
index cbf4ac79d96563fd982c26ea2fe79d3fdec2aaa0..2487b7c30f1b6d0b068a65299380202a0a5fa73b 100644 (file)
@@ -10,6 +10,7 @@
 #include <Model_ResultPart.h>
 #include <Model_ResultConstruction.h>
 #include <Model_ResultBody.h>
+#include <Model_ResultGroup.h>
 #include <ModelAPI_Validator.h>
 #include <Events_Loop.h>
 #include <Events_Error.h>
@@ -912,6 +913,23 @@ boost::shared_ptr<ModelAPI_ResultPart> Model_Document::createPart(
   return aResult;
 }
 
+boost::shared_ptr<ModelAPI_ResultGroup> Model_Document::createGroup(
+    const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
+{
+  TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+  TDataStd_Comment::Set(aLab, ModelAPI_ResultGroup::group().c_str());
+  ObjectPtr anOldObject = object(aLab);
+  boost::shared_ptr<ModelAPI_ResultGroup> aResult;
+  if (anOldObject) {
+    aResult = boost::dynamic_pointer_cast<ModelAPI_ResultGroup>(anOldObject);
+  }
+  if (!aResult) {
+    aResult = boost::shared_ptr<ModelAPI_ResultGroup>(new Model_ResultGroup(theFeatureData));
+    storeResult(theFeatureData, aResult, theIndex);
+  }
+  return aResult;
+}
+
 boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(
     const boost::shared_ptr<ModelAPI_Result>& theResult)
 {
@@ -957,7 +975,8 @@ void Model_Document::updateResults(FeaturePtr theFeature)
           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()) {
+        } else if (aGroup->Get() != ModelAPI_ResultConstruction::group().c_str() &&
+          aGroup->Get() != ModelAPI_ResultGroup::group().c_str()) {
           Events_Error::send(std::string("Unknown type of result is found in the document:") +
             TCollection_AsciiString(aGroup->Get()).ToCString());
         }
index cbea4a19e58826dd8c9148f0e33679ccea3b60d8..d8743f0994d03ffe707df3d26605251531c81f6f 100644 (file)
@@ -121,6 +121,9 @@ class Model_Document : public ModelAPI_Document
   /// Creates a part results
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultPart> createPart(
       const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
+  /// Creates a group results
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultGroup> createGroup(
+      const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
 
   //! Returns a feature by result (owner of result)
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature>
index 807dcc7330ed1077ba7aaa47c8b39ef9c549b1f7..3c7f7a689cd018483b88d64fbb0ebc1cc7e5dea8 100644 (file)
@@ -101,11 +101,6 @@ boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
   return boost::shared_ptr<GeomAPI_Shape>();
 }
 
-boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
-{
-  return myOwner;
-}
-
 void Model_ResultBody::clean()
 {
   std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
index 340b35bb515e9699b244f69d22680eb7acd2cebe..a12ccb87d509deee934bdffbd5c30c1e27237153 100644 (file)
@@ -23,7 +23,6 @@ class TNaming_Builder;
  */
 class Model_ResultBody : public ModelAPI_ResultBody
 {
-  boost::shared_ptr<ModelAPI_Feature> myOwner;  ///< owner of this result
   /// 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;
@@ -41,8 +40,6 @@ public:
 
   /// 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();
 
   /// 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.
diff --git a/src/Model/Model_ResultGroup.cpp b/src/Model/Model_ResultGroup.cpp
new file mode 100644 (file)
index 0000000..2fd1ead
--- /dev/null
@@ -0,0 +1,34 @@
+// File:        Model_ResultGroup.cpp
+// Created:     08 Jul 2014
+// Author:      Mikhail PONIKAROV
+
+#include <Model_ResultGroup.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+Model_ResultGroup::Model_ResultGroup(boost::shared_ptr<ModelAPI_Data> theOwnerData)
+{
+  setIsConcealed(false);
+  myOwnerData = theOwnerData;
+}
+
+boost::shared_ptr<GeomAPI_Shape> Model_ResultGroup::shape() const
+{
+  boost::shared_ptr<GeomAPI_Shape> aResult;
+  if (myOwnerData) {
+    AttributeSelectionListPtr aList = myOwnerData->selectionList("group_list");
+    if (aList) {
+      std::list<boost::shared_ptr<GeomAPI_Shape> > aSubs;
+      for(int a = aList->size(); a >= 0; a--) {
+        boost::shared_ptr<GeomAPI_Shape> aSelection = aList->value(a)->value();
+        if (aSelection && !aSelection->isNull()) {
+          aSubs.push_back(aSelection);
+        }
+      }
+      if (!aSubs.empty()) {
+        aResult = GeomAlgoAPI_CompoundBuilder::compound(aSubs);
+      }
+    }
+  }
+  return aResult;
+}
diff --git a/src/Model/Model_ResultGroup.h b/src/Model/Model_ResultGroup.h
new file mode 100644 (file)
index 0000000..30e3588
--- /dev/null
@@ -0,0 +1,34 @@
+// File:        Model_ResultGroup.h
+// Created:     08 Jul 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef Model_ResultGroup_H_
+#define Model_ResultGroup_H_
+
+#include "Model.h"
+#include <ModelAPI_ResultGroup.h>
+
+/**\class ModelAPI_ResultGroup
+ * \ingroup DataModel
+ * \brief The groups result.
+ *
+ * Provides a compound of selected elements, without storage, one the fly.
+ */
+class Model_ResultGroup : public ModelAPI_ResultGroup
+{
+  boost::shared_ptr<ModelAPI_Data> myOwnerData;  ///< data of owner of this result
+public:
+  /// Returns the compound of selected entities
+  MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape() const;
+
+  /// Removes the stored builders
+  MODEL_EXPORT virtual ~Model_ResultGroup() {}
+
+protected:
+  /// Makes a body on the given feature data
+  Model_ResultGroup(boost::shared_ptr<ModelAPI_Data> theOwnerData);
+
+  friend class Model_Document;
+};
+
+#endif
index 0bfa08a58c57ad2e1486feafaa3df577f0cb887a..bbc99cbb1543d004c3504af482afb9439aa07577 100644 (file)
@@ -31,6 +31,7 @@ SET(PROJECT_HEADERS
     ModelAPI_ResultConstruction.h
     ModelAPI_ResultPart.h
     ModelAPI_ResultParameters.h
+    ModelAPI_ResultGroup.h
     ModelAPI_ResultValidator.h
     ModelAPI_AttributeValidator.h
     ModelAPI_Tools.h
index cdfa1d75ed89bb6661e2d7e30a239cfc3eab1a88..703ab0f881cebeb997bbf62d9fe3b5d4747ec1f8 100644 (file)
@@ -17,6 +17,7 @@ class ModelAPI_Result;
 class ModelAPI_ResultConstruction;
 class ModelAPI_ResultBody;
 class ModelAPI_ResultPart;
+class ModelAPI_ResultGroup;
 class ModelAPI_Data;
 
 /**\class Model_Document
@@ -76,6 +77,9 @@ public:
   /// Creates a part results
   virtual boost::shared_ptr<ModelAPI_ResultPart> createPart(
       const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+  /// Creates a group results
+  virtual boost::shared_ptr<ModelAPI_ResultGroup> createGroup(
+      const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
 
   //! Returns a feature by result (owner of result)
   virtual boost::shared_ptr<ModelAPI_Feature> feature(
diff --git a/src/ModelAPI/ModelAPI_ResultGroup.h b/src/ModelAPI/ModelAPI_ResultGroup.h
new file mode 100644 (file)
index 0000000..a8b183c
--- /dev/null
@@ -0,0 +1,42 @@
+// File:        ModelAPI_ResultGroup.hxx
+// Created:     07 Jul 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef ModelAPI_ResultGroup_H_
+#define ModelAPI_ResultGroup_H_
+
+#include "ModelAPI_Result.h"
+#include <GeomAPI_Shape.h>
+#include <boost/shared_ptr.hpp>
+#include <string>
+
+/**\class ModelAPI_ResultGroup
+ * \ingroup DataModel
+ * \brief The groups result.
+ *
+ * Provides a compound of selected elements, without storage, one the fly.
+ */
+class ModelAPI_ResultGroup : public ModelAPI_Result
+{
+public:
+  /// Returns the group identifier of this result
+  virtual std::string groupName()
+  {
+    return group();
+  }
+
+  /// Returns the group identifier of this result
+  static std::string group()
+  {
+    static std::string MY_GROUP = "Groups";
+    return MY_GROUP;
+  }
+
+  /// Returns the compound of selected entities
+  virtual boost::shared_ptr<GeomAPI_Shape> shape() const = 0;
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_ResultGroup> ResultGroupPtr;
+
+#endif
index 75c404a772a12922e9bd6284a8b07e4d3a952d15..2d85a43b3873b99f1d938c29296da7230f0572c0 100644 (file)
@@ -21,8 +21,7 @@ using namespace std;
 
 SketchPlugin_Line::SketchPlugin_Line()
     : SketchPlugin_Feature()
-{
-}
+{}
 
 void SketchPlugin_Line::initAttributes()
 {