/// Returns the identifier of feature-owner, unique in this document
MODEL_EXPORT virtual int featureId() const;
+ // returns all objects referenced to this
+ MODEL_EXPORT virtual const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
+
private:
// removes all information about back references
void eraseBackReferences();
// adds a back reference (with identifier which attribute references to this object
void addBackReference(FeaturePtr theFeature, std::string theAttrID);
- // returns all objects referenced to this
- const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
// returns all references by attributes of this data
// \param the returned list of pairs: id of referenced attribute and list of referenced objects
void referencesToObjects(std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);
TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
for (; aLabIter.More(); aLabIter.Next()) {
TDF_Label aFeatureLabel = aLabIter.Value()->Label();
+ FeaturePtr aFeature;
if (!myObjs.IsBound(aFeatureLabel)) { // a new feature is inserted
// create a feature
- FeaturePtr aNewObj = ModelAPI_Session::get()->createFeature(
+ aFeature = ModelAPI_Session::get()->createFeature(
TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(aLabIter.Value())->Get())
.ToCString());
- if (!aNewObj) { // somethig is wrong, most probably, the opened document has invalid structure
+ if (!aFeature) { // somethig is wrong, most probably, the opened document has invalid structure
Events_Error::send("Invalid type of object in the document");
aLabIter.Value()->Label().ForgetAllAttributes();
continue;
}
// this must be before "setData" to redo the sketch line correctly
- myObjs.Bind(aFeatureLabel, aNewObj);
- aNewFeatures.insert(aNewObj);
- initData(aNewObj, aFeatureLabel, TAG_FEATURE_ARGUMENTS);
+ myObjs.Bind(aFeatureLabel, aFeature);
+ aNewFeatures.insert(aFeature);
+ initData(aFeature, aFeatureLabel, TAG_FEATURE_ARGUMENTS);
// event: model is updated
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
- ModelAPI_EventCreator::get()->sendUpdated(aNewObj, anEvent);
+ ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
// update results of the appeared feature
- updateResults(aNewObj);
+ updateResults(aFeature);
} else { // nothing is changed, both iterators are incremented
- FeaturePtr aFeature = myObjs.Find(aFeatureLabel);
+ aFeature = myObjs.Find(aFeatureLabel);
aKeptFeatures.insert(aFeature);
if (theMarkUpdated) {
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
updateResults(aFeature);
}
}
- // execute new features to restore results: after features creation to make all references valid
- /*std::set<FeaturePtr>::iterator aNewIter = aNewFeatures.begin();
- for(; aNewIter != aNewFeatures.end(); aNewIter++) {
- (*aNewIter)->execute();
- }*/
// check all features are checked: if not => it was removed
NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFIter(myObjs);
while (aFIter.More()) {
static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
- /*
- for (; aRIter != aResults.cend(); aRIter++) {
- boost::shared_ptr<ModelAPI_Result> aRes = *aRIter;
- //aRes->setData(boost::shared_ptr<ModelAPI_Data>()); // deleted flag
- ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
- ModelAPI_EventCreator::get()->sendDeleted(aThis, aRes->groupName());
- }
- */
// redisplay also removed feature (used for sketch and AISObject)
ModelAPI_EventCreator::get()->sendUpdated(aFeature, EVENT_DISP);
aFeature->erase();
mySketch = 0;
}
-/*
SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
{
if (!mySketch) {
// find sketch that references to this feature
- int aSketches = document()->size(ModelAPI_Feature::group());
- for (int a = 0; a < aSketches && !mySketch; a++) {
- ObjectPtr anObj = document()->object(ModelAPI_Feature::group(), a);
+ const std::set<AttributePtr>& aBackRefs = data()->refsToMe();
+ std::set<AttributePtr>::const_iterator aBackRef = aBackRefs.begin();
+ for(; aBackRef != aBackRefs.end(); aBackRef++) {
boost::shared_ptr<SketchPlugin_Sketch> aSketch =
- boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj);
+ boost::dynamic_pointer_cast<SketchPlugin_Sketch>((*aBackRef)->owner());
if (aSketch) {
- std::list<ObjectPtr> aList = aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())
- ->list();
- std::list<ObjectPtr>::iterator aSub = aList.begin();
- for (; aSub != aList.end(); aSub++) {
- if ((*aSub)->data()->isEqual(data())) {
- mySketch = aSketch.get();
- break;
- }
- }
+ mySketch = aSketch.get();
+ break;
}
}
}
return mySketch;
-}*/
+}
AISObjectPtr SketchPlugin_Feature::simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
AISObjectPtr thePrevious)