XGUI_DocumentDataModel.h
XGUI_PartDataModel.h
XGUI_ObjectsBrowser.h
+ XGUI_DataTreeModel.h
+ XGUI_SelectionMgr.h
)
SET(PROJECT_AUTOMOC
XGUI_DocumentDataModel.cpp
XGUI_PartDataModel.cpp
XGUI_ObjectsBrowser.cpp
+ XGUI_SelectionMgr.cpp
)
SET(PROJECT_RESOURCES
#define XGUI_Constants_H
#include <QList>
+#include <ModelAPI_Feature.h>
-//! This file contains varioous constants used in the application
+//! This file contains various constants used in the application
typedef QList<int> QIntList; //!< list of int values
typedef QList<short> QShortList; //!< list of short int values
typedef QList<double> QDoubleList; //!< list of double values
+//! Pointer on feature object
+typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
+typedef QList<FeaturePtr> QFeatureList; //!< List of features
+
namespace XGUI
{
--- /dev/null
+
+
+#ifndef XGUI_DataTreeModel_H
+#define XGUI_DataTreeModel_H
+
+#include <ModelAPI_Document.h>
+#include <QAbstractItemModel>
+
+#include "XGUI_Constants.h"
+
+/**\class XGUI_FeaturesModel
+ * \ingroup GUI
+ * \brief Abstaract class of model object which operates with features data.
+ */
+class XGUI_FeaturesModel : public QAbstractItemModel
+{
+public:
+ XGUI_FeaturesModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent):
+ QAbstractItemModel(theParent), myDocument(theDocument) {}
+
+ //! Returns Feature object by the given Model index.
+ //! Returns 0 if the given index is not index of a feature
+ virtual FeaturePtr feature(const QModelIndex& theIndex) const = 0;
+
+protected:
+ std::shared_ptr<ModelAPI_Document> myDocument;
+};
+
+
+/**\class XGUI_PartModel
+ * \ingroup GUI
+ * \brief Abstaract class of model object which operates with parts data.
+ */
+class XGUI_PartModel : public XGUI_FeaturesModel
+{
+public:
+ XGUI_PartModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent):
+ XGUI_FeaturesModel(theDocument, theParent) {}
+
+ void setPartId(int theId) { myId = theId; }
+
+protected:
+ //! Id of the current part object in the document
+ int myId;
+};
+
+
+#endif
\ No newline at end of file
Event_Loop::loop()->registerListener(this, Event_Loop::eventByName(EVENT_FEATURE_UPDATED));
// Create a top part of data tree model
- myModel = new XGUI_TopDataModel(this);
- myModel->setDocument(myDocument);
+ myModel = new XGUI_TopDataModel(myDocument, this);
}
myPartModels.removeLast();
}
while (myPartModels.size() < aNbParts) {
- myPartModels.append(new XGUI_PartDataModel(this));
+ myPartModels.append(new XGUI_PartDataModel(myDocument, this));
}
for (int i = 0; i < myPartModels.size(); i++)
- myPartModels.at(i)->setDocument(myDocument, i);
+ myPartModels.at(i)->setPartId(i);
}
clearModelIndexes();
endResetModel();
for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt)
delete (*aIt);
myIndexes.clear();
+}
+
+FeaturePtr XGUI_DocumentDataModel::feature(const QModelIndex& theIndex) const
+{
+ QModelIndex aIndex = toSourceModel(theIndex);
+ const XGUI_FeaturesModel* aModel = dynamic_cast<const XGUI_FeaturesModel*>(aIndex.model());
+ return aModel->feature(aIndex);
}
\ No newline at end of file
#ifndef XGUI_DocumentDataModel_H
#define XGUI_DocumentDataModel_H
+#include "XGUI_Constants.h"
+
#include <QAbstractItemModel>
#include <Event_Listener.h>
#include <QList>
class ModelAPI_Document;
-class XGUI_PartDataModel;
+class XGUI_PartModel;
class XGUI_TopDataModel;
/**\class XGUI_DocumentDataModel
virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
+ //! Returns Feature object by the given Model index.
+ //! Returns 0 if the given index is not index of a feature
+ FeaturePtr feature(const QModelIndex& theIndex) const;
+
private:
//! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
XGUI_TopDataModel* myModel;
//! Data models for Parts data tree representation (one data model per a one part)
- QList<XGUI_PartDataModel*> myPartModels;
+ QList<XGUI_PartModel*> myPartModels;
//! List of saved QModelIndexes created by sub-models
QList<QModelIndex*> myIndexes;
: QTreeView(theParent)
{
setHeaderHidden(true);
- XGUI_DocumentDataModel* aDocModel = new XGUI_DocumentDataModel(this);
- setModel(aDocModel);
+ myDocModel = new XGUI_DocumentDataModel(this);
+ setModel(myDocModel);
+
+ connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
+ this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
}
{
}
+
+
+void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected,
+ const QItemSelection& theDeselected)
+{
+ mySelectedData.clear();
+ QModelIndexList aIndexes = selectionModel()->selectedIndexes();
+ QModelIndexList::const_iterator aIt;
+ for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) {
+ FeaturePtr aFeature = myDocModel->feature(*aIt);
+ if (aFeature)
+ mySelectedData.append(aFeature);
+ }
+ emit selectionChanged();
+}
\ No newline at end of file
#ifndef XGUI_ObjectsBrowser_H
#define XGUI_ObjectsBrowser_H
+#include "XGUI_Constants.h"
+
#include <QTreeView>
class XGUI_DocumentDataModel;
XGUI_ObjectsBrowser(QWidget* theParent);
virtual ~XGUI_ObjectsBrowser();
- QAbstractItemModel* dataModel() const { return myDocModel; }
+ XGUI_DocumentDataModel* dataModel() const { return myDocModel; }
+
+ QFeatureList selectedData() const { return mySelectedData; }
+
+signals:
+ void selectionChanged();
+
+
+private slots:
+ void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
private:
+ XGUI_DocumentDataModel* myDocModel;
- QAbstractItemModel* myDocModel;
+ QFeatureList mySelectedData;
};
#endif
\ No newline at end of file
#include <QIcon>
-XGUI_TopDataModel::XGUI_TopDataModel(QObject* theParent)
- : QAbstractItemModel(theParent)
+XGUI_TopDataModel::XGUI_TopDataModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent)
+ : XGUI_FeaturesModel(theDocument, theParent)
{
}
return rowCount(theParent) > 0;
}
+FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
+{
+ switch (theIndex.internalId()) {
+ case ParamsFolder:
+ case ConstructFolder:
+ return 0;
+ case ParamObject:
+ return myDocument->feature(PARAMETERS_GROUP, theIndex.row());
+ case ConstructObject:
+ return myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+ }
+ return 0;
+}
+
//******************************************************************
//******************************************************************
//******************************************************************
-XGUI_PartDataModel::XGUI_PartDataModel(QObject* theParent)
- : QAbstractItemModel(theParent)
+XGUI_PartDataModel::XGUI_PartDataModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent)
+ : XGUI_PartModel(theDocument, theParent)
{
}
QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const
{
- int aId = (int)theIndex.internalId();
- switch (aId) {
+ switch (theIndex.internalId()) {
case MyRoot:
return QModelIndex();
case ParamsFolder:
{
std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
return aFeature->data()->docRef("PartDocument")->value();
-}
\ No newline at end of file
+}
+
+FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
+{
+ switch (theIndex.internalId()) {
+ case MyRoot:
+ return myDocument->feature(PARTS_GROUP, myId);
+ case ParamsFolder:
+ case ConstructFolder:
+ return 0;
+ case ParamObject:
+ return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
+ case ConstructObject:
+ return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+ }
+ return 0;
+}
#ifndef XGUI_PartDataModel_H
#define XGUI_PartDataModel_H
-#include <QAbstractItemModel>
-
-class ModelAPI_Feature;
-class ModelAPI_Document;
+#include "XGUI_DataTreeModel.h"
/**\class XGUI_TopDataModel
* \ingroup GUI
* \brief This is a data model for Object Browser (QTreeView).
* It represents only upper part of data tree (non-parts tree items)
*/
-class XGUI_TopDataModel : public QAbstractItemModel
+class XGUI_TopDataModel : public XGUI_FeaturesModel
{
Q_OBJECT
public:
- XGUI_TopDataModel(QObject* theParent);
+ XGUI_TopDataModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent);
virtual ~XGUI_TopDataModel();
-
- //! Set a document object
- virtual void setDocument(const std::shared_ptr<ModelAPI_Document>& theDoc)
- {
- myDocument = theDoc;
- }
// Reimplementation from QAbstractItemModel
virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
+ //! Returns Feature object by the given Model index.
+ //! Returns 0 if the given index is not index of a feature
+ virtual FeaturePtr feature(const QModelIndex& theIndex) const;
+
private:
//! Types of QModelIndexes
enum DataIds {
ConstructObject
};
- //! Document object
- std::shared_ptr<ModelAPI_Document> myDocument;
};
* \brief This is a data model for Object Browser (QTreeView).
* It represents data tree only of a one part
*/
-class XGUI_PartDataModel : public QAbstractItemModel
+class XGUI_PartDataModel : public XGUI_PartModel
{
Q_OBJECT
public:
- XGUI_PartDataModel(QObject* theParent);
+ XGUI_PartDataModel(const std::shared_ptr<ModelAPI_Document>& theDocument, QObject* theParent);
virtual ~XGUI_PartDataModel();
- //! Set a document object and Id of a part in the document
- virtual void setDocument(const std::shared_ptr<ModelAPI_Document>& theDoc, int theId)
- {
- myDocument = theDoc;
- myId = theId;
- }
-
// Reimplementation from QAbstractItemModel
virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
+ //! Returns Feature object by the given Model index.
+ //! Returns 0 if the given index is not index of a feature
+ virtual FeaturePtr feature(const QModelIndex& theIndex) const;
+
private:
std::shared_ptr<ModelAPI_Document> featureDocument() const;
ConstructObject
};
- //! Document object
- std::shared_ptr<ModelAPI_Document> myDocument;
-
- //! Id of the current part object in the document
- int myId;
};
#endif
\ No newline at end of file
--- /dev/null
+#include "XGUI_SelectionMgr.h"
+#include "XGUI_Workshop.h"
+#include "XGUI_MainWindow.h"
+#include "XGUI_ObjectsBrowser.h"
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_Object.h>
+
+
+
+XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) :
+ QObject(theParent), myWorkshop(theParent)
+{
+ XGUI_ObjectsBrowser* aObjBrowser = myWorkshop->mainWindow()->objectBrowser();
+
+ connect(aObjBrowser, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+}
+
+
+XGUI_SelectionMgr::~XGUI_SelectionMgr()
+{
+}
+
+void XGUI_SelectionMgr::onSelectionChanged()
+{
+ XGUI_ObjectsBrowser* aObjBrowser = myWorkshop->mainWindow()->objectBrowser();
+ mySelectedData = aObjBrowser->selectedData();
+
+ // Set current document
+ if (mySelectedData.size() > 0) {
+ FeaturePtr aFeature = mySelectedData.first();
+
+ std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+ aMgr->setCurrentDocument(aFeature->data()->docRef("PartDocument")->value());
+ }
+
+ emit selectionChanged();
+}
\ No newline at end of file
--- /dev/null
+#ifndef XGUI_SelectionMgr_H
+#define XGUI_SelectionMgr_H
+
+#include "XGUI_Constants.h"
+#include <QObject>
+
+class XGUI_Workshop;
+
+class XGUI_SelectionMgr : public QObject
+{
+ Q_OBJECT
+public:
+ XGUI_SelectionMgr(XGUI_Workshop* theParent);
+ virtual ~XGUI_SelectionMgr();
+
+ QFeatureList selectedData() const { return mySelectedData; }
+
+
+signals:
+ void selectionChanged();
+
+public slots:
+ void onSelectionChanged();
+
+private:
+ XGUI_Workshop* myWorkshop;
+
+ QFeatureList mySelectedData;
+};
+
+#endif;
\ No newline at end of file
Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
if (aFmt == "PS")
- a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
+ a3dView->Export(_strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
else if (aFmt == "EPS")
- a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
+ a3dView->Export(_strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
else
aPicture.save( aFileName, aFmt.toLatin1() );
QApplication::restoreOverrideCursor();
#include "XGUI_Workshop.h"
#include "XGUI_Viewer.h"
#include "XGUI_WidgetFactory.h"
+#include "XGUI_SelectionMgr.h"
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Feature.h>
myPartSetModule(NULL)
{
myMainWindow = new XGUI_MainWindow();
+ mySelector = new XGUI_SelectionMgr(this);
}
//******************************************************
class XGUI_Command;
class XGUI_Module;
class XGUI_Workbench;
+class XGUI_SelectionMgr;
class ModuleBase_Operation;
class Config_FeatureMessage;
return myMainWindow;
}
+ //! Returns selection manager object
+ XGUI_SelectionMgr* selector() const { return mySelector; }
+
//! Creates and adds a new workbench (menu group) with the given name and returns it
XGUI_Workbench* addWorkbench(const QString& theName);
XGUI_MainWindow* myMainWindow;
XGUI_Module* myPartSetModule;
+ XGUI_SelectionMgr* mySelector;
+
ModuleBase_Operation* myCurrentOperation;
};