//! Returns 0 if the given index is not index of a feature
virtual FeaturePtr feature(const QModelIndex& theIndex) const = 0;
+ //! Returns QModelIndex which corresponds to the given feature
+ //! If the feature is not found then index is not valid
+ virtual QModelIndex featureIndex(const FeaturePtr& theFeature) const = 0;
+
//! Returns parent index of the given feature
virtual QModelIndex findParent(const FeaturePtr& theFeature) const = 0;
: QAbstractItemModel(theParent), myActivePart(0)
{
// Find Document object
- boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+ PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
myDocument = aMgr->currentDocument();
// Register in event loop
// Created object event *******************
if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
- boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
- boost::shared_ptr<ModelAPI_Document> aDoc = aFeature->document();
+ FeaturePtr aFeature = aUpdMsg->feature();
+ DocumentPtr aDoc = aFeature->document();
if (aDoc == myDocument) { // If root objects
if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Update only Parts group
// Deleted object event ***********************
} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) {
const Model_FeatureDeletedMessage* aUpdMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
- boost::shared_ptr<ModelAPI_Document> aDoc = aUpdMsg->document();
+ DocumentPtr aDoc = aUpdMsg->document();
if (aDoc == myDocument) { // If root objects
if (aUpdMsg->group().compare(PARTS_GROUP) == 0) { // Updsate only Parts group
// Deleted object event ***********************
} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED)) {
//const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
- //boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
- //boost::shared_ptr<ModelAPI_Document> aDoc = aFeature->document();
+ //FeaturePtr aFeature = aUpdMsg->feature();
+ //DocumentPtr aDoc = aFeature->document();
// TODO: Identify the necessary index by the modified feature
QModelIndex aIndex;
myActivePart = 0;
myModel->setItemsColor(ACTIVE_COLOR);
}
-
+
Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const
{
Qt::ItemFlags aFlags = QAbstractItemModel::flags(theIndex);
aFlags |= Qt::ItemIsEditable;
}
return aFlags;
-}
\ No newline at end of file
+}
+
+QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const
+{
+ int aRow = -1;
+ XGUI_PartModel* aModel = 0;
+ foreach (XGUI_PartModel* aPartModel, myPartModels) {
+ aRow++;
+ if (aPartModel->part() == theFeature) {
+ aModel = aPartModel;
+ break;
+ }
+ }
+ if (aModel) {
+ return createIndex(aRow, 0, (void*)getModelIndex(aModel->index(0, 0, QModelIndex())));
+ }
+ return QModelIndex();
+}
//! Returns 0 if the given index is not index of a feature
FeaturePtr feature(const QModelIndex& theIndex) const;
+ //! Returns QModelIndex which corresponds to the given feature if this is a part
+ //! If the feature is not found then index is not valid
+ QModelIndex partIndex(const FeaturePtr& theFeature) const;
+
//! Activates a part data model if the index is a Part node index.
//! Returns true if active part changed.
bool activatedIndex(const QModelIndex& theIndex);
{
setHeaderHidden(true);
setModel(new XGUI_DocumentDataModel(this));
+ setEditTriggers(QAbstractItemView::NoEditTriggers);
connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
QMouseEvent* aEvent = (QMouseEvent*) theEvent;
QPoint aPnt = mapFromGlobal(aEvent->globalPos());
if (childAt(aPnt) != myActiveDocLbl) {
- closeDocNameEditing(false);
+ closeDocNameEditing(true);
}
} else if (theEvent->type() == QEvent::KeyRelease) {
QKeyEvent* aEvent = (QKeyEvent*) theEvent;
}
//***************************************************
-void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate)
+void XGUI_ObjectsBrowser::activatePart(const FeaturePtr& thePart)
{
- if (toActivate) {
- QModelIndex aIndex = myTreeView->currentIndex();
+ if (thePart) {
+ QModelIndex aIndex = myDocModel->partIndex(thePart);
if ((myDocModel->activePartIndex() != aIndex) && myDocModel->activePartIndex().isValid()) {
myTreeView->setExpanded(myDocModel->activePartIndex(), false);
bool isChanged = myDocModel->activatedIndex(aIndex);
if (isChanged) {
if (myDocModel->activePartIndex().isValid()) {
+ myTreeView->setExpanded(aIndex.parent(), true);
myTreeView->setExpanded(aIndex, true);
onActivePartChanged(myDocModel->feature(aIndex));
} else {
XGUI_DataTree* treeView() const { return myTreeView; }
//! Activates currently selected part. Signal activePartChanged will not be sent
- void activateCurrentPart(bool toActivate);
+ void activatePart(const FeaturePtr& thePart);
signals:
//! Emited when selection is changed
QModelIndex XGUI_TopDataModel::findParent(const FeaturePtr& theFeature) const
{
- QString aGroup(theFeature->getGroup().c_str());
-
- if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
- return createIndex(0, 0, (qint32) ParamsFolder);
- if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
- return createIndex(1, 0, (qint32) ConstructFolder);
- return QModelIndex();
+ return findGroup(theFeature->getGroup().c_str());
}
QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const
return QModelIndex();
}
+QModelIndex XGUI_TopDataModel::featureIndex(const FeaturePtr& theFeature) const
+{
+ QModelIndex aIndex;
+ if (theFeature) {
+ std::string aGroup = theFeature->getGroup();
+ int aNb = myDocument->size(aGroup);
+ int aRow = -1;
+ for (int i = 0; i < aNb; i++) {
+ if (myDocument->feature(aGroup, i, true) == theFeature) {
+ aRow = i;
+ break;
+ }
+ }
+ if (aRow != -1) {
+ if (aGroup.compare(PARAMETERS_GROUP) == 0)
+ return createIndex(aRow, 0, (qint32) ParamObject);
+ if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+ return createIndex(aRow, 0, (qint32) ConstructObject);
+ }
+ }
+ return aIndex;
+}
+
+
//******************************************************************
//******************************************************************
case ConstructFolder:
return createIndex(theRow, 0, (qint32) ConstructObject);
case BodiesFolder:
- return createIndex(theRow, 0, (qint32) BodieswObject);
+ return createIndex(theRow, 0, (qint32) BodiesObject);
}
return QModelIndex();
}
return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3, true);
case ParamsFolder:
case ConstructFolder:
+ case BodiesFolder:
return FeaturePtr();
case ParamObject:
return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row(), true);
case ConstructObject:
return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+ //case BodiesObject:
+ // return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
}
return FeaturePtr();
}
QModelIndex XGUI_PartDataModel::findParent(const FeaturePtr& theFeature) const
{
- QString aGroup(theFeature->getGroup().c_str());
-
- if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
- return createIndex(0, 0, (qint32) ParamsFolder);
- if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
- return createIndex(1, 0, (qint32) ConstructFolder);
- return QModelIndex();
+ return findGroup(theFeature->getGroup().c_str());
}
QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
FeaturePtr XGUI_PartDataModel::part() const
{
return myDocument->feature(PARTS_GROUP, myId, true);
-}
\ No newline at end of file
+}
+
+QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const
+{
+ QModelIndex aIndex;
+ if (theFeature) {
+ if (part() == theFeature)
+ return aIndex;
+
+ std::string aGroup = theFeature->getGroup();
+ int aNb = myDocument->size(aGroup);
+ int aRow = -1;
+ for (int i = 0; i < aNb; i++) {
+ if (myDocument->feature(aGroup, i, true) == theFeature) {
+ aRow = i;
+ break;
+ }
+ }
+ if (aRow != -1) {
+ if (aGroup.compare(PARAMETERS_GROUP) == 0)
+ return createIndex(aRow, 0, (qint32) ParamObject);
+ if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+ return createIndex(aRow, 0, (qint32) ConstructObject);
+ }
+ }
+ return aIndex;
+}
//! Returns 0 if the given index is not index of a feature
virtual FeaturePtr feature(const QModelIndex& theIndex) const;
+ //! Returns QModelIndex which corresponds to the given feature
+ //! If the feature is not found then index is not valid
+ virtual QModelIndex featureIndex(const FeaturePtr& theFeature) const;
+
//! Returns parent index of the given feature
virtual QModelIndex findParent(const FeaturePtr& theFeature) const;
//! Returns 0 if the given index is not index of a feature
virtual FeaturePtr feature(const QModelIndex& theIndex) const;
+ //! Returns QModelIndex which corresponds to the given feature
+ //! If the feature is not found then index is not valid
+ virtual QModelIndex featureIndex(const FeaturePtr& theFeature) const;
+
//! Returns true if the given document is a sub-document of this tree
virtual bool hasDocument(const DocumentPtr& theDoc) const;
ConstructFolder,
ConstructObject,
BodiesFolder,
- BodieswObject,
+ BodiesObject,
HistoryObject
};
#include <QPushButton>
#include <QDockWidget>
#include <QLayout>
+#include <QTimer>
#ifdef _DEBUG
#include <QDebug>
aLoop->registerListener(this, aPartSetId);
Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED);
aLoop->registerListener(this, aFeatureUpdatedId);
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
+
activateModule();
if (myMainWindow) {
myMainWindow->show();
addFeature(aFeatureMsg);
return;
}
+ // Process creation of Part
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
+ const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
+ FeaturePtr aFeature = aUpdMsg->feature();
+ if (aFeature->getKind() == "Part") {
+ //The created part will be created in Object Browser later and we have to activate that
+ // only when it created everywere
+ QTimer::singleShot(50, this, SLOT(activateLastPart()));
+ }
+ }
+
//Update property panel on corresponding message. If there is no current operation (no
//property panel), or received message has different feature to the current - do nothing.
static Events_ID aFeatureUpdatedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED);
//**************************************************************
void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
{
- if (theId == "ACTIVATE_PART_CMD")
- activatePart(true);
+ QFeatureList aFeatures = mySelector->selectedFeatures();
+ if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0))
+ activatePart(aFeatures.first());
else if (theId == "DEACTIVATE_PART_CMD")
- activatePart(false);
+ activatePart(FeaturePtr());
}
//**************************************************************
-void XGUI_Workshop::activatePart(bool toActivate)
+void XGUI_Workshop::activatePart(FeaturePtr theFeature)
{
- if (toActivate) {
- QFeatureList aFeatures = mySelector->selectedFeatures();
- if (aFeatures.size() > 0) {
- changeCurrentDocument(aFeatures.first());
- myObjectBrowser->activateCurrentPart(true);
- }
- } else {
- changeCurrentDocument(FeaturePtr());
- myObjectBrowser->activateCurrentPart(false);
- }
+ changeCurrentDocument(theFeature);
+ myObjectBrowser->activatePart(theFeature);
}
+//**************************************************************
+void XGUI_Workshop::activateLastPart()
+{
+ PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+ DocumentPtr aDoc = aMgr->rootDocument();
+ FeaturePtr aLastPart = aDoc->feature(PARTS_GROUP, aDoc->size(PARTS_GROUP) - 1, true);
+ activatePart(aLastPart);
+}
signals:
void errorOccurred(const QString&);
+public slots:
+ //! Activates or deactivates a part
+ //! If PartPtr is Null pointer then PartSet will be activated
+ void activatePart(FeaturePtr theFeature);
+
+ void activateLastPart();
+
protected:
//Event-loop processing methods:
void addFeature(const Config_FeatureMessage*);
// Creates Dock widgets: Object browser and Property panel
void createDockWidgets();
- //! Activates or deactivates currently selected part
- void activatePart(bool toActivate);
-
QString myCurrentFile;
XGUI_MainWindow* myMainWindow;
XGUI_Module* myPartSetModule;