feature(const std::shared_ptr<ModelAPI_Result>& theResult);
//! Creates a folder (group of the features in the object browser)
+ //! \param theAddBefore a feature, the folder is added before
+ //! (if empty, the folder is added after the last feature)
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Folder> addFolder(
std::shared_ptr<ModelAPI_Feature> theAddBefore = std::shared_ptr<ModelAPI_Feature>());
//! Removes the folder from the document (all features in the folder will be kept).
virtual std::list<std::shared_ptr<ModelAPI_Object> > allObjects() = 0;
//! Creates a folder (group of the features in the object browser)
+ //! \param theAddBefore a feature, the folder is added before
+ //! (if empty, the folder is added after the last feature)
virtual std::shared_ptr<ModelAPI_Folder> addFolder(
- std::shared_ptr<ModelAPI_Feature> theAddBefore) = 0;
+ std::shared_ptr<ModelAPI_Feature> theAddBefore = std::shared_ptr<ModelAPI_Feature>()) = 0;
//! Removes the folder from the document (all features in the folder will be kept).
virtual void removeFolder(std::shared_ptr<ModelAPI_Folder> theFolder) = 0;
//! Search a folder above the list of features applicable to store them
#=========================================================================
# Test 1. Check number of features out of folder
-# and absense of the crash while getting size of incorrect groupd
+# and absense of the crash while getting size of incorrect group
#=========================================================================
assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
assert(aPartDoc.size("Construction", True) == 1), "Wrong size: {}".format(aPartDoc.size("Construction", True))
+#=========================================================================
+# Test 2. Add a feature to the folder and check number of features once again
+#=========================================================================
+toFolder = FeatureList()
+toFolder.append(aPoint1)
+
+aSession.startOperation()
+aFolder2 = aPartDoc.addFolder(aPoint1)
+aSession.finishOperation()
+
+NB_FEATURES_FULL += 1
+NB_FEATURES_OUT += 1
+
+aSession.startOperation()
+aFolder = aPartDoc.findFolderAbove(toFolder)
+assert(aFolder is not None)
+isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
+aSession.finishOperation()
+assert(isAdded)
+
+NB_FEATURES_OUT -= 1
+assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
+assert(aPartDoc.size("Construction", True) == 1), "Wrong size: {}".format(aPartDoc.size("Construction", True))
+
from salome.shaper import model
assert(model.checkPythonDump())
// shared pointers
%shared_ptr(ModelHighAPI_Interface)
+%shared_ptr(ModelHighAPI_Folder)
// typemaps
#include <ModelAPI_Document.h>
#include <ModelAPI_Entity.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Folder.h>
#include <ModelAPI_Result.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultCompSolid.h>
return aFound->second.myCurrentName;
// entity is not found, store it
- std::string aName;
+ std::string aName, aKind;
bool isDefaultName = false;
+ bool isSaveNotDumped = theSaveNotDumped;
std::ostringstream aDefaultName;
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theEntity);
if (aFeature) {
aName = aFeature->name();
- const std::string& aKind = aFeature->getKind();
- DocumentPtr aDoc = aFeature->document();
+ aKind = aFeature->getKind();
+ } else {
+ FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(theEntity);
+ if (aFolder) {
+ aName = aFolder->data()->name();
+ aKind = ModelAPI_Folder::ID();
+ isSaveNotDumped = false;
+ myNotDumpedFolders.insert(aFolder);
+ }
+ }
+
+ ObjectPtr anObject = std::dynamic_pointer_cast<ModelAPI_Object>(theEntity);
+ if (anObject) {
+ DocumentPtr aDoc = anObject->document();
int& aNbFeatures = myFeatureCount[aDoc][aKind];
aNbFeatures += 1;
}
myNames[theEntity] = EntityName(aDefaultName.str(), aName, isDefaultName);
- if (theSaveNotDumped)
+ if (isSaveNotDumped)
myNotDumpedEntities.insert(theEntity);
// store names of results
bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_Document>& theDoc)
{
bool isOk = true;
- std::list<FeaturePtr> aFeatures = theDoc->allFeatures();
- std::list<FeaturePtr>::const_iterator aFeatIt = aFeatures.begin();
+ std::list<ObjectPtr> anObjects = theDoc->allObjects();
+ std::list<ObjectPtr>::const_iterator anObjIt = anObjects.begin();
// firstly, dump all parameters
- for (; aFeatIt != aFeatures.end(); ++ aFeatIt)
- dumpParameter(*aFeatIt);
+ for (; anObjIt != anObjects.end(); ++ anObjIt) {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anObjIt);
+ if (aFeature)
+ dumpParameter(aFeature);
+ }
// dump all other features
- for (aFeatIt = aFeatures.begin(); aFeatIt != aFeatures.end(); ++aFeatIt) {
- CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aFeatIt);
+ for (anObjIt = anObjects.begin(); anObjIt != anObjects.end(); ++anObjIt) {
+ CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*anObjIt);
if (aCompFeat) // iteratively process composite features
isOk = process(aCompFeat) && isOk;
- else if (!isDumped(*aFeatIt)) // dump common feature
- dumpFeature(*aFeatIt);
+ else if (!isDumped(*anObjIt)) {
+ // dump folder
+ FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(*anObjIt);
+ if (aFolder)
+ dumpFolder(aFolder);
+ else {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anObjIt);
+ if (aFeature) // dump common feature
+ dumpFeature(aFeature);
+ }
+ }
}
return isOk;
}
return *this;
}
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FolderPtr& theFolder)
+{
+ myDumpBuffer << name(theFolder);
+ myNotDumpedFolders.erase(theFolder);
+ return *this;
+}
+
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity)
{
myDumpBuffer << name(theEntity);
// then store currently dumped string
theDumper.myFullDump << aBufCopy;
+ // now, store all not dumped folders
+ std::set<FolderPtr>::const_iterator aFolderIt = theDumper.myNotDumpedFolders.begin();
+ while (aFolderIt != theDumper.myNotDumpedFolders.end()) {
+ FolderPtr aFolder = *aFolderIt++;
+ theDumper.dumpFolder(aFolder);
+ }
+
return theDumper;
}
class ModelAPI_Document;
class ModelAPI_Entity;
class ModelAPI_Feature;
+class ModelAPI_Folder;
class ModelAPI_Object;
class ModelAPI_Result;
typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
typedef std::shared_ptr<ModelAPI_Entity> EntityPtr;
typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
+typedef std::shared_ptr<ModelAPI_Folder> FolderPtr;
typedef std::shared_ptr<ModelAPI_Result> ResultPtr;
/**\class ModelHighAPI_Dumper
virtual void dumpParameter(const FeaturePtr& theFeature) = 0;
/// Dump given feature
virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
+ /// Dump folder
+ virtual void dumpFolder(const FolderPtr& theFolder) = 0;
/// Set a feature that should not be dumped anyway
MODELHIGHAPI_EXPORT
MODELHIGHAPI_EXPORT
ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity);
+ /// Dump folder
+ MODELHIGHAPI_EXPORT
+ ModelHighAPI_Dumper& operator<<(const FolderPtr& theFolder);
+
/// Dump result
MODELHIGHAPI_EXPORT
ModelHighAPI_Dumper& operator<<(const ResultPtr& theResult);
std::set<FeaturePtr> myFeaturesToSkip;
protected:
- /// list of entities, used by other features but not dumped yet
+ /// list of entities, used by other features but not dumped yet
std::set<EntityPtr> myNotDumpedEntities;
+ /// list of folders which do not dumped yet
+ std::set<FolderPtr> myNotDumpedFolders;
friend class SketchAPI_Sketch;
+ friend class ModelHighAPI_Folder;
};
#endif
//
#include "ModelHighAPI_Folder.h"
-#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Reference.h>
+#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_Document.h>
-#include <ModelAPI_Folder.h>
//--------------------------------------------------------------------------------------
ModelHighAPI_Folder::ModelHighAPI_Folder(const std::shared_ptr<ModelAPI_Folder> & theFolder)
+ : ModelHighAPI_Interface(FeaturePtr()),
+ myFolder(theFolder)
{
+ initialize();
}
-
ModelHighAPI_Folder::~ModelHighAPI_Folder()
{
}
+bool ModelHighAPI_Folder::initialize()
+{
+ if (!myFolder) {
+ throwException(ID() + " exception: The folder is NULL.");
+ return false;
+ }
+
+ SET_ATTRIBUTE(firstFeature, ModelAPI_AttributeReference, ModelAPI_Folder::FIRST_FEATURE_ID());
+ SET_ATTRIBUTE(lastFeature, ModelAPI_AttributeReference, ModelAPI_Folder::LAST_FEATURE_ID());
+
+ return true;
+}
+
+void ModelHighAPI_Folder::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ const std::string& aDocName = theDumper.name(myFolder->document());
+
+ AttributeReferencePtr aStartRef = myFolder->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
+ AttributeReferencePtr aEndRef = myFolder->reference(ModelAPI_Folder::LAST_FEATURE_ID());
+
+ // Dump folder if it is empty or when its features have been already dumped.
+ // Otherwise, just store the name of the folder.
+ if (!aEndRef->value())
+ theDumper << myFolder << " = model.addFolder(" << aDocName << ")" << std::endl;
+ else if (theDumper.isDumped(aEndRef->value()))
+ theDumper << myFolder << " = model.addFolder(" << aDocName << ", "
+ << aStartRef << ", " << aEndRef << ")" << std::endl;
+ else
+ theDumper.name(myFolder);
+}
+
//--------------------------------------------------------------------------------------
-std::shared_ptr<ModelHighAPI_Folder> addFolder(const std::shared_ptr<ModelAPI_Document>& thePart)
+std::shared_ptr<ModelHighAPI_Folder> addFolder(const std::shared_ptr<ModelAPI_Document>& theDoc)
{
- std::shared_ptr<ModelAPI_Folder> aFolder;//// = thePart->addFolder();
+ std::shared_ptr<ModelAPI_Folder> aFolder = theDoc->addFolder();
+ return std::shared_ptr<ModelHighAPI_Folder>(new ModelHighAPI_Folder(aFolder));
+}
+
+std::shared_ptr<ModelHighAPI_Folder> addFolder(const std::shared_ptr<ModelAPI_Document>& theDoc,
+ const ModelHighAPI_Reference& theFirstFeature,
+ const ModelHighAPI_Reference& theLastFeature)
+{
+ std::shared_ptr<ModelAPI_Folder> aFolder = theDoc->addFolder(theFirstFeature.feature());
+
+ AttributeReferencePtr aFirstFeatAttr = aFolder->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
+ theFirstFeature.fillAttribute(aFirstFeatAttr);
+
+ AttributeReferencePtr aLastFeatAttr = aFolder->reference(ModelAPI_Folder::LAST_FEATURE_ID());
+ theLastFeature.fillAttribute(aLastFeatAttr);
+
return std::shared_ptr<ModelHighAPI_Folder>(new ModelHighAPI_Folder(aFolder));
}
//--------------------------------------------------------------------------------------
#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+#include <ModelAPI_Folder.h>
#include <memory>
//--------------------------------------------------------------------------------------
+class ModelAPI_AttributeReference;
class ModelAPI_Document;
-class ModelAPI_Folder;
-class ModelHighAPI_Selection;
+class ModelHighAPI_Reference;
//--------------------------------------------------------------------------------------
/**\class ModelHighAPI_Folder
* \ingroup CPPHighAPI
* \brief Class for filling ModelAPI_Folder
*/
-class ModelHighAPI_Folder
+class ModelHighAPI_Folder : public ModelHighAPI_Interface
{
public:
/// Constructor for a folder
MODELHIGHAPI_EXPORT
- explicit ModelHighAPI_Folder(const std::shared_ptr<ModelAPI_Folder> & theFolder);
+ explicit ModelHighAPI_Folder(const std::shared_ptr<ModelAPI_Folder>& theFolder);
/// Destructor
MODELHIGHAPI_EXPORT virtual ~ModelHighAPI_Folder();
+
+ static std::string ID() { return ModelAPI_Folder::ID(); }
+ virtual std::string getID() { return ID(); }
+
+ /// First feature reference
+ std::shared_ptr<ModelAPI_AttributeReference> firstFeature() const
+ { return myfirstFeature; }
+
+ /// Last feature reference
+ std::shared_ptr<ModelAPI_AttributeReference> lastFeature() const
+ { return mylastFeature; }
+
+ /// Dump wrapped feature
+ MODELHIGHAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+
+protected:
+ bool initialize();
+
+private:
+ std::shared_ptr<ModelAPI_Folder> myFolder;
+
+ std::shared_ptr<ModelAPI_AttributeReference> myfirstFeature;
+ std::shared_ptr<ModelAPI_AttributeReference> mylastFeature;
};
//--------------------------------------------------------------------------------------
/**\ingroup CPPHighAPI
- * \brief Create Folder feature
+ * \brief Create empty Folder feature
*/
MODELHIGHAPI_EXPORT
std::shared_ptr<ModelHighAPI_Folder> addFolder(const std::shared_ptr<ModelAPI_Document>& theDoc);
+
+/**\ingroup CPPHighAPI
+ * \brief Create Folder feature
+ */
+MODELHIGHAPI_EXPORT
+std::shared_ptr<ModelHighAPI_Folder> addFolder(const std::shared_ptr<ModelAPI_Document>& theDoc,
+ const ModelHighAPI_Reference& theFirstFeature,
+ const ModelHighAPI_Reference& theLastFeature);
//--------------------------------------------------------------------------------------
#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_FOLDER_H_ */
# In case of theFeature is not a constraint, it will not be dumped.
self.myFeatures[SketchAPI.SketchAPI_Constraint.ID()](theFeature).dump(self)
+ ## Create wrapper for a folder and dump it
+ def dumpFolder(self, theFolder):
+ if theFolder.ID() in self.myFeatures:
+ self.myFeatures[theFolder.ID()](theFolder).dump(self)
+
## Dump all parameters
def dumpParameter(self, theFeature):
aFeatureKind = theFeature.getKind()