setCurrentFeature(currentFeature(false), false);
aSession->setCheckTransactions(true);
aSession->setActiveDocument(Model_Session::get()->moduleDocument(), false);
- // this is done in Part result "activate", so no needed here. Causes not-blue active part.
- //aSession->setActiveDocument(anApp->getDocument(myID), true);
+ aSession->setActiveDocument(anApp->getDocument(myID), true);
}
return !isError;
}
void Model_Document::removeFeature(FeaturePtr theFeature)
{
- // if this feature is current, make the current the previous feature
- if (theFeature == currentFeature(false)) {
- FeaturePtr aPrev = myObjs->nextFeature(theFeature, true);
- setCurrentFeature(aPrev, false);
- }
myObjs->removeFeature(theFeature);
}
aLoop->flush(aRedispEvent);
}
+void Model_Document::setCurrentFeatureUp()
+{
+ FeaturePtr aCurrent = currentFeature(false);
+ if (aCurrent.get()) { // if not, do nothing because null is the upper
+ FeaturePtr aPrev = myObjs->nextFeature(aCurrent, true);
+ setCurrentFeature(aPrev, false);
+ }
+}
+
TDF_Label Model_Document::generalLabel() const
{
return myDoc->Main().FindChild(TAG_GENERAL);
MODEL_EXPORT virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
const bool theVisible);
+ //! Makes the current feature one feature upper
+ MODEL_EXPORT virtual void setCurrentFeatureUp();
+
/// Creates a construction cresults
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
void Model_Objects::removeFeature(FeaturePtr theFeature)
{
std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theFeature->data());
- if (aData) {
- TDF_Label aFeatureLabel = aData->label().Father();
- if (myFeatures.IsBound(aFeatureLabel))
- myFeatures.UnBind(aFeatureLabel);
- else
- return; // not found feature => do not remove
-
- clearHistory(theFeature);
+ if (aData && aData->isValid()) {
// checking that the sub-element of composite feature is removed: if yes, inform the owner
std::set<std::shared_ptr<ModelAPI_Feature> > aRefs;
refsToFeature(theFeature, aRefs, false);
}
// erase fields
theFeature->erase();
+
+ TDF_Label aFeatureLabel = aData->label().Father();
+ if (myFeatures.IsBound(aFeatureLabel))
+ myFeatures.UnBind(aFeatureLabel);
+
+ clearHistory(theFeature);
+
static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
ModelAPI_EventCreator::get()->sendUpdated(theFeature, EVENT_DISP);
// erase all attributes under the label of feature
FeaturePtr Model_Objects::nextFeature(FeaturePtr theCurrent, const bool theReverse)
{
std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theCurrent->data());
- if (aData) {
+ if (aData && aData->isValid()) {
TDF_Label aFeatureLabel = aData->label().Father();
Handle(TDataStd_ReferenceArray) aRefs;
if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
void Model_Session::closeAll()
{
Model_Application::getApplication()->deleteAllDocuments();
- //ROOT_DOC->close(true);
}
void Model_Session::startOperation(const std::string& theId)
if (std::dynamic_pointer_cast<Model_Document>(theFeature->document())->executeFeatures() ||
!theFeature->isPersistentResult()) {
if (aFactory->validate(theFeature)) {
+ FeaturePtr aCurrent = theFeature->document()->currentFeature(false);
if (myIsAutomatic || !theFeature->isPersistentResult() /* execute quick, not persistent results */
|| (isUpdated(theFeature) &&
- (theFeature == theFeature->document()->currentFeature(false) ||
- theFeature->document()->currentFeature(false)->isMacro()))) // currently edited
+ (theFeature == aCurrent ||
+ (aCurrent.get() && aCurrent->isMacro())))) // currently edited
{
if (aState == ModelAPI_StateDone || aState == ModelAPI_StateMustBeUpdated) {
executeFeature(theFeature);
//! \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;
+ //! Makes the current feature one feature upper
+ virtual void setCurrentFeatureUp() = 0;
/// To virtually destroy the fields of successors
MODELAPI_EXPORT virtual ~ModelAPI_Document();
void ModelAPI_Feature::erase()
{
+ // if this is the current feature, make the upper feature as current before removing
+ if (document().get() && document()->currentFeature(false).get() == this) {
+ document()->setCurrentFeatureUp();
+ }
+
static Events_Loop* aLoop = Events_Loop::loop();
static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();