if (aDoc) {
const TDF_LabelList& aList = myRef->List();
for(TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
- aResult.push_back(aDoc->object(aLIter.Value()));
+ ObjectPtr anObj = aDoc->object(aLIter.Value());
+ if (!anObj) { // try to use father (for feature)
+ anObj = aDoc->object(aLIter.Value().Father());
+ }
+ aResult.push_back(anObj);
}
}
return aResult;
aDocToAdd->initData(aFeature, aFeatureLab, TAG_FEATURE_ARGUMENTS);
// keep the feature ID to restore document later correctly
TDataStd_Comment::Set(aFeatureLab, aFeature->getKind().c_str());
- aDocToAdd->setUniqueName(aFeature);
aDocToAdd->myObjs.Bind(aFeatureLab, aFeature);
// store feature in the history of features array
if (aFeature->isInHistory()) {
ObjectPtr Model_Document::object(TDF_Label theLabel)
{
- TDF_Label aFeatureLabel = theLabel.Father().Father();
+ if (feature(theLabel)) // feature by label
+ return feature(theLabel);
+ TDF_Label aFeatureLabel = theLabel.Father().Father(); // let's suppose it is result
FeaturePtr aFeature = feature(aFeatureLabel);
if (aFeature) {
const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
void Model_Document::setUniqueName(FeaturePtr theFeature)
{
+ if (!theFeature->data()->name().empty()) return; // not needed, name is already defined
std::string aName; // result
// first count all objects of such kind to start with index = count + 1
int aNumObjects = 0;
boost::shared_ptr<ModelAPI_Document> aThis =
Model_Application::getApplication()->getDocument(myID);
boost::shared_ptr<Model_Data> aData(new Model_Data);
- aData->setLabel(theLab.FindChild(theTag + 1));
+ aData->setLabel(theLab.FindChild(theTag));
aData->setObject(theObj);
theObj->setDoc(aThis);
theObj->setData(aData);
FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
- if (aFeature) aFeature->initAttributes();
+ if (aFeature) {
+ setUniqueName(aFeature); // must be before "initAttributes" because duplicate part uses name
+ aFeature->initAttributes();
+ }
}
void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
Model_Application::getApplication()->getDocument(myID);
theResult->setDoc(aThis);
initData(theResult, boost::dynamic_pointer_cast<Model_Data>(theFeatureData)->
- label().Father().FindChild(TAG_FEATURE_RESULTS), theResultIndex);
+ label().Father().FindChild(TAG_FEATURE_RESULTS), theResultIndex + 1);
if (theResult->data()->name().empty()) { // if was not initialized, generate event and set a name
theResult->data()->setName(theFeatureData->name());
}
void PartSetPlugin_Duplicate::initAttributes()
{
PartSetPlugin_Part::initAttributes();
- data()->addAttribute(PartSetPlugin_Duplicate::DOC_REF(), ModelAPI_AttributeRefAttr::type());
+ data()->addAttribute(ORIGIN_REF(), ModelAPI_AttributeRefAttr::type());
- ResultPartPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
- aResult->data()->refattr(ModelAPI_ResultPart::DOC_REF());
- if (!aRef->attr()) { // create a copy: if not created yet attribute is not initialized
- boost::shared_ptr<ModelAPI_PluginManager> aPManager = ModelAPI_PluginManager::get();
- boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
- boost::shared_ptr<PartSetPlugin_Part> aSource; // searching for source document attribute
- for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
- aSource = boost::dynamic_pointer_cast<PartSetPlugin_Part>(
- aRoot->object(ModelAPI_Feature::group(), a));
- if (aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() == aPManager->currentDocument())
- break;
- aSource.reset();
- }
- if (aSource) {
- boost::shared_ptr<ModelAPI_Document> aCopy =
- aPManager->copy(aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value(), data()->name());
- aRef->setObject(aSource);
- }
+ boost::shared_ptr<ModelAPI_PluginManager> aPManager = ModelAPI_PluginManager::get();
+ boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
+ boost::shared_ptr<ModelAPI_ResultPart> aSource; // searching for source document attribute
+ for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
+ aSource = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aRoot->object(getGroup(), a));
+ if (aSource && aSource->data() &&
+ aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() ==
+ aPManager->currentDocument())
+ break;
+ aSource.reset();
+ }
+ if (aSource) {
+ boost::shared_ptr<ModelAPI_Document> aCopy = aPManager->copy(
+ aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value(),
+ data()->name());
}
}
{
public:
/// the reference to copy: reference to the attribute
- inline static const std::string& DOC_REF()
+ inline static const std::string& ORIGIN_REF()
{
static const std::string MY_DUPLICATE_ID("Origin");
return MY_DUPLICATE_ID;
boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
boost::shared_ptr<ModelAPI_Document> aCurrent;
boost::shared_ptr<PartSetPlugin_Part> a;
- for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
- FeaturePtr aFeature =
- boost::dynamic_pointer_cast<ModelAPI_Feature>(aRoot->object(ModelAPI_Feature::group(), a));
+ for(int a = aRoot->size(ModelAPI_Feature::group()) - 1; a >= 0; a--) {
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(
+ aRoot->object(ModelAPI_Feature::group(), a));
if (aFeature->getKind() == PartSetPlugin_Part::ID()) {
boost::shared_ptr<PartSetPlugin_Part> aPart =
boost::static_pointer_cast<PartSetPlugin_Part>(aFeature);
- if (aPart->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() ==
- aPManager->currentDocument()) {
+ if (aPart && aPart->firstResult() &&
+ aPart->firstResult()->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() ==
+ aPManager->currentDocument()) {
// do remove
- aPart->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value()->close();
+ aPart->firstResult()->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value()->close();
aRoot->removeFeature(aPart);
}
}