#include <Config_PropManager.h>
+#include <TopAbs_ShapeEnum.hxx>
+
#include <SUIT_ResourceMgr.h>
#include <SUIT_PreferenceMgr.h>
#include <Qtx.h>
myPreferences->setItemProperty("texture_stretch_enabled", true, bgId);
myPreferences->setItemProperty("custom_enabled", false, bgId);
myPreferences->setItemProperty("image_formats", aImgFiles, bgId);
+
+ // Create other parameters group in viewer tab
+ int otherGroup = myPreferences->addItem(tr("Other parameters"), viewTab);
+ int selId = myPreferences->addItem(tr("Default selection type"), otherGroup,
+ SUIT_PreferenceMgr::Selector,
+ ModuleBase_Preferences::VIEWER_SECTION, "selection");
+ QStringList aSelectionList;
+ aSelectionList.append( tr("Vertices") );
+ aSelectionList.append( tr("Edges") );
+ aSelectionList.append( tr("Faces") );
+ aSelectionList.append( tr("Results") );
+
+ QList<QVariant> anIndexesList;
+ anIndexesList.append(TopAbs_VERTEX);
+ anIndexesList.append(TopAbs_EDGE);
+ anIndexesList.append(TopAbs_FACE);
+ anIndexesList.append(-1);
+
+ myPreferences->setItemProperty( "strings", aSelectionList, selId );
+ myPreferences->setItemProperty( "indexes", anIndexesList, selId );
}
void ModuleBase_PreferencesDlg::createMenuPage(int thePageId)
myStackWidget->setCurrentIndex(0);
bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
+
+ // Clear previous selection mode It is necessary for correct activation of preview planes
+ aDisp->activateObjects(QIntList(), aDisplayed, false);
+
if (!aBodyIsVisualized) {
// We have to select a plane before any operation
myPreviewPlanes->showPreviewPlanes(myWorkshop);
<section name="Viewer" >
<!-- Viewer preferences -->
<parameter name="background" value="bt=2;fn=;tm=0;ts=false;c1=#cddbff;c2=#698fff;gt=1;gr=" />
+ <parameter name="selection" value="4" />
</section>
<section name="Menu" >
<!-- Menu bar preferences -->
#include <ModuleBase_OperationAction.h>
#include <QAction>
+#include <QActionGroup>
#include <QContextMenuEvent>
#include <QMenu>
#include <QMdiArea>
mySeparator = new QAction(this);
mySeparator->setSeparator(true);
+ mySelectActions = new QActionGroup(this);
+ mySelectActions->setExclusive(true);
+
+ aAction = new QAction(QIcon(":pictures/vertex.png"), tr("Vertices"), this);
+ aAction->setCheckable(true);
+ addAction("SELECT_VERTEX_CMD", aAction);
+ mySelectActions->addAction(aAction);
+
+ aAction = new QAction(QIcon(":pictures/edge.png"), tr("Edges"), this);
+ aAction->setCheckable(true);
+ addAction("SELECT_EDGE_CMD", aAction);
+ mySelectActions->addAction(aAction);
+
+ aAction = new QAction(QIcon(":pictures/face.png"), tr("Faces"), this);
+ aAction->setCheckable(true);
+ addAction("SELECT_FACE_CMD", aAction);
+ mySelectActions->addAction(aAction);
+
+ aAction = new QAction(QIcon(":pictures/result.png"), tr("Result"), this);
+ aAction->setCheckable(true);
+ addAction("SELECT_RESULT_CMD", aAction);
+ mySelectActions->addAction(aAction);
+
+ aAction->setChecked(true);
buildObjBrowserMenu();
buildViewerMenu();
aAction->setEnabled(false);
XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
QList<ModuleBase_ViewerPrs> aPrsList = aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
if (aPrsList.size() > 0) {
bool isVisible = false;
}
if (isVisible) {
if (canBeShaded) {
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject);
if (aMode != XGUI_Displayer::NoMode) {
action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading);
action("DELETE_CMD")->setEnabled(true);
+ // Update selection menu
+ QIntList aModes = aDisplayer->activeSelectionModes();
+ if (aModes.count() <= 1) {
+ action("SELECT_VERTEX_CMD")->setEnabled(true);
+ action("SELECT_EDGE_CMD")->setEnabled(true);
+ action("SELECT_FACE_CMD")->setEnabled(true);
+ action("SELECT_RESULT_CMD")->setEnabled(true);
+ if (aModes.count() == 1) {
+ switch (aModes.first()) {
+ case TopAbs_VERTEX:
+ action("SELECT_VERTEX_CMD")->setChecked(true);
+ break;
+ case TopAbs_EDGE:
+ action("SELECT_EDGE_CMD")->setChecked(true);
+ break;
+ case TopAbs_FACE:
+ action("SELECT_FACE_CMD")->setChecked(true);
+ break;
+ default:
+ action("SELECT_RESULT_CMD")->setChecked(true);
+ }
+ } else
+ action("SELECT_RESULT_CMD")->setChecked(true);
+ }
ModuleBase_IModule* aModule = myWorkshop->module();
if (aModule)
aModule->updateViewerMenu(myActions);
QList<ModuleBase_ViewerPrs> aPrsList = aSelMgr->selection()->getSelected(ModuleBase_ISelection::Viewer);
int aSelected = aPrsList.size();
QActionsList aActions;
+
+ // Create selection menu
+ XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
+ QIntList aModes;
+ myWorkshop->module()->activeSelectionModes(aModes);
+ if ((!aOpMgr->hasOperation()) && aModes.isEmpty()) {
+ QMenu* aSelMenu = new QMenu(tr("Selection mode"), theMenu);
+ aSelMenu->addAction(action("SELECT_VERTEX_CMD"));
+ aSelMenu->addAction(action("SELECT_EDGE_CMD"));
+ aSelMenu->addAction(action("SELECT_FACE_CMD"));
+ aSelMenu->addAction(action("SELECT_RESULT_CMD"));
+ theMenu->addMenu(aSelMenu);
+ theMenu->addSeparator();
+ }
if (aSelected == 1) {
ObjectPtr aObject = aPrsList.first().object();
if (aObject.get() != NULL) {
class QAction;
class QContextMenuEvent;
class QMenu;
+class QActionGroup;
/**
* \ingroup GUI
QMap<std::string, QActionsList> myObjBrowserMenus;
QMap<std::string, QActionsList> myViewerMenu;
- QAction* mySeparator;
+ QActionGroup* mySelectActions;
+
+ QAction* mySeparator;
};
#endif
updateViewer();
}
+
+QIntList XGUI_Displayer::activeSelectionModes() const
+{
+ QIntList aModes;
+ foreach (int aMode, myActiveSelectionModes) {
+ // aMode < 9 is a Shape Enum values
+ aModes << ((aMode < 9)? AIS_Shape::SelectionType(aMode) : aMode);
+ }
+ return aModes;
+}
/// Returns true if the trihedron should be activated in current selection modes
bool isTrihedronActive() const { return myIsTrihedronActive; }
+ /// Returns list of currently active selection modes
+ /// Selection modes will be returned according to TopAbs_ShapeEnum
+ QIntList activeSelectionModes() const;
+
+
/// Converts shape type (TopAbs_ShapeEnum) to selection mode
/// \param theShapeType a shape type from TopAbs_ShapeEnum
static int getSelectionMode(int theShapeType);
void XGUI_ModuleConnector::activateModuleSelectionModes()
{
XGUI_Displayer* aDisp = myWorkshop->displayer();
- QIntList aModes;
- module()->activeSelectionModes(aModes);
- aDisp->activateObjects(aModes, activeObjects(aDisp->displayedObjects()));
+ myWorkshop->activateObjectsSelection(activeObjects(aDisp->displayedObjects()));
}
AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
QList<ModuleBase_ViewerPrs> aSelectedPrs =
myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
+ QList<ModuleBase_ViewerPrs> aTmpList = aSelectedPrs;
+ ObjectPtr aObject;
+ FeaturePtr aFeature;
+ foreach(ModuleBase_ViewerPrs aPrs, aTmpList) {
+ aObject = aPrs.object();
+ if (aObject.get()) {
+ aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
+ if (aFeature.get()) {
+ const std::list<std::shared_ptr<ModelAPI_Result>> aResList = aFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
+ aSelectedPrs.append(ModuleBase_ViewerPrs((*aIt), TopoDS_Shape(), NULL));
+ }
+ }
+ }
+ }
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
aDisplayer->setSelected(aSelectedPrs);
emit selectionChanged();
aFeatures.append(aPrs.object());
}
}
+ // Add features by selected results
+ QObjectPtrList aTmpList = aFeatures;
+ ResultPtr aResult;
+ FeaturePtr aFeature;
+ foreach(ObjectPtr aObj, aTmpList) {
+ aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ if (aResult.get()) {
+ aFeature = ModelAPI_Feature::feature(aResult);
+ if (aFeature.get() && (!aFeatures.contains(aFeature)))
+ aFeatures.append(aFeature);
+ }
+ }
bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
myWorkshop->objectBrowser()->blockSignals(aBlocked);
mySalomeConnector(theConnector),
myPropertyPanel(0),
myObjectBrowser(0),
- myDisplayer(0)
+ myDisplayer(0),
+ myViewerSelMode(TopAbs_FACE)
{
#ifndef HAVE_SALOME
myMainWindow = new AppElements_MainWindow();
Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
+
+ myViewerSelMode =
+ ModuleBase_Preferences::resourceMgr()->integerValue("Viewer", "selection", TopAbs_FACE);
}
//******************************************************
updateCommandStatus();
+ // TODO: get default selection mode
+
// activate visualized objects in the viewer
- XGUI_Displayer* aDisplayer = displayer();
- QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
- QIntList aModes;
- module()->activeSelectionModes(aModes);
- aDisplayer->activateObjects(aModes, aDisplayed);
+ activateObjectsSelection(displayer()->displayedObjects());
myOperationMgr->activate();
}
}
}
}
- QIntList aModes;
- module()->activeSelectionModes(aModes);
- myDisplayer->activateObjects(aModes, anObjects);
+ activateObjectsSelection(anObjects);
}
aObj->setDisplayed(false);
}
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ } else if (theId == "SELECT_VERTEX_CMD") {
+ setViewerSelectionMode(TopAbs_VERTEX);
+ } else if (theId == "SELECT_EDGE_CMD") {
+ setViewerSelectionMode(TopAbs_EDGE);
+ } else if (theId == "SELECT_FACE_CMD") {
+ setViewerSelectionMode(TopAbs_FACE);
+ } else if (theId == "SELECT_RESULT_CMD") {
+ setViewerSelectionMode(-1);
}
}
+//**************************************************************
+void XGUI_Workshop::setViewerSelectionMode(int theMode)
+{
+ myViewerSelMode = theMode;
+ activateObjectsSelection(myDisplayer->displayedObjects());
+}
+
+//**************************************************************
+void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
+{
+ QIntList aModes;
+ module()->activeSelectionModes(aModes);
+ if (aModes.isEmpty() && (myViewerSelMode != -1))
+ aModes.append(myViewerSelMode);
+ myDisplayer->activateObjects(aModes, theList);
+}
+
+
//**************************************************************
void XGUI_Workshop::deleteObjects()
{
/// \param theMode a mode to set (see \ref XGUI_Displayer)
void setDisplayMode(const QObjectPtrList& theList, int theMode);
+ /// Set selection mode in viewer. If theMode=-1 then activate default mode
+ /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
+ void setViewerSelectionMode(int theMode);
+
+ /// Activates current selection mode for the given list of objects
+ void activateObjectsSelection(const QObjectPtrList& theList);
+
/// Returns current module
ModuleBase_IModule* module() const
{
/// Activates/deactivates the trihedron in the viewer AIS context
void onTrihedronVisibilityChanged(bool theState);
+ /// Returns defailt selection mode in 3d viewer
+ int viewerSelectionMode() const { return myViewerSelMode; }
+
+
protected:
/// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
/// and set them into the operation. Secondly, it asks the module about ids of granted operations.
XGUI_WorkshopListener* myEventsListener;
QString myCurrentDir;
+
+ int myViewerSelMode;
};
#endif
<file>pictures/compound.png</file>
<file>pictures/shell.png</file>
<file>pictures/wire.png</file>
+ <file>pictures/result.png</file>
</qresource>
</RCC>