Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
authormpv <mpv@opencascade.com>
Mon, 13 Apr 2015 13:30:15 +0000 (16:30 +0300)
committermpv <mpv@opencascade.com>
Mon, 13 Apr 2015 13:30:15 +0000 (16:30 +0300)
src/Model/Model_AttributeRefList.cpp
src/Model/Model_AttributeRefList.h
src/Model/Model_AttributeSelectionList.cpp
src/Model/Model_AttributeSelectionList.h
src/Model/Model_Document.cpp
src/ModelAPI/ModelAPI_Attribute.h
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Feature.h
src/ModelAPI/ModelAPI_Result.h
src/PartSetPlugin/PartSetPlugin_Part.cpp
src/PartSetPlugin/PartSetPlugin_Part.h

index 13233fb9c4e0128becbf03d324014051ceb4539e..b1fcda04632516822a6a4ae3c9abdbd4d95320dd 100644 (file)
@@ -54,6 +54,14 @@ int Model_AttributeRefList::size() const
   return myRef->Extent();
 }
 
+bool Model_AttributeRefList::isInitialized()
+{
+  if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo
+    return false;
+  }
+  return ModelAPI_AttributeRefList::isInitialized();
+}
+
 list<ObjectPtr> Model_AttributeRefList::list()
 {
   std::list<ObjectPtr> aResult;
index 2a4550a80bfd376c3437b5c5aaadfc2e82967863..f59229a1a697f73b231f78e6de162ad8b4a7a334 100644 (file)
@@ -37,6 +37,8 @@ class Model_AttributeRefList : public ModelAPI_AttributeRefList
   /// Returns the list of features
   MODEL_EXPORT virtual ObjectPtr object(const int theIndex) const;
 
+  /// Returns true if attribute was  initialized by some value
+  MODEL_EXPORT virtual bool isInitialized();
  protected:
   /// Objects are created for features automatically
   MODEL_EXPORT Model_AttributeRefList(TDF_Label& theLabel);
index 79eb5c714e12ee2e5565c209dfb271f3d793b389..3b67df9eb0a9063e23a7874fde696432fdaa9857 100644 (file)
@@ -102,6 +102,14 @@ void Model_AttributeSelectionList::clear()
   }
 }
 
+bool Model_AttributeSelectionList::isInitialized()
+{
+  if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo
+    return false;
+  }
+  return ModelAPI_AttributeSelectionList::isInitialized();
+}
+
 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
 {
   myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
index 584c170e9c7cb10d5c0b255ba34b691a511968b0..5865b8562b6d447cd1828856194ccf6cdf7ea183 100644 (file)
@@ -50,6 +50,9 @@ public:
   /// Returns all attributes
   MODEL_EXPORT virtual void clear();
 
+  /// Returns true if attribute was  initialized by some value
+  MODEL_EXPORT virtual bool isInitialized();
+
 protected:
   /// Objects are created for features automatically
   MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
index 00531ba8445b1ff25404cbee87f8ca7c3cf03ad5..ec0c236f6f0389ab60177023a65ab8e30a399696 100644 (file)
@@ -557,13 +557,18 @@ FeaturePtr Model_Document::addFeature(std::string theID)
 {
   TDF_Label anEmptyLab;
   FeaturePtr anEmptyFeature;
-  FeaturePtr aFeature = 
-    std::dynamic_pointer_cast<Model_Session>(ModelAPI_Session::get())->createFeature(theID, this);
+  std::shared_ptr<Model_Session> aSession = 
+    std::dynamic_pointer_cast<Model_Session>(ModelAPI_Session::get());
+  FeaturePtr aFeature = aSession->createFeature(theID, this);
   if (!aFeature)
     return aFeature;
   Model_Document* aDocToAdd;
-  if (aFeature->documentToAdd().get()) { // use the customized document to add
-    aDocToAdd = std::dynamic_pointer_cast<Model_Document>(aFeature->documentToAdd()).get();
+  if (!aFeature->documentToAdd().empty()) { // use the customized document to add
+    if (aFeature->documentToAdd() != kind()) { // the root document by default
+      aDocToAdd = std::dynamic_pointer_cast<Model_Document>(aSession->moduleDocument()).get();
+    } else {
+      aDocToAdd = this;
+    }
   } else { // if customized is not presented, add to "this" document
     aDocToAdd = this;
   }
index e3b1b056df9514052fe2bfebd6f256c5320b56e9..442e4e4a05065fa93dedaecb8721c5959a362232 100644 (file)
@@ -44,7 +44,7 @@ class ModelAPI_Attribute
   MODELAPI_EXPORT const std::shared_ptr<ModelAPI_Object>& owner() const;
 
   /// Returns true if attribute was  initialized by some value
-  MODELAPI_EXPORT bool isInitialized();
+  MODELAPI_EXPORT virtual bool isInitialized();
 
   /// Makes attribute initialized
   MODELAPI_EXPORT void setInitialized();
index ef212d23f1b13559d4d89280821cbb1f7af06c88..d9533e83e33d17c570bcc013ab65332f3be084dd 100644 (file)
@@ -132,10 +132,11 @@ void ModelAPI_Feature::eraseResults()
   }
 }
 
-std::shared_ptr<ModelAPI_Document> ModelAPI_Feature::documentToAdd()
+const std::string& ModelAPI_Feature::documentToAdd()
 {
-  // null pointer t ouse the current document
-  return std::shared_ptr<ModelAPI_Document>();
+  // empty to use the current document
+  static const std::string anEmpty;
+  return anEmpty;
 }
 
 void ModelAPI_Feature::erase()
index b80583544021bd7afc1f74b9129df94f246166f5..85ebe38b533d0c7ce3093fb575c3ebd67aa07b0b 100644 (file)
@@ -99,8 +99,8 @@ class ModelAPI_Feature : public ModelAPI_Object
   }
 
   /// Must return document where the new feature must be added to
