${PROJECT_SOURCE_DIR}/src/PyInterp
${PROJECT_SOURCE_DIR}/src/PyConsole
${PROJECT_SOURCE_DIR}/src/ModelAPI
- ${PROJECT_SOURCE_DIR}/src/Model
+ ${PROJECT_SOURCE_DIR}/src/GeomAPI
+ ${PROJECT_SOURCE_DIR}/src/Model
${PROJECT_SOURCE_DIR}/src/ModuleBase
${PROJECT_SOURCE_DIR}/src/PartSetPlugin
${CAS_INCLUDE_DIRS})
#include <ModelAPI_Document.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <GeomAPI_Shape.h>
#include <AIS_InteractiveContext.hxx>
#include <AIS_LocalContext.hxx>
bool XGUI_Displayer::isVisible(FeaturePtr theFeature)
{
- return myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end();
+ FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
+ return myFeature2AISObjectMap.find(aFeature) != myFeature2AISObjectMap.end();
}
-//void XGUI_Displayer::Display(FeaturePtr theFeature,
-// const bool isUpdateViewer)
-//{
-//}
+void XGUI_Displayer::display(FeaturePtr theFeature, bool isUpdateViewer)
+{
+ FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
+ boost::shared_ptr<GeomAPI_Shape> aShapePtr = aFeature->data()->shape();
+
+ if (aShapePtr) {
+ TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+ display(aFeature, aShape, isUpdateViewer);
+ }
+}
-/*void XGUI_Displayer::Display(FeaturePtr theFeature,
- const TopoDS_Shape& theShape, const bool isUpdateViewer)
+void XGUI_Displayer::display(FeaturePtr theFeature,
+ const TopoDS_Shape& theShape, bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
myFeature2AISObjectMap[theFeature] = anAIS;
- aContext->Display(anAIS, Standard_False);
- if (isUpdateViewer)
- updateViewer();
-}*/
+ aContext->Display(anAIS, isUpdateViewer);
+}
std::list<XGUI_ViewerPrs> XGUI_Displayer::getSelected(const int theShapeTypeToSkip)
return aPresentations;
}
+QFeatureList XGUI_Displayer::selectedFeatures() const
+{
+ QFeatureList aSelectedList;
+
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
+ Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
+ FeaturePtr aFeature = getFeature(anIO);
+ if (aFeature)
+ aSelectedList.append(aFeature);
+ }
+ return aSelectedList;
+}
+
+
std::list<XGUI_ViewerPrs> XGUI_Displayer::getHighlighted(const int theShapeTypeToSkip)
{
std::set<FeaturePtr > aPrsFeatures;
void XGUI_Displayer::erase(FeaturePtr theFeature,
const bool isUpdateViewer)
{
- if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
+ FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
+
+ if (myFeature2AISObjectMap.find(aFeature) == myFeature2AISObjectMap.end())
return;
Handle(AIS_InteractiveContext) aContext = AISContext();
- Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[theFeature];
+ Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[aFeature];
Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
if (!anAISShape.IsNull())
{
- aContext->Erase(anAISShape);
+ aContext->Erase(anAISShape, isUpdateViewer);
}
- myFeature2AISObjectMap.erase(theFeature);
-
- if (isUpdateViewer)
- updateViewer();
+ myFeature2AISObjectMap.erase(aFeature);
}
+
bool XGUI_Displayer::redisplay(FeaturePtr theFeature,
Handle(AIS_InteractiveObject) theAIS,
const int theSelectionMode,
updateViewer();
}
+
+void XGUI_Displayer::setSelected(const QFeatureList& theFeatures, const bool isUpdateViewer)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ aContext->ClearSelected();
+ foreach(FeaturePtr aFeature, theFeatures) {
+ FeaturePtr aRFeature = XGUI_Tools::realFeature(aFeature);
+ if (myFeature2AISObjectMap.find(aRFeature) == myFeature2AISObjectMap.end())
+ return;
+
+ Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[aRFeature];
+ if (!anAIS.IsNull())
+ aContext->AddOrRemoveSelected(anAIS, false);
+ }
+ if (isUpdateViewer)
+ updateViewer();
+}
+
+
/*void XGUI_Displayer::EraseAll(const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) ic = AISContext();
#define XGUI_Displayer_H
#include "XGUI.h"
+#include "XGUI_Constants.h"
#include <QString>
#include <boost/shared_ptr.hpp>
/// Display the feature. Obtain the visualized object from the feature.
/// \param theFeature a feature instance
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- //void Display(FeaturePtr theFeature, const bool isUpdateViewer = true);
+ void display(FeaturePtr theFeature, bool isUpdateViewer = true);
/// Display the feature and a shape. This shape would be associated to the given feature
/// \param theFeature a feature instance
/// \param theShape a shape
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- //void Display(FeaturePtr theFeature, const TopoDS_Shape& theShape,
- // const bool isUpdateViewer = true);
+ void display(FeaturePtr theFeature, const TopoDS_Shape& theShape, bool isUpdateViewer = true);
/// Returns a list of viewer selected presentations
/// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
/// \return list of presentations
std::list<XGUI_ViewerPrs> getSelected(const int theShapeTypeToSkip = -1);
+ /**
+ * Returns list of features currently selected in 3d viewer
+ */
+ QFeatureList selectedFeatures() const;
+
/// Returns a list of viewer highlited presentations
/// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
/// \return list of presentations
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
void setSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer);
+ /**
+ * Add presentations which corresponds to the given features to current selection
+ * \param theFeatures a list of features to be selected
+ * isUpdateViewer the parameter whether the viewer should be update immediatelly
+ */
+ void setSelected(const QFeatureList& theFeatures, bool isUpdateViewer = true);
+
/// Erase the feature and a shape.
/// \param theFeature a feature instance
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const
{
- FeaturePtr aFeature = theFeature;
- if (XGUI_Tools::isModelObject(aFeature)) {
- ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
- aFeature = aObject->featureRef();
- }
+ FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
+
int aRow = -1;
XGUI_PartModel* aModel = 0;
foreach (XGUI_PartModel* aPartModel, myPartModels) {
}
return QModelIndex();
}
+
+QModelIndex XGUI_DocumentDataModel::featureIndex(const FeaturePtr theFeature) const
+{
+ // Check that this feature belongs to root document
+ DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ DocumentPtr aDoc = theFeature->document();
+ if (aDoc == aRootDoc) {
+ // This feature belongs to histrory or top model
+ if (theFeature->isInHistory()) {
+ int aId;
+ for (aId = 0; aId < aRootDoc->size(FEATURES_GROUP); aId++) {
+ if (theFeature == aRootDoc->feature(FEATURES_GROUP, aId))
+ break;
+ }
+ return index(aId + historyOffset(), 0, QModelIndex());
+ } else {
+ QModelIndex aIndex = myModel->featureIndex(theFeature);
+ return aIndex.isValid()?
+ createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) :
+ QModelIndex();
+ }
+ } else {
+ XGUI_PartModel* aPartModel = 0;
+ foreach(XGUI_PartModel* aModel, myPartModels) {
+ if (aModel->hasDocument(aDoc)) {
+ aPartModel = aModel;
+ break;
+ }
+ }
+ if (aPartModel) {
+ QModelIndex aIndex = aPartModel->featureIndex(theFeature);
+ return aIndex.isValid()?
+ createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) :
+ QModelIndex();
+ }
+ }
+}
\ No newline at end of file
//! Returns 0 if the given index is not index of a feature
FeaturePtr feature(const QModelIndex& theIndex) const;
+ QModelIndex featureIndex(const FeaturePtr theFeature) 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;
//! Returns true if active part changed.
bool activatedIndex(const QModelIndex& theIndex);
+ //! Retrurns Feature which corresponds to active part
FeaturePtr activePart() const;
+ //! Retrurns QModelIndex of active part
QModelIndex activePartIndex() const { return myActivePartIndex; }
//! Deactivates a Part
{
myDocModel->rebuildDataTree();
update();
-}
\ No newline at end of file
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::setFeaturesSelected(const QFeatureList& theFeatures)
+{
+ QList<QModelIndex> theIndexes;
+ QItemSelectionModel* aSelectModel = myTreeView->selectionModel();
+ aSelectModel->clear();
+
+ foreach(FeaturePtr aFeature, theFeatures) {
+ QModelIndex aIndex = myDocModel->featureIndex(aFeature);
+ if (aIndex.isValid()) {
+ aSelectModel->select(aIndex, QItemSelectionModel::Select);
+ }
+ }
+}
//! Returns list of currently selected features
QFeatureList selectedFeatures() const { return myFeaturesList; }
+ void setFeaturesSelected(const QFeatureList& theFeatures);
+
//! Returns currently selected indexes
QModelIndexList selectedIndexes() const { return myTreeView->selectionModel()->selectedIndexes(); }
return aIndex;
std::string aGroup = theFeature->getGroup();
- DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- int aNb = aRootDoc->size(aGroup);
+ DocumentPtr aDoc = theFeature->document();
+ int aNb = aDoc->size(aGroup);
int aRow = -1;
for (int i = 0; i < aNb; i++) {
- if (aRootDoc->feature(aGroup, i) == theFeature) {
+ if (aDoc->feature(aGroup, i) == theFeature) {
aRow = i;
break;
}
virtual FeaturePtr part() const;
private:
+
+ //! Returns document of the current part
DocumentPtr featureDocument() const;
//! Types of QModelIndexes
void keyRelease(QKeyEvent* theEvent);
void activated();
+ void selectionChanged();
};
#endif
\ No newline at end of file
#include "XGUI_SelectionMgr.h"
+
#include "XGUI_Workshop.h"
#include "XGUI_MainWindow.h"
#include "XGUI_ObjectsBrowser.h"
-#include "XGUI_Viewer.h"
#include "XGUI_SalomeConnector.h"
#include "XGUI_ViewerProxy.h"
+#include "XGUI_Displayer.h"
#include <ModelAPI_Feature.h>
#include <ModelAPI_PluginManager.h>
this, SLOT(onObjectBrowserSelection()));
//Connect to other viewers
- if (myWorkshop->isSalomeMode()) {
- connect(myWorkshop, SIGNAL(salomeViewerSelection()),
- this, SLOT(onViewerSelection()));
- } else {
- connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
- this, SLOT(onViewerSelection()));
- }
+ connect(myWorkshop->viewer(), SIGNAL(selectionChanged()),
+ this, SLOT(onViewerSelection()));
}
//**************************************************************
void XGUI_SelectionMgr::onObjectBrowserSelection()
{
-
- // TODO: Highliht selected objects in Viewer 3d
+ QFeatureList aFeatures = selectedFeatures();
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ aDisplayer->setSelected(aFeatures);
emit selectionChanged();
}
//**************************************************************
void XGUI_SelectionMgr::onViewerSelection()
{
- // TODO: Highliht selected objects in Object Browser
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ QFeatureList aFeatures = aDisplayer->selectedFeatures();
+ myWorkshop->objectBrowser()->setFeaturesSelected(aFeatures);
emit selectionChanged();
}
#include "XGUI_Tools.h"
#include <TopoDS_Shape.hxx>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
#include <QDir>
return QString(aStream.str().c_str()).toStdString();
}
-}
\ No newline at end of file
+//******************************************************************
+FeaturePtr realFeature(const FeaturePtr theFeature)
+{
+ if (theFeature->data()) {
+ return theFeature;
+ } else {
+ ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
+ return aObject->featureRef();
+ }
+}
+
+}
\param theFeature a feature
*/
std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature);
+
+ /**
+ * Returns pointer on real feature
+ */
+ FeaturePtr realFeature(const FeaturePtr theFeature);
}
#endif
connect(aViewer, SIGNAL(keyRelease(QKeyEvent*)),
this, SIGNAL(keyRelease(QKeyEvent*)));
+
+ connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
} else {
XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
this, SLOT(onKeyPress(XGUI_ViewWindow*, QKeyEvent*)));
connect(aViewer, SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)),
this, SLOT(onKeyRelease(XGUI_ViewWindow*, QKeyEvent*)));
+
+ connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
}
}
//**************************************************************
void XGUI_Workshop::showFeatures(QFeatureList theList, bool isVisible)
{
-// foreach (FeaturePtr aFeature, theList) {
-// }
+ if (isVisible) {
+ foreach (FeaturePtr aFeature, theList) {
+ myDisplayer->display(aFeature, false);
+ }
+ } else {
+ foreach (FeaturePtr aFeature, theList) {
+ myDisplayer->erase(aFeature, false);
+ }
+ }
+ myDisplayer->updateViewer();
}