static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
aFeature->setDisabled(false); // by default created feature is enabled
- setCurrentFeature(aFeature); // after all this feature stays in the document, so make it current
+ setCurrentFeature(aFeature, false); // after all this feature stays in the document, so make it current
} else { // feature must be executed
// no creation event => updater not working, problem with remove part
aFeature->execute();
}
}
// if this feature is current, make the current the previous feature
- if (theFeature == currentFeature()) {
+ if (theFeature == currentFeature(false)) {
int aCurrentIndex = index(theFeature);
if (aCurrentIndex != -1) {
setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(
- object(ModelAPI_Feature::group(), aCurrentIndex - 1)));
+ object(ModelAPI_Feature::group(), aCurrentIndex - 1)), false);
}
}
return aResult;
}
-std::shared_ptr<ModelAPI_Feature> Model_Document::currentFeature()
+std::shared_ptr<ModelAPI_Feature> Model_Document::currentFeature(const bool theVisible)
{
TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE);
Handle(TDF_Reference) aRef;
if (aRefLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
TDF_Label aLab = aRef->Get();
- return feature(aLab);
+ FeaturePtr aResult = feature(aLab);
+ if (theVisible) { // get nearest visible (in history) going up
+ int aTag = aLab.Tag();
+ while(aTag > 1 && (!aResult.get() || !aResult->isInHistory())) {
+ aTag--;
+ aLab = aLab.Father().FindChild(aTag);
+ aResult = feature(aLab);
+ }
+ if (aTag <= 1)
+ aResult.reset();
+ }
+ return aResult;
}
return std::shared_ptr<ModelAPI_Feature>(); // null feature means the higher than first
}
-void Model_Document::setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent)
+void Model_Document::setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
+ const bool theVisible)
{
TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE);
if (theCurrent.get()) {
std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theCurrent->data());
if (aData.get()) {
TDF_Label aFeatureLabel = aData->label().Father();
+ if (theVisible) { // make features below which are not in history also enabled: sketch subs
+ int aTag = aFeatureLabel.Tag();
+ FeaturePtr aNextFeature;
+ TDF_Label aNextLabel;
+ for(aTag++; true; aTag++) {
+ TDF_Label aLabel = aFeatureLabel.Father().FindChild(aTag, 0);
+ if (aLabel.IsNull())
+ break;
+ FeaturePtr aFeature = feature(aLabel);
+ if (aFeature.get()) {
+ if (aFeature->isInHistory())
+ break;
+ aNextFeature = aFeature;
+ aNextLabel = aLabel;
+ }
+ }
+ if (aNextFeature.get()) {
+ theCurrent = aNextFeature;
+ aFeatureLabel = aNextLabel;
+ }
+ }
Handle(TDF_Reference) aRef;
if (aRefLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
aRef->Set(aFeatureLabel);
//! Returns the feature that is currently edited in this document, normally
//! this is the latest created feature
+ //! \param theVisible use visible features only: flag is true for Object Browser functionality
//! \returns null if next created feature must be the first
- MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> currentFeature();
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible);
//! Sets the current feature: all features below will be disabled, new features
//! will be appended after this one.
- MODEL_EXPORT virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent);
+ //! \param theCurrent the selected feature as current: blow it everythin become disabled
+ //! \param theVisible use visible features only: flag is true for Object Browser functionality
+ MODEL_EXPORT virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
+ const bool theVisible);
/// Creates a construction cresults
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
//! Returns the feature that is currently edited in this document, normally
//! this is the latest created feature
+ //! \param theVisible use visible features only: flag is true for Object Browser functionality
//! \returns null if next created feature must be the first
- virtual std::shared_ptr<ModelAPI_Feature> currentFeature() = 0;
+ virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible) = 0;
//! Sets the current feature: all features below will be disabled, new features
//! will be appended after this one.
- virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent) = 0;
+ //! \param theCurrent the selected feature as current: blow it everythin become disabled
+ //! \param theVisible use visible features only: flag is true for Object Browser functionality
+ virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
+ const bool theVisible) = 0;
/// To virtually destroy the fields of successors
MODELAPI_EXPORT virtual ~ModelAPI_Document();
int PartSet_DocumentDataModel::lastHistoryRow() const
{
DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- FeaturePtr aFeature = aRootDoc->currentFeature();
+ FeaturePtr aFeature = aRootDoc->currentFeature(true);
if (aFeature.get())
return historyOffset() + aRootDoc->index(aFeature);
else
if (theIndex.internalId() == HistoryNode) {
ObjectPtr aObject = object(theIndex);
aMgr->startOperation(aOpName);
- aRootDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
+ aRootDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject), true);
aMgr->finishOperation();
} else {
aMgr->startOperation(aOpName);
- aRootDoc->setCurrentFeature(FeaturePtr());
+ aRootDoc->setCurrentFeature(FeaturePtr(), true);
aMgr->finishOperation();
}
}
int PartSet_PartDataModel::lastHistoryRow() const
{
DocumentPtr aDoc = partDocument();
- FeaturePtr aFeature = aDoc->currentFeature();
+ FeaturePtr aFeature = aDoc->currentFeature(true);
if (aFeature.get())
return getRowsNumber() + aDoc->index(aFeature);
else
if (theIndex.internalId() == HistoryObject) {
ObjectPtr aObject = object(theIndex);
aMgr->startOperation(aOpName);
- aDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
+ aDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject), true);
aMgr->finishOperation();
} else {
aMgr->startOperation(aOpName);
- aDoc->setCurrentFeature(FeaturePtr());
+ aDoc->setCurrentFeature(FeaturePtr(), true);
aMgr->finishOperation();
}
}