const Event_ID& eventID() const {return myEventId;}
//! Returns sender of the message or NULL if it is anonymous message
- void* sender() {return mySender;}
+ void* sender() const {return mySender;}
};
#endif
const Event_ID& theEvent);
/// Returns the feature that has been updated
- std::shared_ptr<ModelAPI_Feature> feature() {return myFeature;}
+ std::shared_ptr<ModelAPI_Feature> feature() const {return myFeature;}
/// Returns the document that has been updated
- std::shared_ptr<ModelAPI_Document> document() {return myDoc;}
+ std::shared_ptr<ModelAPI_Document> document() const {return myDoc;}
};
/// Message that feature was deleted (used for Object Browser update)
static const Event_ID messageId();
/// Returns the feature that has been updated
- std::shared_ptr<ModelAPI_Document> document() {return myDoc;}
+ std::shared_ptr<ModelAPI_Document> document() const {return myDoc;}
/// Returns the group where the feature was deleted
- const std::string& group() {return myGroup;}
+ const std::string& group() const {return myGroup;}
};
#endif
//! Returns 0 if the given index is not index of a feature
virtual FeaturePtr feature(const QModelIndex& theIndex) const = 0;
+ //! Returns parent index of the given feature
+ virtual QModelIndex findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
+
protected:
std::shared_ptr<ModelAPI_Document> myDocument;
};
XGUI_PartModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent):
XGUI_FeaturesModel(theDocument, theParent) {}
- void setPartId(int theId) { myId = theId; }
+ void setPartId(int theId) { myId = theId; }
+
+ //! Returns true if the given document is a sub-document of this tree
+ virtual bool hasDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) const = 0;
protected:
//! Id of the current part object in the document
void XGUI_DocumentDataModel::processEvent(const Event_Message* theMessage)
{
if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_CREATED) {
- // Add a new part
- int aStart = myModel->rowCount(QModelIndex()) + myPartModels.size();
- beginInsertRows(QModelIndex(), aStart, aStart + 1);
- XGUI_PartDataModel* aModel = new XGUI_PartDataModel(myDocument, this);
- aModel->setPartId(myPartModels.count());
- myPartModels.append(aModel);
- endInsertRows();
+ const ModelAPI_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const ModelAPI_FeatureUpdatedMessage*>(theMessage);
+ std::shared_ptr<ModelAPI_Document> aDoc = aUpdMsg->document();
+ std::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
+
+ if (aDoc == myDocument) {
+ if (aFeature->getGroup().compare(PARTS_GROUP) == 0) {
+ // Add a new part
+ int aStart = myModel->rowCount(QModelIndex()) + myPartModels.size();
+ beginInsertRows(QModelIndex(), aStart, aStart + 1);
+ XGUI_PartDataModel* aModel = new XGUI_PartDataModel(myDocument, this);
+ aModel->setPartId(myPartModels.count());
+ myPartModels.append(aModel);
+ endInsertRows();
+ } else {
+ QModelIndex aIndex = myModel->findParent(aFeature);
+ int aStart = myModel->rowCount(aIndex);
+ aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex));
+ beginInsertRows(aIndex, aStart-1, aStart);
+ endInsertRows();
+ if (aStart == 1) // Update parent if this is a first child in order to update node decoration
+ emit dataChanged(aIndex, aIndex);
+ }
+ } else {
+ XGUI_PartModel* aPartModel = 0;
+ QList<XGUI_PartModel*>::const_iterator aIt;
+ for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) {
+ if ((*aIt)->hasDocument(aDoc)) {
+ aPartModel = (*aIt);
+ break;
+ }
+ }
+ if (aPartModel) {
+ QModelIndex aIndex = aPartModel->findParent(aFeature);
+ int aStart = aPartModel->rowCount(aIndex);
+ aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex));
+ beginInsertRows(aIndex, aStart-1, aStart);
+ endInsertRows();
+ if (aStart == 1) // Update parent if this is a first child in order to update node decoration
+ emit dataChanged(aIndex, aIndex);
+ }
+ }
} else {
// Reset whole tree
beginResetModel();
case ParamObject:
{
std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
- return aFeature->data()->getName().c_str();
+ if (aFeature)
+ return aFeature->data()->getName().c_str();
}
case ConstructFolder:
return tr("Constructions");
case ConstructObject:
{
std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
- return aFeature->data()->getName().c_str();
+ if (aFeature)
+ return aFeature->data()->getName().c_str();
}
}
break;
}
+QModelIndex XGUI_TopDataModel::findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
+{
+ QString aGroup(theFeature->getGroup().c_str());
+
+ if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
+ return createIndex(0, 0, (quintptr) ParamsFolder);
+ if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
+ return createIndex(1, 0, (quintptr) ConstructFolder);
+ return QModelIndex();
+}
+
+
//******************************************************************
//******************************************************************
//******************************************************************
case MyRoot:
{
std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
- return aFeature->data()->getName().c_str();
+ if (aFeature)
+ return aFeature->data()->getName().c_str();
}
case ParamsFolder:
return tr("Parameters");
{
std::shared_ptr<ModelAPI_Feature> aFeature =
featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
- return aFeature->data()->getName().c_str();
+ if (aFeature)
+ return aFeature->data()->getName().c_str();
}
case ConstructObject:
{
std::shared_ptr<ModelAPI_Feature> aFeature =
featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
- return aFeature->data()->getName().c_str();
+ if (aFeature)
+ return aFeature->data()->getName().c_str();
}
}
break;
}
return 0;
}
+
+bool XGUI_PartDataModel::hasDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) const
+{
+ return (featureDocument() == theDoc);
+}
+
+
+QModelIndex XGUI_PartDataModel::findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
+{
+ QString aGroup(theFeature->getGroup().c_str());
+
+ if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
+ return createIndex(0, 0, (quintptr) ParamsFolder);
+ if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
+ return createIndex(1, 0, (quintptr) ConstructFolder);
+ return QModelIndex();
+}
\ No newline at end of file
//! Returns 0 if the given index is not index of a feature
virtual FeaturePtr feature(const QModelIndex& theIndex) const;
+ virtual QModelIndex findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
+
private:
//! Types of QModelIndexes
enum DataIds {
//! Returns 0 if the given index is not index of a feature
virtual FeaturePtr feature(const QModelIndex& theIndex) const;
+ //! Returns true if the given document is a sub-document of this tree
+ virtual bool hasDocument(const std::shared_ptr<ModelAPI_Document>& theDoc) const;
+
+ //! Returns parent index of the given feature
+ virtual QModelIndex findParent(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
+
private:
std::shared_ptr<ModelAPI_Document> featureDocument() const;
XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) :
QObject(theParent), myWorkshop(theParent)
{
- XGUI_ObjectsBrowser* aObjBrowser = myWorkshop->mainWindow()->objectBrowser();
-
- connect(aObjBrowser, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
}
+void XGUI_SelectionMgr::connectObjectBrowser(XGUI_ObjectsBrowser* theOB)
+{
+ myObjectBrowser = theOB;
+ connect(myObjectBrowser, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+}
XGUI_SelectionMgr::~XGUI_SelectionMgr()
{
#include <QObject>
class XGUI_Workshop;
+class XGUI_ObjectsBrowser;
/**\class XGUI_SelectionMgr
* \ingroup GUI
//! Returns list of currently selected objects
QFeatureList selectedData() const { return mySelectedData; }
+ void connectObjectBrowser(XGUI_ObjectsBrowser* theOB);
+
signals:
//! Emited when selection in a one of viewers was changed
void selectionChanged();
private:
XGUI_Workshop* myWorkshop;
+ XGUI_ObjectsBrowser* myObjectBrowser;
//! List of selected features
QFeatureList mySelectedData;
void XGUI_Workshop::onNew()
{
QApplication::setOverrideCursor(Qt::WaitCursor);
- if (myMainWindow->objectBrowser() == 0)
+ if (myMainWindow->objectBrowser() == 0) {
myMainWindow->createDockWidgets();
+ mySelector->connectObjectBrowser(myMainWindow->objectBrowser());
+ }
myMainWindow->showObjectBrowser();
myMainWindow->showPythonConsole();
QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();