}
boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(
- const string& theGroupID, const int theIndex)
+ const string& theGroupID, const int theIndex, const bool isOperation)
{
TDF_Label aGroupLab = groupLabel(theGroupID);
Handle(TDataStd_ReferenceArray) aRefs;
TDF_Label aFeatureLab = aRefs->Value(theIndex);
boost::shared_ptr<ModelAPI_Feature> aFeature = feature(aFeatureLab);
- if (theGroupID == FEATURES_GROUP) { // just returns the feature from the history
+ if (theGroupID == FEATURES_GROUP || isOperation) { // just returns the feature from the history
return aFeature;
} else { // create a new object from the group to return it
Handle(TDataStd_Name) aName; // name of the object
void Model_Document::setUniqueName(boost::shared_ptr<ModelAPI_Feature> theFeature)
{
- // first count all objects of such kind to start with index = count + 1
- int a, aNumObjects = 0;
- int aSize = size(FEATURES_GROUP);
- for(a = 0; a < aSize; a++) {
- if (feature(FEATURES_GROUP, a)->getKind() == theFeature->getKind())
- aNumObjects++;
+ string aName; // result
+ // iterate all features but also iterate group of this feature if object is not in history
+ list<string> aGroups;
+ aGroups.push_back(FEATURES_GROUP);
+ if (!theFeature->isInHistory()) {
+ aGroups.push_back(theFeature->getGroup());
}
- // generate candidate name
- stringstream aNameStream;
- aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
- string aName = aNameStream.str();
- // check this is unique, if not, increase index by 1
- for(a = 0; a < aSize;) {
- if (feature(FEATURES_GROUP, a)->data()->getName() == aName) {
- aNumObjects++;
- stringstream aNameStream;
- aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
- // reinitialize iterator to make sure a new name is unique
- a = 0;
- } else a++;
+ for(list<string>::iterator aGIter = aGroups.begin(); aGIter != aGroups.end(); aGIter++) {
+ // first count all objects of such kind to start with index = count + 1
+ int a, aNumObjects = 0;
+ int aSize = size(*aGIter);
+ for(a = 0; a < aSize; a++) {
+ if (feature(*aGIter, a)->getKind() == theFeature->getKind())
+ aNumObjects++;
+ }
+ // generate candidate name
+ stringstream aNameStream;
+ aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+ aName = aNameStream.str();
+ // check this is unique, if not, increase index by 1
+ for(a = 0; a < aSize;) {
+ if (feature(*aGIter, a, true)->data()->getName() == aName) {
+ aNumObjects++;
+ stringstream aNameStream;
+ aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+ // reinitialize iterator to make sure a new name is unique
+ a = 0;
+ } else a++;
+ }
}
-
theFeature->data()->setName(aName);
}
MODEL_EXPORT virtual const std::string& id() const {return myID;}
//! Returns the feature in the group by the index (started from zero)
+ //! \param theGroupID group that contains a feature
+ //! \param theIndex zero-based index of feature in the group
+ //! \param isOperation if it is true, returns feature (not Object)
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature>
- feature(const std::string& theGroupID, const int theIndex);
+ feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false);
//! Returns the number of features in the group
MODEL_EXPORT virtual int size(const std::string& theGroupID);
MODELAPI_EXPORT virtual const std::string& id() const = 0;
//! Returns the feature in the group by the index (started from zero)
+ //! \param theGroupID group that contains a feature
+ //! \param theIndex zero-based index of feature in the group
+ //! \param isOperation if it is true, returns feature (not Object)
MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature>
- feature(const std::string& theGroupID, const int theIndex) = 0;
+ feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false) = 0;
//! Returns the number of features in the group
MODELAPI_EXPORT virtual int size(const std::string& theGroupID) = 0;
// find sketch that references to this feature
int aSketches = document()->size("Construction");
for(int a = 0; a < aSketches && !mySketch; a++) {
- boost::shared_ptr<ModelAPI_Object> anObj =
- boost::dynamic_pointer_cast<ModelAPI_Object>(document()->feature("Construction", a));
- if (anObj) {
- boost::shared_ptr<SketchPlugin_Sketch> aSketch =
- boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj->featureRef());
- if (aSketch) {
- std::list<boost::shared_ptr<ModelAPI_Feature> > aList =
- aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
- std::list<boost::shared_ptr<ModelAPI_Feature> >::iterator aSub = aList.begin();
- for(; aSub != aList.end(); aSub++) {
- if ((*aSub)->data()->isEqual(data())) {
- mySketch = aSketch.get();
- break;
- }
+ boost::shared_ptr<SketchPlugin_Sketch> aSketch = boost::
+ dynamic_pointer_cast<SketchPlugin_Sketch>(document()->feature("Construction", a, true));
+ if (aSketch) {
+ std::list<boost::shared_ptr<ModelAPI_Feature> > aList =
+ aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
+ std::list<boost::shared_ptr<ModelAPI_Feature> >::iterator aSub = aList.begin();
+ for(; aSub != aList.end(); aSub++) {
+ if ((*aSub)->data()->isEqual(data())) {
+ mySketch = aSketch.get();
+ break;
}
}
}