myObjs->removeFeature(theFeature);
}
+// recursive function to check if theSub is a child of theMain composite feature
+// through all the hierarchy of parents
+static bool isSub(const CompositeFeaturePtr theMain, const FeaturePtr theSub) {
+ CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(theSub);
+ if (!aParent.get())
+ return false;
+ if (aParent == theMain)
+ return true;
+ return isSub(theMain, aParent);
+}
+
+
void Model_Document::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
{
bool aCurrentUp = theMoved == currentFeature(false);
if (aCurrentUp) {
setCurrentFeatureUp();
}
+ // if user adds after high-level feature with nested, add it after all nested (otherwise the nested will be disabled)
+ CompositeFeaturePtr aCompositeAfter = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theAfterThis);
+ if (aCompositeAfter.get()) {
+ FeaturePtr aSub = aCompositeAfter;
+ do {
+ FeaturePtr aNext = myObjs->nextFeature(aSub);
+ if (!isSub(aCompositeAfter, aNext)) {
+ theAfterThis = aSub;
+ break;
+ }
+ aSub = aNext;
+ } while (aSub.get());
+ }
myObjs->moveFeature(theMoved, theAfterThis);
if (aCurrentUp) { // make the moved feature enabled or disabled due to the real status
return std::shared_ptr<ModelAPI_Feature>(); // null feature means the higher than first
}
-// recursive function to check if theSub is a child of theMain composite feature
-// through all the hierarchy of parents
-static bool isSub(const CompositeFeaturePtr theMain, const FeaturePtr theSub) {
- CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(theSub);
- if (!aParent.get())
- return false;
- if (aParent == theMain)
- return true;
- return isSub(theMain, aParent);
-}
-
void Model_Document::setCurrentFeature(
std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theVisible)
{
Events_Loop::loop()->send(aMsg, true);
}
-void Model_EventCreator::sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
- const std::string& theGroup) const
+void Model_EventCreator::sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const
{
std::shared_ptr<Model_OrderUpdatedMessage> aMsg(
- new Model_OrderUpdatedMessage(theDoc, theGroup));
+ new Model_OrderUpdatedMessage(theReordered));
Events_Loop::loop()->send(aMsg, true);
}
/////////////////////// REORDERED MESSAGE /////////////////////////////
Model_OrderUpdatedMessage::Model_OrderUpdatedMessage(
- const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
- : ModelAPI_OrderUpdatedMessage(messageId(), 0),
- myDoc(theDoc), myGroup(theGroup)
+ FeaturePtr theReordered, const void* theSender)
+ : ModelAPI_OrderUpdatedMessage(messageId(), theSender),
+ myReordered(theReordered)
{
}
const std::string& theGroup) const;
/// creates reordered message and sends to the loop
- virtual void sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
- const std::string& theGroup) const;
+ virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const;
/// must be one per application, the constructor for internal usage only
Model_EventCreator();
/// Message that feature was deleted (used for Object Browser update)
class Model_OrderUpdatedMessage : public ModelAPI_OrderUpdatedMessage
{
- std::shared_ptr<ModelAPI_Document> myDoc; ///< document owner of the feature
- std::string myGroup; ///< group identifier that contained the deleted feature
+ std::shared_ptr<ModelAPI_Feature> myReordered; ///< the feature that was moved
/// Use ModelAPI for creation of this event.
- Model_OrderUpdatedMessage(const std::shared_ptr<ModelAPI_Document>& theDoc,
- const std::string& theGroup);
+ Model_OrderUpdatedMessage(FeaturePtr theReordered,
+ const void* theSender = 0);
friend class Model_EventCreator;
public:
/// Returns the document that has been updated
- virtual std::shared_ptr<ModelAPI_Document> document() const
- {
- return myDoc;
- }
-
- /// Returns the group where the objects were reordered
- virtual const std::string& group() const
+ virtual std::shared_ptr<ModelAPI_Feature> reordered()
{
- return myGroup;
+ return myReordered;
}
/// Returns the identifier of this message
// update the feature and the history
clearHistory(theMoved);
// make sure all (selection) attributes of moved feature will be updated
- theMoved->data()->setUpdateID(0);
static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
ModelAPI_EventCreator::get()->sendUpdated(theMoved, EVENT_UPD);
- ModelAPI_EventCreator::get()->sendReordered(theMoved->document(), theMoved->groupName());
+ ModelAPI_EventCreator::get()->sendReordered(theMoved);
}
void Model_Objects::clearHistory(ObjectPtr theObj)
aLoop->registerListener(this, kPreviewBlockedEvent);
static const Events_ID kPreviewRequestedEvent = aLoop->eventByName(EVENT_PREVIEW_REQUESTED);
aLoop->registerListener(this, kPreviewRequestedEvent);
+ static const Events_ID kReorderEvent = aLoop->eventByName(EVENT_ORDER_UPDATED);
+ aLoop->registerListener(this, kReorderEvent);
// Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true";
myIsParamUpdated = false;
static const Events_ID kStabilityEvent = aLoop->eventByName(EVENT_STABILITY_CHANGED);
static const Events_ID kPreviewBlockedEvent = aLoop->eventByName(EVENT_PREVIEW_BLOCKED);
static const Events_ID kPreviewRequestedEvent = aLoop->eventByName(EVENT_PREVIEW_REQUESTED);
+ static const Events_ID kReorderEvent = aLoop->eventByName(EVENT_ORDER_UPDATED);
#ifdef DEB_UPDATE
std::cout<<"****** Event "<<theMessage->eventID().eventText()<<std::endl;
// in the end of transaction everything is updated, so clear the old objects
myIsParamUpdated = false;
myWaitForFinish.clear();
+ } else if (theMessage->eventID() == kReorderEvent) {
+ std::shared_ptr<ModelAPI_OrderUpdatedMessage> aMsg =
+ std::dynamic_pointer_cast<ModelAPI_OrderUpdatedMessage>(theMessage);
+ addModified(aMsg->reordered(), aMsg->reordered()); // to update all attributes
}
}
}
ModelAPI_OrderUpdatedMessage::ModelAPI_OrderUpdatedMessage(const Events_ID theID,
- const void* theSender)
+ const void* theSender)
: Events_Message(theID, theSender)
{
class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
{
protected:
- /// Creates an empty message
+ /// Creates a message:
ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
/// The virtual destructor
virtual ~ModelAPI_OrderUpdatedMessage();
public:
/// Returns the document that has been updated
- virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
-
- /// Returns the groups where the objects were reordered
- virtual const std::string& group() const = 0;
+ virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
/// Returns the identifier of the kind of a message
virtual const Events_ID messageId() = 0;
virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
const std::string& theGroup) const = 0;
/// creates reordered message and sends to the loop
- virtual void sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
- const std::string& theGroup) const = 0;
+ virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
/// returns the creator instance
static const ModelAPI_EventCreator* get();
} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_ORDER_UPDATED)) {
std::shared_ptr<ModelAPI_OrderUpdatedMessage> aUpdMsg =
std::dynamic_pointer_cast<ModelAPI_OrderUpdatedMessage>(theMessage);
- DocumentPtr aDoc = aUpdMsg->document();
- std::string aGroup = aUpdMsg->group();
+ DocumentPtr aDoc = aUpdMsg->reordered()->document();
+ std::string aGroup = aUpdMsg->reordered()->group();
QModelIndex aParent;
int aStartId = 0;