PartSet_DocumentDataModel::PartSet_DocumentDataModel(QObject* theParent)
: ModuleBase_IDocumentDataModel(theParent),
- myActivePartId(-1), myHistoryBackOffset(0)
+ myActivePartId(-1)
{
// Create a top part of data tree model
myModel = new PartSet_TopDataModel(this);
myActivePartId = aRootDoc->index(aFeature);
myPartModels[myActivePartId]->setItemsColor(ACTIVE_COLOR);
}
- //QModelIndex* aIndex = toSourceModelIndex(theIndex);
- //if (!aIndex)
- // return false;
-
- //const QAbstractItemModel* aModel = aIndex->model();
-
- //if (isPartSubModel(aModel)) {
- // // if this is root node (Part item index)
- // if (!aIndex->parent().isValid()) {
- // if (myActivePart)
- // myActivePart->setItemsColor(PASSIVE_COLOR);
-
- // if (myActivePart == aModel) {
- // myActivePart = 0;
- // myActivePartIndex = QModelIndex();
- // } else {
- // myActivePart = (PartSet_PartModel*)aModel;
- // myActivePartIndex = theIndex;
- // }
-
- // if (myActivePart) {
- // myActivePart->setItemsColor(ACTIVE_COLOR);
- // myModel->setItemsColor(PASSIVE_COLOR);
- // } else
- // myModel->setItemsColor(ACTIVE_COLOR);
- // return true;
- // }
- // }
return true;
}
int PartSet_DocumentDataModel::lastHistoryRow() const
{
- return rowCount() - 1 - myHistoryBackOffset;
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ FeaturePtr aFeature = aRootDoc->currentFeature();
+ return historyOffset() + aRootDoc->index(aFeature);
}
void PartSet_DocumentDataModel::setLastHistoryItem(const QModelIndex& theIndex)
{
- myHistoryBackOffset = rowCount() - 1 - theIndex.row();
+ if (theIndex.internalId() == HistoryNode) {
+ ObjectPtr aObject = object(theIndex);
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aRootDoc = aMgr->moduleDocument();
+ aMgr->startOperation(tr("History change").toStdString());
+ aRootDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
+ aMgr->finishOperation();
+ }
}
QModelIndex PartSet_DocumentDataModel::lastHistoryItem() const
//! List of saved QModelIndexes created by sub-models
QList<QModelIndex*> myIndexes;
- int myHistoryBackOffset;
-
static QMap<QString, QString> myIcons;
};
#include "PartSet_SketcherMgr.h"
#include "PartSet_Tools.h"
+#include <PartSetPlugin_Part.h>
+
#include <GeomAPI_Pnt2d.h>
#include <GeomDataAPI_Point2D.h>
{
QObjectPtrList aObjects = myModule->workshop()->selection()->selectedObjects();
if (aObjects.size() > 0) {
- ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
- if (aPart) {
- aPart->activate();
+ ObjectPtr aObj = aObjects.first();
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
+ if (!aPart.get()) {
+ FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+ if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
+ aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
+ }
}
+ if (aPart.get())
+ aPart->activate();
}
}
ObjectPtr aObject = aObjects.first();
if (aObject) {
ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
- if (aPart) {
- if (aMgr->activeDocument() == aPart->partDoc())
+ FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
+ bool isPart = aPart.get() ||
+ (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID()));
+ if (isPart) {
+ DocumentPtr aPartDoc;
+ if (!aPart.get()) {
+ aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
+ }
+ aPartDoc = aPart->partDoc();
+ if (aMgr->activeDocument() == aPartDoc)
theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD"));
else
theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD"));
}
} else if (aSelected == 0) {
// if there is no selection then it means that upper label is selected
- if (aMgr->activeDocument() != aMgr->moduleDocument())
- theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
+ QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
+ if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
+ if (aMgr->activeDocument() != aMgr->moduleDocument())
+ theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
}
}
//******************************************************************
//******************************************************************
PartSet_PartDataModel::PartSet_PartDataModel(QObject* theParent)
- : PartSet_PartModel(theParent), myHistoryBackOffset(0)
+ : PartSet_PartModel(theParent)
{
}
int PartSet_PartDataModel::lastHistoryRow() const
{
- return rowCount() - 1 - myHistoryBackOffset;
+ DocumentPtr aDoc = partDocument();
+ FeaturePtr aFeature = aDoc->currentFeature();
+ return getRowsNumber() + aDoc->index(aFeature);
}
void PartSet_PartDataModel::setLastHistoryItem(const QModelIndex& theIndex)
{
if (theIndex.internalId() == HistoryObject) {
- myHistoryBackOffset = rowCount() - 1 - theIndex.row();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ObjectPtr aObject = object(theIndex);
+ DocumentPtr aDoc = partDocument();
+ aMgr->startOperation(tr("History change").toStdString());
+ aDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
+ aMgr->finishOperation();
}
}
GroupObject,
HistoryObject
};
-
- int myHistoryBackOffset;
};
#endif