-  /// By default it is null document: it is added to the document this method is called to
-  MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Document> documentToAdd();
+  /// By default it is empty: it is added to the document this method is called to
+  MODELAPI_EXPORT virtual const std::string& documentToAdd();
 
   /// To virtually destroy the fields of successors
   MODELAPI_EXPORT virtual ~ModelAPI_Feature();
index daad432e75dbdc2de59a1b42c977bc982d342d0a..472fe0056924b7b43f3658d172c19469438e9be2 100644 (file)
@@ -43,7 +43,8 @@ class ModelAPI_Result : public ModelAPI_Object
   }
 
   // Retuns the parameters of color definition in the resources config manager
-  virtual void colorConfigInfo(std::string& theSection, std::string& theName, std::string& theDefault) {}
+  virtual void colorConfigInfo(std::string& theSection, std::string& theName,
+    std::string& theDefault) {}
 
   /// Request for initialization of data model of the result: adding all attributes
   virtual void initAttributes() {};
index 58c2d85fd3384c6ca14a7a3506ce77c5a0306ecf..95fa5f06bee10875028b822faaf7c3e3bc11a62b 100644 (file)
@@ -31,7 +31,8 @@ void PartSetPlugin_Part::execute()
   }
 }
 
-std::shared_ptr<ModelAPI_Document> PartSetPlugin_Part::documentToAdd()
+const std::string& PartSetPlugin_Part::documentToAdd()
 {
-  return ModelAPI_Session::get()->moduleDocument();
+  // part must be added only to the module document
+  return ModelAPI_Session::get()->moduleDocument()->kind();
 }
index 5b7d63e4947d53269f7ef29a52995e1916ef59b9..e7f23387c8ce407bbc8cf7122a0b3ff4c447f0eb 100644 (file)
@@ -43,7 +43,7 @@ class PartSetPlugin_Part : public ModelAPI_Feature
   /// Request for initialization of data model of the feature: adding all attributes
   PARTSETPLUGIN_EXPORT virtual void initAttributes();
 
-  PARTSETPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Document> documentToAdd();
+  PARTSETPLUGIN_EXPORT virtual const std::string& documentToAdd();
 
   /// Returns true if this feature must be displayed in the history (top level of Part tree)
   PARTSETPLUGIN_EXPORT virtual bool isInHistory()