ADD_SUBDIRECTORY (src/SketchSolver)
ADD_SUBDIRECTORY (src/ModuleBase)
ADD_SUBDIRECTORY (src/PartSet)
+ADD_SUBDIRECTORY (src/AppElements)
ADD_SUBDIRECTORY (src/XGUI)
ADD_SUBDIRECTORY (src/GeomApp)
ADD_SUBDIRECTORY (src/ExchangePlugin)
ModuleBase_ResultPrs.h
ModuleBase_IViewWindow.h
ModuleBase_WidgetLabel.h
+ ModuleBase_IPrefMgr.h
+ ModuleBase_Preferences.h
)
SET(PROJECT_SOURCES
ModuleBase_ViewerFilters.cpp
ModuleBase_ResultPrs.cpp
ModuleBase_WidgetLabel.cpp
+ ModuleBase_Preferences.cpp
)
SET(PROJECT_LIBRARIES
${CAS_VIEWER}
${CAS_KERNEL}
${CAS_SHAPE}
+ ${suit}
+ ${qtx}
)
SET(PROJECT_AUTOMOC
${CMAKE_SOURCE_DIR}/src/GeomDataAPI
${CMAKE_SOURCE_DIR}/src/GeomAPI
${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
+ ${SUIT_INCLUDE}
)
ADD_DEFINITIONS(-DMODULEBASE_EXPORTS ${CAS_DEFINITIONS})
--- /dev/null
+// File: ModuleBase_IPrefMgr.h
+// Created: 10 Sept 2014
+// Author: Vitaly SMETANNIKOV
+
+
+#ifndef ModuleBase_IPrefMgr_H
+#define ModuleBase_IPrefMgr_H
+
+#include <QString>
+#include <SUIT_PreferenceMgr.h>
+
+/**
+* An interface class which provides incapsulation of SUIT_PreferenceMgr class instance
+* It is used in order to make common interface to Preference manager in Salome
+* and this application
+*/
+class ModuleBase_IPrefMgr
+{
+public:
+
+ /**
+ * Add preference item into preference dialog box
+ * \param theLbl - label of the item
+ * \param pId - id of container item
+ * \param theType - type of the item
+ * \param theSection - resouce section name
+ * \param theName - name of the resource
+ * Returns Id of the ctreated item
+ */
+ virtual int addPreference(const QString& theLbl, int pId,
+ SUIT_PreferenceMgr::PrefItemType theType,
+ const QString& theSection, const QString& theName ) = 0;
+
+ virtual void setItemProperty(const QString& thePropName,
+ const QVariant& theValue,
+ const int theId = -1) = 0;
+
+ /// Returns incapsulated preference manager
+ virtual SUIT_PreferenceMgr* prefMgr() const = 0;
+};
+
+#endif
--- /dev/null
+// File: ModuleBase_Preferences.cpp
+// Created: 07 Aug 2014
+// Author: Vitaly SMETANNIKOV
+
+#include "ModuleBase_Preferences.h"
+//#include "ModuleBase_Constants.h"
+
+#include <Config_PropManager.h>
+
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_PreferenceMgr.h>
+#include <Qtx.h>
+
+#include <QLayout>
+#include <QApplication>
+#include <QDialogButtonBox>
+#include <QPushButton>
+
+const QString ModuleBase_Preferences::VIEWER_SECTION = "Viewer";
+const QString ModuleBase_Preferences::MENU_SECTION = "Menu";
+
+SUIT_ResourceMgr* ModuleBase_Preferences::myResourceMgr = 0;
+
+SUIT_ResourceMgr* ModuleBase_Preferences::resourceMgr()
+{
+ if (!myResourceMgr) {
+ myResourceMgr = new SUIT_ResourceMgr("NewGeom");
+ myResourceMgr->setCurrentFormat("xml");
+ }
+ return myResourceMgr;
+}
+
+bool ModuleBase_Preferences::editPreferences(ModuleBase_Prefs& theModified)
+{
+ ModuleBase_PreferencesDlg aDlg(resourceMgr(), QApplication::activeWindow());
+ aDlg.exec();
+ if (aDlg.isChanged()) {
+ aDlg.modified(theModified);
+ resourceMgr()->save();
+ return true;
+ }
+ return false;
+}
+
+void ModuleBase_Preferences::updateConfigByResources()
+{
+ Config_Properties aProps = Config_PropManager::getProperties();
+ Config_Properties::iterator aIt;
+ for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
+ Config_Prop* aProp = (*aIt);
+ QString aVal = myResourceMgr->stringValue(QString(aProp->section().c_str()),
+ QString(aProp->name().c_str()));
+ if (!aVal.isEmpty()) {
+ aProp->setValue(aVal.toStdString());
+ }
+ }
+}
+
+void ModuleBase_Preferences::updateResourcesByConfig()
+{
+ Config_Properties aProps = Config_PropManager::getProperties();
+ Config_Properties::iterator aIt;
+ for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
+ Config_Prop* aProp = (*aIt);
+ myResourceMgr->setValue(QString(aProp->section().c_str()), QString(aProp->name().c_str()),
+ QString(aProp->value().c_str()));
+ }
+}
+
+void ModuleBase_Preferences::resetConfig()
+{
+ Config_Properties aProps = Config_PropManager::getProperties();
+ Config_Properties::iterator aIt;
+ for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
+ Config_Prop* aProp = (*aIt);
+ aProp->setValue(aProp->defaultValue());
+ }
+}
+
+void ModuleBase_Preferences::loadCustomProps()
+{
+ if(!myResourceMgr)
+ return;
+ QStringList aSections = myResourceMgr->sections();
+ foreach (QString aSection, aSections)
+ {
+ QStringList aParams = myResourceMgr->parameters(aSection);
+ foreach (QString aParam, aParams)
+ {
+ Config_Prop* aProp = Config_PropManager::registerProp(aSection.toStdString(),
+ aParam.toStdString(), "", Config_Prop::Disabled);
+ aProp->setValue(myResourceMgr->stringValue(aSection, aParam).toStdString());
+ }
+ }
+}
+
+
+void ModuleBase_Preferences::createEditContent(ModuleBase_IPrefMgr* thePref, int thePage)
+{
+ thePref->prefMgr()->setItemIcon(thePage, QIcon(":pictures/module.png"));
+ createCustomPage(thePref, thePage);
+}
+
+
+void ModuleBase_Preferences::createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId)
+{
+ SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
+ bool isResModified = false;
+
+ // Make a Tab from each section
+ std::list<std::string> aSections = Config_PropManager::getSections();
+ std::list<std::string>::const_iterator it;
+ for (it = aSections.cbegin(); it != aSections.cend(); ++it) {
+ Config_Properties aProps = Config_PropManager::getProperties(*it);
+ int aTab = thePref->prefMgr()->addItem(QString((*it).c_str()), thePageId);
+ thePref->prefMgr()->setItemProperty("columns", 2, aTab);
+
+ Config_Properties::const_iterator aIt;
+ for (aIt = aProps.cbegin(); aIt != aProps.cend(); ++aIt) {
+ Config_Prop* aProp = (*aIt);
+ // check that the property is defined
+ QString aSection(aProp->section().c_str());
+ QString aName(aProp->name().c_str());
+ if (!aResMgr->hasValue(aSection, aName)) {
+ aResMgr->setValue(aSection, aName, QString(aProp->value().c_str()));
+ isResModified = true;
+ }
+ // Add item
+ if (aProp->type() != Config_Prop::Disabled) {
+ SUIT_PreferenceMgr::PrefItemType aPrefType = SUIT_PreferenceMgr::Auto;
+ if (aProp->type() == Config_Prop::Directory) {
+ aPrefType = SUIT_PreferenceMgr::File;
+ } else {
+ aPrefType = (SUIT_PreferenceMgr::PrefItemType) aProp->type();
+ }
+ int anId = thePref->addPreference(QObject::tr(aProp->title().c_str()), aTab, aPrefType,
+ QString::fromStdString(aProp->section()),
+ QString::fromStdString(aProp->name()));
+ if(aProp->type() == Config_Prop::Directory) {
+ thePref->setItemProperty("path_type", Qtx::PT_Directory, anId);
+ }
+ }
+ }
+ }
+}
+
+//**********************************************************
+//**********************************************************
+//**********************************************************
+class ModuleBase_PrefMgr: public ModuleBase_IPrefMgr
+{
+public:
+ ModuleBase_PrefMgr(ModuleBase_PreferencesMgr* theMgr):myMgr(theMgr) {}
+
+ virtual int addPreference(const QString& theLbl, int pId,
+ SUIT_PreferenceMgr::PrefItemType theType,
+ const QString& theSection, const QString& theName )
+ {
+ return myMgr->addItem(theLbl, pId, theType, theSection, theName);
+ }
+
+ virtual void setItemProperty( const QString& thePropName, const QVariant& theValue,
+ const int theId = -1) {
+ myMgr->setItemProperty(thePropName, theValue, theId);
+ }
+
+ virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
+
+private:
+ ModuleBase_PreferencesMgr* myMgr;
+};
+
+//**********************************************************
+//**********************************************************
+//**********************************************************
+ModuleBase_PreferencesDlg::ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent)
+ : QDialog(theParent),
+ myIsChanged(false)
+{
+ setWindowTitle(tr("Edit preferences"));
+
+ QVBoxLayout* main = new QVBoxLayout(this);
+ main->setMargin(5);
+ main->setSpacing(5);
+
+ myPreferences = new ModuleBase_PreferencesMgr(theResurces, this);
+ main->addWidget(myPreferences);
+
+ setFocusProxy(myPreferences);
+ myPreferences->setFrameStyle(QFrame::Box | QFrame::Sunken);
+
+ QDialogButtonBox* aBtnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
+ QDialogButtonBox::Reset,
+ Qt::Horizontal, this);
+ QPushButton* aDefaultButton = aBtnBox->button(QDialogButtonBox::Reset);
+ aDefaultButton->setText(tr("Default"));
+ connect(aDefaultButton, SIGNAL(clicked()), this, SLOT(onDefault()));
+
+ main->addWidget(aBtnBox);
+ connect(aBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(aBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
+ createEditors();
+
+ myPreferences->retrieve();
+ setMinimumSize(800, 200);
+}
+
+ModuleBase_PreferencesDlg::~ModuleBase_PreferencesDlg()
+{
+}
+
+void ModuleBase_PreferencesDlg::createEditors()
+{
+ int aPage = myPreferences->addItem(tr("Desktop"));
+ myPreferences->setItemIcon(aPage, QIcon(":pictures/view_prefs.png"));
+
+ createMenuPage(aPage);
+ createViewerPage(aPage);
+
+ aPage = myPreferences->addItem(tr("Module"));
+ myPreferences->setItemIcon(aPage, QIcon(":pictures/module.png"));
+
+ ModuleBase_PrefMgr aMgr(myPreferences);
+ ModuleBase_Preferences::createEditContent(&aMgr, aPage);
+}
+
+void ModuleBase_PreferencesDlg::createViewerPage(int thePageId)
+{
+ int viewTab = myPreferences->addItem(tr("Viewer"), thePageId);
+
+ QStringList gradList;
+ gradList << tr("Horizontal gradient") << tr("Vertical gradient") << tr("First diagonal gradient")
+ << tr("Second diagonal gradient") << tr("First corner gradient")
+ << tr("Second corner gradient") << tr("Third corner gradient")
+ << tr("Fourth corner gradient");
+
+ QList<QVariant> idList;
+ for (int i = 0; i < gradList.size(); i++)
+ idList << i;
+
+ int bgGroup = myPreferences->addItem(tr("Background"), viewTab);
+
+ QString aImgFiles("Image files (*.bmp *.gif *.pix *.xwd *.rgb *.rs)");
+
+ int bgId = myPreferences->addItem(tr("Viewer 3d"), bgGroup, SUIT_PreferenceMgr::Background,
+ ModuleBase_Preferences::VIEWER_SECTION, "background");
+ myPreferences->setItemProperty("gradient_names", gradList, bgId);
+ myPreferences->setItemProperty("gradient_ids", idList, bgId);
+ myPreferences->setItemProperty("texture_enabled", true, bgId);
+ myPreferences->setItemProperty("texture_center_enabled", true, bgId);
+ myPreferences->setItemProperty("texture_tile_enabled", true, bgId);
+ myPreferences->setItemProperty("texture_stretch_enabled", true, bgId);
+ myPreferences->setItemProperty("custom_enabled", false, bgId);
+ myPreferences->setItemProperty("image_formats", aImgFiles, bgId);
+}
+
+void ModuleBase_PreferencesDlg::createMenuPage(int thePageId)
+{
+ int aMenuTab = myPreferences->addItem(tr("Main menu"), thePageId);
+
+ int aSizeGroup = myPreferences->addItem(tr("Size"), aMenuTab);
+ myPreferences->setItemProperty("columns", 1, aSizeGroup);
+
+ int aRowsNb = myPreferences->addItem(tr("Number of rows"), aSizeGroup,
+ SUIT_PreferenceMgr::IntSpin, ModuleBase_Preferences::MENU_SECTION,
+ "rows_number");
+ myPreferences->setItemProperty("min", 1, aRowsNb);
+ myPreferences->setItemProperty("max", 6, aRowsNb);
+}
+
+void ModuleBase_PreferencesDlg::accept()
+{
+ myPreferences->store();
+ myIsChanged = true;
+
+ // Save custom properties
+ ModuleBase_Preferences::updateConfigByResources();
+ QDialog::accept();
+}
+
+void ModuleBase_PreferencesDlg::modified(ModuleBase_Prefs& theModified) const
+{
+ theModified = myPreferences->modified();
+}
+
+void ModuleBase_PreferencesDlg::onDefault()
+{
+ // reset main resources
+#ifdef SALOME_750 // until SALOME 7.5.0 is released
+ QtxResourceMgr::WorkingMode aPrev =
+ myPreferences->resourceMgr()->setWorkingMode(QtxResourceMgr::IgnoreUserValues);
+ myPreferences->retrieve();
+ myPreferences->resourceMgr()->setWorkingMode(aPrev);
+#endif
+ // reset plugin's resources
+ ModuleBase_Preferences::resetConfig();
+ ModuleBase_Preferences::updateResourcesByConfig();
+
+ myPreferences->retrieve();
+}
+
+//**********************************************************
+//**********************************************************
+//**********************************************************
+void ModuleBase_PreferencesMgr::changedResources(const ResourceMap& theMap)
+{
+ myModified.clear();
+ ResourceMap::ConstIterator it;
+ QString sec, param;
+ for (it = theMap.begin(); it != theMap.end(); ++it) {
+ ModuleBase_Pref aPref;
+ it.key()->resource(aPref.first, aPref.second);
+ myModified.append(aPref);
+ }
+}
--- /dev/null
+// File: ModuleBase_Preferences.h
+// Created: 07 Aug 2014
+// Author: Vitaly SMETANNIKOV
+
+#ifndef ModuleBase_Preferences_H
+#define ModuleBase_Preferences_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_IPrefMgr.h"
+
+#include <SUIT_PreferenceMgr.h>
+#include <QDialog>
+
+class SUIT_ResourceMgr;
+class QWidget;
+
+// Pair of values: section name, value name
+typedef QPair<QString, QString> ModuleBase_Pref;
+typedef QList<ModuleBase_Pref> ModuleBase_Prefs;
+
+//***********************************************************************
+/// Class for manipulation with preferences in the application
+class MODULEBASE_EXPORT ModuleBase_Preferences
+{
+ public:
+ static const QString VIEWER_SECTION;
+ static const QString MENU_SECTION;
+
+ static bool editPreferences(ModuleBase_Prefs& theModified);
+
+ /// Returns currently installed resource manager
+ static SUIT_ResourceMgr* resourceMgr();
+
+ /// Sets a resource manager
+ /// It is used in case of necessity to define external resource manager (not NewGeom)
+ static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
+
+ /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
+ static void updateConfigByResources();
+
+ /// Updates SUIT_ResourceMgr values by Config_PropManager properties
+ /// \param theUpdateOnlyInvalid flag to update only invalid values, if it is false, all are updated
+ static void updateResourcesByConfig();
+
+ /// Set default values to the Config_PropManager properties
+ static void resetConfig();
+
+ /// Loads properties defined by module to Config_PropManager
+ static void loadCustomProps();
+
+ ///
+ static void createEditContent(ModuleBase_IPrefMgr* thePref, int thePage);
+
+private:
+ /// Creates content of preferences editing widget
+ static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
+
+ static SUIT_ResourceMgr* myResourceMgr;
+};
+
+//***********************************************************************
+/// Manager of preferences
+class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
+{
+Q_OBJECT
+ public:
+ ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
+ : SUIT_PreferenceMgr(theResource, theParent)
+ {
+ }
+
+ virtual ~ModuleBase_PreferencesMgr()
+ {
+ }
+
+ ModuleBase_Prefs modified() const
+ {
+ return myModified;
+ }
+
+ protected:
+ virtual void changedResources(const ResourceMap& theMap);
+
+ private:
+ ModuleBase_Prefs myModified;
+};
+
+//***********************************************************************
+/// Dialog box for preferences editing
+class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
+{
+Q_OBJECT
+ public:
+ ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
+ virtual ~ModuleBase_PreferencesDlg();
+
+ bool isChanged() const
+ {
+ return myIsChanged;
+ }
+
+ void modified(ModuleBase_Prefs& theModified) const;
+
+ public slots:
+ virtual void accept();
+
+protected slots:
+ void onDefault();
+
+ private:
+ /// Create editors for aplication properties
+ void createEditors();
+
+ /// Create a viewer page in dialog box
+ void createViewerPage(int thePageId);
+
+ /// Create menu properties page in the dialog box
+ void createMenuPage(int thePageId);
+
+ ModuleBase_PreferencesMgr* myPreferences;
+ bool myIsChanged;
+};
+
+#endif
#include <XGUI_Workshop.h>
#include <XGUI_PropertyPanel.h>
#include <XGUI_ContextMenuMgr.h>
-#include <XGUI_Preferences.h>
#include <XGUI_ObjectsBrowser.h>
#include <XGUI_OperationMgr.h>
#include <ModuleBase_Operation.h>
+#include <ModuleBase_Preferences.h>
#include <LightApp_Application.h>
#include <LightApp_SelectionMgr.h>
}
}
-class NewGeom_PrefMgr: public XGUI_IPrefMgr
+class NewGeom_PrefMgr: public ModuleBase_IPrefMgr
{
public:
NewGeom_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):myMgr(theMgr), myModName(theModName) {}
myWorkshop = new XGUI_Workshop(this);
myProxyViewer = new NewGeom_SalomeViewer(this);
- XGUI_Preferences::setResourceMgr(application()->resourceMgr());
- XGUI_Preferences::loadCustomProps();
+ ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
+ ModuleBase_Preferences::loadCustomProps();
}
//******************************************************
//******************************************************
void NewGeom_Module::onDefaultPreferences()
{
- XGUI_Preferences::resetConfig();
- XGUI_Preferences::updateResourcesByConfig();
+ ModuleBase_Preferences::resetConfig();
+ ModuleBase_Preferences::updateResourcesByConfig();
LightApp_Preferences* pref = preferences();
if (pref)
LightApp_Preferences* pref = preferences();
if (!pref)
return;
- XGUI_Preferences::updateConfigByResources();
+ ModuleBase_Preferences::updateConfigByResources();
QString aModName = moduleName();
QtxPreferenceItem* item = pref->findItem(aModName, true );
if ( catId == -1 )
return;
NewGeom_PrefMgr aMgr(pref, aModName);
- XGUI_Preferences::createEditContent(&aMgr, catId);
+ ModuleBase_Preferences::createEditContent(&aMgr, catId);
pref->retrieve();
}
SET(PROJECT_HEADERS
XGUI.h
- XGUI_Command.h
+ XGUI_ActionsMgr.h
+ XGUI_ContextMenuMgr.h
+ XGUI_DataTreeModel.h
XGUI_Displayer.h
- XGUI_MainMenu.h
- XGUI_MainWindow.h
- XGUI_MenuGroupPanel.h
- XGUI_Tools.h
- XGUI_Workbench.h
- XGUI_Workshop.h
- XGUI_ViewWindow.h
- XGUI_ViewPort.h
- XGUI_Viewer.h
- XGUI_RubberBand.h
- XGUI_Constants.h
XGUI_DocumentDataModel.h
- XGUI_PartDataModel.h
+ XGUI_ErrorDialog.h
+ XGUI_ModuleConnector.h
XGUI_ObjectsBrowser.h
XGUI_OperationMgr.h
- XGUI_DataTreeModel.h
- XGUI_SelectionMgr.h
- XGUI_SalomeConnector.h
- XGUI_ActionsMgr.h
- XGUI_ErrorDialog.h
- XGUI_ViewerProxy.h
- XGUI_PropertyPanel.h
- XGUI_ContextMenuMgr.h
- XGUI_ModuleConnector.h
- XGUI_Selection.h
- XGUI_Preferences.h
- XGUI_IPrefMgr.h
+ XGUI_PartDataModel.h
+ XGUI_PropertyPanel.h
XGUI_QtEvents.h
+ XGUI_SalomeConnector.h
+ XGUI_Selection.h
+ XGUI_SelectionMgr.h
+ XGUI_Tools.h
+ XGUI_ViewerProxy.h
+ XGUI_Workshop.h
)
SET(PROJECT_AUTOMOC
)
SET(PROJECT_SOURCES
- XGUI_Command.cpp
+ XGUI_ActionsMgr.cpp
+ XGUI_ContextMenuMgr.cpp
XGUI_Displayer.cpp
- XGUI_MainMenu.cpp
- XGUI_MainWindow.cpp
- XGUI_MenuGroupPanel.cpp
- XGUI_Tools.cpp
- XGUI_Workbench.cpp
- XGUI_Workshop.cpp
- XGUI_ViewWindow.cpp
- XGUI_ViewPort.cpp
- XGUI_Viewer.cpp
- XGUI_RubberBand.cpp
XGUI_DocumentDataModel.cpp
- XGUI_PartDataModel.cpp
+ XGUI_ErrorDialog.cpp
+ XGUI_ModuleConnector.cpp
XGUI_ObjectsBrowser.cpp
XGUI_OperationMgr.cpp
- XGUI_SelectionMgr.cpp
- XGUI_ActionsMgr.cpp
- XGUI_ErrorDialog.cpp
- XGUI_ViewerProxy.cpp
- XGUI_PropertyPanel.cpp
- XGUI_ContextMenuMgr.cpp
- XGUI_ModuleConnector.cpp
- XGUI_Selection.cpp
- XGUI_Preferences.cpp
+ XGUI_PartDataModel.cpp
+ XGUI_PropertyPanel.cpp
XGUI_QtEvents.cpp
+ XGUI_Selection.cpp
+ XGUI_SelectionMgr.cpp
+ XGUI_Tools.cpp
+ XGUI_ViewerProxy.cpp
+ XGUI_Workshop.cpp
)
SET(PROJECT_RESOURCES
Config
ModelAPI
ModuleBase
+ AppElements
${QT_LIBRARIES}
${CAS_VIEWER}
${CAS_KERNEL}
${PROJECT_SOURCE_DIR}/src/ModelAPI
${PROJECT_SOURCE_DIR}/src/GeomAPI
${PROJECT_SOURCE_DIR}/src/ModuleBase
- ${PROJECT_SOURCE_DIR}/src/PartSetPlugin
+# ${PROJECT_SOURCE_DIR}/src/PartSetPlugin
${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
+ ${PROJECT_SOURCE_DIR}/src/AppElements
${CAS_INCLUDE_DIRS}
${SUIT_INCLUDE})
*/
#include "XGUI_ActionsMgr.h"
-#include "XGUI_Command.h"
#include "XGUI_Workshop.h"
#include "XGUI_OperationMgr.h"
#include "XGUI_SalomeConnector.h"
+#include <AppElements_Command.h>
+
#include <ModelAPI_Session.h>
#include <ModuleBase_Operation.h>
return;
}
myActions.insert(aId, theCmd);
- XGUI_Command* aXCmd = dynamic_cast<XGUI_Command*>(theCmd);
+ AppElements_Command* aXCmd = dynamic_cast<AppElements_Command*>(theCmd);
if (aXCmd) {
myNestedActions[aId] = aXCmd->nestedCommands();
} else {
QString aDocKind = QString::fromStdString(aStdDocKind);
XGUI_Workshop* aWorkshop = static_cast<XGUI_Workshop*>(parent());
foreach(QAction* eachAction, myActions.values()) {
- XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(eachAction);
+ AppElements_Command* aCmd = dynamic_cast<AppElements_Command*>(eachAction);
QString aCmdDocKind;
if(aCmd) {
aCmdDocKind = aCmd->documentKind();
#include <QStringList>
#include <QKeySequence>
-class XGUI_Command;
class XGUI_Workshop;
class XGUI_OperationMgr;
class ModuleBase_Operation;
+++ /dev/null
-#include "XGUI_Command.h"
-#include <QEvent>
-#include <QToolButton>
-#include <QVariant>
-#include <QDebug>
-
-XGUI_Command::XGUI_Command(const QString& theId,
- const QString& theDocumentKind,
- QObject * parent,
- bool isCheckable)
- : QWidgetAction(parent),
- myCheckable(isCheckable),
- myDocumentKind(theDocumentKind)
-{
- setData(theId);
-}
-
-XGUI_Command::XGUI_Command(const QString& theId,
- const QString& theDocumentKind,
- const QIcon& icon,
- const QString& text,
- QObject* parent,
- bool isCheckable)
- : QWidgetAction(parent),
- myCheckable(isCheckable),
- myDocumentKind(theDocumentKind)
-{
- setIcon(icon);
- setText(text);
- setData(theId);
-}
-
-XGUI_Command::~XGUI_Command()
-{
-}
-
-const QString& XGUI_Command::documentKind() const
-{
- return myDocumentKind;
-}
-
-QWidget* XGUI_Command::createWidget(QWidget* theParent)
-{
- if (theParent->inherits("XGUI_MenuGroupPanel")) {
- QToolButton* aButton = new QToolButton(theParent);
- aButton->setIcon(icon());
- aButton->setText(text());
- QKeySequence aKeys = shortcut();
- QString aToolTip = toolTip();
- if (!aKeys.isEmpty()) {
- aToolTip = QString("%1 (%2)").arg(aToolTip).arg(aKeys.toString());
- aButton->setShortcut(aKeys);
- }
- if (!aToolTip.isEmpty()) {
- aButton->setToolTip(aToolTip);
- }
- aButton->setCheckable(myCheckable);
- aButton->setAutoRaise(true);
- aButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- aButton->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
- aButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
-
- connect(aButton, SIGNAL(clicked()), this, SLOT(trigger()));
- connect(this, SIGNAL(toggled(bool)), aButton, SLOT(setChecked(bool)));
- this->setCheckable(myCheckable);
-
- return aButton;
- }
- return QWidgetAction::createWidget(theParent);
-}
-
-void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
-{
- connect(this, SIGNAL(triggered(bool)), theResiver, theSlot);
-}
-
-const QStringList& XGUI_Command::nestedCommands() const
-{
- return myNestedCommands;
-}
-
-void XGUI_Command::setNestedCommands(const QStringList& myUnblockableCommands)
-{
- this->myNestedCommands = myUnblockableCommands;
-}
+++ /dev/null
-#ifndef XGUI_Command_H
-#define XGUI_Command_H
-
-#include "XGUI.h"
-#include <QWidgetAction>
-
-#define MIN_BUTTON_HEIGHT 25
-#define MIN_BUTTON_WIDTH 60
-
-/**\class XGUI_Command
- * \ingroup GUI
- * \brief Represents a command item in the application menu (Workbench)
- */
-class XGUI_EXPORT XGUI_Command : public QWidgetAction
-{
-Q_OBJECT
- public:
- XGUI_Command(const QString& theId, const QString& theDocumentKind,
- QObject * parent, bool isCheckable = false);
- XGUI_Command(const QString& theId, const QString& theDocumentKind,
- const QIcon& icon, const QString& text, QObject* parent,
- bool isCheckable = false);
- ~XGUI_Command();
-
- const QString& documentKind() const;
- const QStringList& nestedCommands() const;
- void setNestedCommands(const QStringList& myUnblockableCommands);
-
- //! Connect the command to a slot
- virtual void connectTo(const QObject* theResiver, const char* theSlot);
-
- protected:
- //! Creates a command representation widget dependently on parent widget type
- virtual QWidget* createWidget(QWidget* theParent);
-
- private:
- bool myCheckable;
-
- QString myDocumentKind;
- //! List of Ids of commands which WILL NOT be blocked when the command is on.
- QStringList myNestedCommands;
-};
-
-#endif
+++ /dev/null
-#ifndef XGUI_Constants_H
-#define XGUI_Constants_H
-
-namespace XGUI {
-
-//! Types of gradient type used in background of Viewer 3d
-enum GradientType
-{
- NoGradient = -1,
- HorizontalGradient,
- VerticalGradient,
- Diagonal1Gradient,
- Diagonal2Gradient,
- Corner1Gradient,
- Corner2Gradient,
- Corner3Gradient,
- Corner4Gradient,
- LastGradient = Corner4Gradient
-};
-
-//! Type of rotation point in viewer 3d
-enum RotationPointType
-{
- GRAVITY,
- SELECTED
-};
-
-//! Type of ribbon rect in Viewer 3d
-enum SketchingType
-{
- NoSketching,
- Rect,
- Polygon
-};
-
-//! View window operations accessible by hot keys
-enum HotOperation
-{
- PAN,
- ZOOM,
- ROTATE,
- FIT_AREA
-};
-
-//! Types of view window interactions
-enum InteractionStyle
-{
- STANDARD,
- KEY_FREE
-};
-
-//! Types of 2d mode in viewer 3d
-enum Mode2dType
-{
- No2dMode,
- XYPlane,
- XZPlane,
- YZPlane
-};
-
-//! Types of background in view window
-//enum BackgroundMode
-//{
-// NoBackground, // no (invalid) background data
-// ColorBackground, // single color
-// SimpleGradientBackground, // simple two-color gradient
-// CustomGradientBackground // custom (complex) gradient
-//};
-
-//! Texture mode
-enum TextureMode
-{
- CenterTexture, // center texture
- TileTexture, // tile texture
- StretchTexture, // stretch texture
-};
-
-const static char* PROP_PANEL = "property_panel_dock";
-const static char* PROP_PANEL_OK = "property_panel_ok";
-const static char* PROP_PANEL_CANCEL = "property_panel_cancel";
-
-}
-;
-
-#endif
#include "XGUI_ObjectsBrowser.h"
#include "XGUI_SelectionMgr.h"
#include "XGUI_Displayer.h"
-#include "XGUI_MainWindow.h"
#include "XGUI_ViewerProxy.h"
#include "XGUI_Selection.h"
-#include "PartSetPlugin_Part.h"
+#include <AppElements_MainWindow.h>
+
+//#include "PartSetPlugin_Part.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDocRef.h>
#define XGUI_DataTreeModel_H
#include "XGUI.h"
-#include "XGUI_Constants.h"
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
// Author: Natalia ERMOLAEVA
#include "XGUI_Displayer.h"
-#include "XGUI_Viewer.h"
#include "XGUI_Workshop.h"
#include "XGUI_ViewerProxy.h"
+#include <AppElements_Viewer.h>
+
#include <ModelAPI_Document.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
#include <QString>
#include <QMap>
-class XGUI_Viewer;
class ModelAPI_Feature;
class XGUI_Workshop;
+++ /dev/null
-// File: XGUI_IPrefMgr.h
-// Created: 10 Sept 2014
-// Author: Vitaly SMETANNIKOV
-
-
-#ifndef XGUI_IPrefMgr_H
-#define XGUI_IPrefMgr_H
-
-#include <QString>
-#include <SUIT_PreferenceMgr.h>
-
-/**
-* An interface class which provides incapsulation of SUIT_PreferenceMgr class instance
-* It is used in order to make common interface to Preference manager in Salome
-* and this application
-*/
-class XGUI_IPrefMgr
-{
-public:
-
- /**
- * Add preference item into preference dialog box
- * \param theLbl - label of the item
- * \param pId - id of container item
- * \param theType - type of the item
- * \param theSection - resouce section name
- * \param theName - name of the resource
- * Returns Id of the ctreated item
- */
- virtual int addPreference(const QString& theLbl, int pId,
- SUIT_PreferenceMgr::PrefItemType theType,
- const QString& theSection, const QString& theName ) = 0;
-
- virtual void setItemProperty(const QString& thePropName,
- const QVariant& theValue,
- const int theId = -1) = 0;
-
- /// Returns incapsulated preference manager
- virtual SUIT_PreferenceMgr* prefMgr() const = 0;
-};
-
-#endif
+++ /dev/null
-#include <XGUI_MainMenu.h>
-#include <XGUI_Workbench.h>
-#include <XGUI_MenuGroupPanel.h>
-#include <XGUI_MainWindow.h>
-#include <XGUI_Command.h>
-#include <XGUI_Preferences.h>
-
-#include <SUIT_ResourceMgr.h>
-
-#include <QLayout>
-#include <QTabWidget>
-#include <QLabel>
-#include <QDockWidget>
-#include <QEvent>
-#include <QPushButton>
-#include <QTabBar>
-
-XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent)
- : QWidget(parent),
- myDesktop(parent)
-{
- myGeneralPage = new XGUI_MenuGroupPanel(this);
- myGeneralPage->setObjectName("Default");
- myGeneralPage->parentWidget()->setMaximumWidth(200);
- myGeneralPage->installEventFilter(this);
- myGeneralPage->setFrameStyle(QFrame::StyledPanel);
-
- myMenuTabs = new QTabWidget(this);
- myMenuTabs->setStyleSheet("QTabBar::tab {height: 24px;} QTabWidget:pane {border: 0px;}");
- QHBoxLayout* aMainLayout = new QHBoxLayout(this);
- aMainLayout->addWidget(myGeneralPage);
- aMainLayout->addWidget(myMenuTabs);
- aMainLayout->setContentsMargins(0, 2, 2, 0);
- aMainLayout->setSpacing(2);
- setLayout(aMainLayout);
- updateFromResources();
-}
-
-XGUI_MainMenu::~XGUI_MainMenu(void)
-{
-}
-
-XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, const QString& theTitle)
-{
- QString aTitle = theTitle;
- if (aTitle.isEmpty()) {
- aTitle = tr(theId.toLatin1().constData());
- }
- XGUI_Workbench* aPage = new XGUI_Workbench(myMenuTabs);
- aPage->setObjectName(theId);
- myMenuTabs->addTab(aPage, aTitle);
- myWorkbenches.append(aPage);
- return aPage;
-}
-
-/*
- * Searches for already created workbench with given name.
- */
-XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName) const
-{
- return myDesktop->findChild<XGUI_Workbench*>(theObjName);
-}
-
-bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent)
-{
- if (theWatched == myGeneralPage) {
- if (theEvent->type() == QEvent::Show) {
- myGeneralPage->parentWidget()->setMaximumWidth(16777215);
- myGeneralPage->removeEventFilter(this);
- }
- }
- return QObject::eventFilter(theWatched, theEvent);
-}
-
-void XGUI_MainMenu::insertConsole(QWidget* theConsole)
-{
- int aConsoleTabId = myMenuTabs->addTab(theConsole, "Console");
-
- QTabBar* aTabBar = myMenuTabs->findChild<QTabBar*>();
- QPushButton* aCloseTabButton = new QPushButton();
- aCloseTabButton->setFixedSize(16, 16);
- aCloseTabButton->setIcon(QIcon(":pictures/wnd_close.png"));
- aCloseTabButton->setFlat(true);
- aTabBar->setTabButton(aConsoleTabId, QTabBar::RightSide, aCloseTabButton);
-
- connect(aCloseTabButton, SIGNAL(clicked()), myDesktop, SLOT(dockPythonConsole()));
-}
-
-void XGUI_MainMenu::removeConsole()
-{
- const int kLastTab = myMenuTabs->count() - 1;
- myMenuTabs->removeTab(kLastTab);
-}
-
-XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const
-{
- XGUI_Command* result;
- result = myGeneralPage->feature(theId);
- if (!result) {
- XGUI_Workbench* aWbn;
- foreach (aWbn, myWorkbenches)
- {
- result = aWbn->feature(theId);
- if (result)
- break;
- }
- }
- return result;
-}
-
-QList<XGUI_Command*> XGUI_MainMenu::features() const
-{
- QList<XGUI_Command*> aList = myGeneralPage->features();
- XGUI_Workbench* aWbn;
- foreach (aWbn, myWorkbenches)
- {
- aList.append(aWbn->features());
- }
- return aList;
-}
-
-int XGUI_MainMenu::menuItemSize() const
-{
- const int kDefaultItemSize = 25;
- return kDefaultItemSize;
-}
-
-int XGUI_MainMenu::menuHeight() const
-{
- // Default group has no tabs above --> one extra row
- int rows = menuItemRowsCount() + 1;
- const int kMarginsSpacings = 5;
- return rows * menuItemSize() + kMarginsSpacings;
-}
-
-int XGUI_MainMenu::menuItemRowsCount() const
-{
- static const int kDefaultRowsCount = 3;
- int aRowsCount = XGUI_Preferences::resourceMgr()->integerValue(XGUI_Preferences::MENU_SECTION,
- "rows_number", kDefaultRowsCount);
- return aRowsCount;
-}
-
-void XGUI_MainMenu::updateFromResources()
-{
- setFixedHeight(menuHeight());
- repaint();
-}
+++ /dev/null
-#ifndef XGUI_MainMenu_H
-#define XGUI_MainMenu_H
-
-#include "XGUI.h"
-#include <QObject>
-#include <QList>
-#include <QMap>
-#include <QWidget>
-
-class XGUI_Command;
-class XGUI_MainWindow;
-class XGUI_Workbench;
-class XGUI_MenuGroupPanel;
-
-class QTabWidget;
-class QLabel;
-class QAction;
-class QDockWidget;
-class QEvent;
-
-/**\class XGUI_MainMenu
- * \ingroup GUI
- * \brief Class for creation of main menu (set of workbenches)
- */
-class XGUI_EXPORT XGUI_MainMenu : public QWidget
-{
-Q_OBJECT
-
- public:
- XGUI_MainMenu(XGUI_MainWindow *parent);
- virtual ~XGUI_MainMenu();
-
- //! Creates and adds a new workbench (menu group) with the given name and returns it.
- XGUI_Workbench* addWorkbench(const QString& theId, const QString& theText = "");
-
- //! Returns workbench (menu group) by the given name.
- XGUI_Workbench* findWorkbench(const QString& theId) const;
-
- //! Returns General page (predefined workbench)
- XGUI_MenuGroupPanel* generalPage() const
- {
- return myGeneralPage;
- }
-
- //! Rerturns last created workbench in dock widget container
- //QDockWidget* getLastDockWindow() const;
-
- //! Returns already created command by its ID
- XGUI_Command* feature(const QString& theId) const;
-
- //! Returns list of created commands
- QList<XGUI_Command*> features() const;
-
- virtual bool eventFilter(QObject *theWatched, QEvent *theEvent);
-
- //! Displays given console as a tab in the workbench
- void insertConsole(QWidget*);
- //! Removes already created tab with python console
- void removeConsole();
-
- //! Defines size of menu item.
- //! In the future this value should be extracted from the preferences.
- int menuItemSize() const;
- //! Defines number of menu item rows.
- //! In the future this value should be extracted from the preferences.
- int menuItemRowsCount() const;
- //! Defines height of the main menu. (Number of rows * row height)
- int menuHeight() const;
-
- void updateFromResources();
-
- private:
- XGUI_MainWindow* myDesktop;
- QTabWidget* myMenuTabs;
- XGUI_MenuGroupPanel* myGeneralPage;
- QList<XGUI_Workbench*> myWorkbenches;
-
- QMap<XGUI_Command*, bool> myCommandState;
-};
-
-#endif
+++ /dev/null
-#include "XGUI_MainWindow.h"
-#include "XGUI_Constants.h"
-#include "XGUI_MainMenu.h"
-#include "XGUI_ViewWindow.h"
-#include "XGUI_Viewer.h"
-#include "XGUI_ObjectsBrowser.h"
-
-#include <PyConsole_Console.h>
-#include <PyConsole_EnhInterp.h>
-
-#include <QMdiArea>
-#include <QMdiSubWindow>
-#include <QAction>
-#include <QDockWidget>
-#include <QApplication>
-#include <QTimer>
-#include <QCloseEvent>
-
-
-XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
- : QMainWindow(parent),
- myPythonConsole(0), myIsModified(false)
-{
- myTitle = tr("New Geom");
- updateTitle();
- createMainMenu();
- QMdiArea* aMdiArea = new QMdiArea(this);
- aMdiArea->setContextMenuPolicy(Qt::ActionsContextMenu);
- setCentralWidget(aMdiArea);
- connect(aMdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this,
- SLOT(onViewActivated(QMdiSubWindow*)));
-
- // Create actions of MDI area
- QAction* aAction = new QAction(QIcon(":pictures/new_view.png"), tr("Create Window"), aMdiArea);
- aMdiArea->addAction(aAction);
- connect(aAction, SIGNAL(triggered(bool)), this, SLOT(createSubWindow()));
-
- aAction = new QAction(QIcon(":pictures/tile_views.png"), tr("Tile"), aMdiArea);
- aMdiArea->addAction(aAction);
- connect(aAction, SIGNAL(triggered(bool)), aMdiArea, SLOT(tileSubWindows()));
-
- aAction = new QAction(QIcon(":pictures/cascade_views.png"), tr("Cascade"), aMdiArea);
- aMdiArea->addAction(aAction);
- connect(aAction, SIGNAL(triggered(bool)), this, SLOT(cascadeWindows()));
-
- aAction = new QAction(aMdiArea);
- aAction->setSeparator(true);
- aMdiArea->addAction(aAction);
-
- myViewer = new XGUI_Viewer(this);
- connect(myViewer, SIGNAL(viewCreated(XGUI_ViewWindow*)), this,
- SLOT(onViewCreated(XGUI_ViewWindow*)));
- connect(myViewer, SIGNAL(deleteView(XGUI_ViewWindow*)), this,
- SLOT(onDeleteView(XGUI_ViewWindow*)));
-}
-
-XGUI_MainWindow::~XGUI_MainWindow(void)
-{
-}
-
-//******************************************************
-QMdiArea* XGUI_MainWindow::mdiArea() const
-{
- return static_cast<QMdiArea*>(centralWidget());
-}
-
-//******************************************************
-void XGUI_MainWindow::showPythonConsole()
-{
- // TODO: Check why PyConsole can not be created
- if (!myPythonConsole) {
- myPythonConsole = new PyConsole_EnhConsole(this, new PyConsole_EnhInterp());
- myPythonConsole->setObjectName("PythonConsole");
- undockPythonConsole();
- }
- myPythonConsole->parentWidget()->show();
-}
-
-//******************************************************
-void XGUI_MainWindow::hidePythonConsole()
-{
- if (myPythonConsole)
- myPythonConsole->parentWidget()->hide();
-}
-
-//******************************************************
-void XGUI_MainWindow::dockPythonConsole()
-{
- if (!myPythonConsole)
- return;
- myMenuBar->removeConsole();
- QDockWidget* aDock = new QDockWidget(this);
- aDock->setFeatures(QDockWidget::AllDockWidgetFeatures | QDockWidget::DockWidgetVerticalTitleBar);
- aDock->setAllowedAreas(
- Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
- aDock->setMinimumHeight(0);
- aDock->setWindowTitle("Console");
- aDock->setWidget(myPythonConsole);
- addDockWidget(Qt::BottomDockWidgetArea, aDock);
- // Undock python console if widget is closed...
- CloseEventWatcher* aWatcher = new CloseEventWatcher(aDock);
- connect(aWatcher, SIGNAL(widgetClosed()), this, SLOT(undockPythonConsole()));
- aDock->installEventFilter(aWatcher);
-}
-
-void XGUI_MainWindow::undockPythonConsole()
-{
- if (!myPythonConsole)
- return;
- QDockWidget* aDock = qobject_cast<QDockWidget*>(myPythonConsole->parentWidget());
- //When the application starts console will be displayed as
- //a wokbench tab, so there is no dock yet
- if (aDock) {
- aDock->hide();
- aDock->setWidget(NULL);
- aDock->deleteLater();
- }
- myMenuBar->insertConsole(myPythonConsole);
-}
-
-//******************************************************
-void XGUI_MainWindow::createSubWindow()
-{
- viewer()->createView();
-}
-
-//******************************************************
-void XGUI_MainWindow::cascadeWindows()
-{
- QMdiArea* aMdiArea = static_cast<QMdiArea*>(centralWidget());
- QList<QMdiSubWindow*> aWindows = aMdiArea->subWindowList();
-
- QSize aSize = aMdiArea->size();
- QRect aRect = aMdiArea->geometry();
- const int aOffset = 30;
- int i = 0, j = 0;
- int x, y;
- int w = aSize.width() / 2;
- int h = aSize.height() / 2;
- QMdiSubWindow* aLastWnd;
- foreach(QMdiSubWindow* aWnd, aWindows)
- {
- aWnd->showNormal();
- aWnd->raise();
- x = aOffset * i;
- if ((x + w) > aSize.width()) {
- x = 0;
- i = 0;
- }
- y = aOffset * j;
- if ((y + h) > aSize.height()) {
- y = 0;
- j = 0;
- }
- aWnd->setGeometry(QStyle::visualRect(aWnd->layoutDirection(), aRect, QRect(x, y, w, h)));
- i++;
- j++;
- viewer()->onWindowActivated(aWnd);
- aLastWnd = aWnd;
- QApplication::processEvents();
- }
- aLastWnd->setFocus();
-}
-
-void XGUI_MainWindow::onViewCreated(XGUI_ViewWindow* theWindow)
-{
- QWidget* aSubWindow = theWindow->parentWidget();
- QWidget* aMDIWidget = centralWidget();
-
- QAction* aAction = new QAction(aSubWindow->windowTitle(), aMDIWidget);
- aAction->setCheckable(true);
- connect(aAction, SIGNAL(triggered(bool)), this, SLOT(activateView()));
- aMDIWidget->addAction(aAction);
-
- QList<QAction*> aActions = aMDIWidget->actions();
- foreach(QAction* aAct, aActions)
- {
- if (aAct->isCheckable())
- aAct->setChecked(false);
- }
- aAction->setChecked(true);
-}
-
-void XGUI_MainWindow::onDeleteView(XGUI_ViewWindow* theWindow)
-{
- QWidget* aSubWindow = theWindow->parentWidget();
- QString aTitle = aSubWindow->windowTitle();
- QWidget* aMDIWidget = centralWidget();
- QList<QAction*> aActions = aMDIWidget->actions();
-
- QAction* aDelAct = 0;
- foreach(QAction* aAct, aActions)
- {
- if (aAct->text() == aTitle) {
- aDelAct = aAct;
- break;
- }
- }
- aMDIWidget->removeAction(aDelAct);
-}
-
-void XGUI_MainWindow::activateView()
-{
- QAction* aAction = static_cast<QAction*>(sender());
- QString aWndTitle = aAction->text();
- QMdiArea* aMdiArea = static_cast<QMdiArea*>(centralWidget());
-
- QList<QMdiSubWindow*> aWndList = aMdiArea->subWindowList();
- QMdiSubWindow* aTargetView = 0;
- foreach(QMdiSubWindow* aWnd, aWndList)
- {
- if (aWnd->windowTitle() == aWndTitle) {
- aWnd->raise();
- aWnd->activateWindow();
- aTargetView = aWnd;
- break;
- }
- }
- QApplication::processEvents();
- if (aTargetView)
- QTimer::singleShot(20, aTargetView, SLOT(setFocus()));
-}
-
-void XGUI_MainWindow::onViewActivated(QMdiSubWindow* theSubWnd)
-{
- if (!theSubWnd)
- return;
- QMdiArea* aMdiArea = static_cast<QMdiArea*>(centralWidget());
- QString aWndTitle = theSubWnd->windowTitle();
- QList<QAction*> aActionList = aMdiArea->actions();
- foreach(QAction* aAct, aActionList)
- {
- if (aAct->isCheckable())
- aAct->setChecked(aAct->text() == aWndTitle);
- }
-}
-
-void XGUI_MainWindow::closeEvent(QCloseEvent * event)
-{
- emit exitKeySequence();
- event->ignore();
-}
-
-void XGUI_MainWindow::createMainMenu()
-{
- myMenuBar = new XGUI_MainMenu(this);
- QDockWidget* aMenuDock = new QDockWidget(this);
- aMenuDock->setWidget(myMenuBar);
- aMenuDock->setAllowedAreas(Qt::TopDockWidgetArea);
- aMenuDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar);
- aMenuDock->setWindowTitle(tr("General"));
- addDockWidget(Qt::TopDockWidgetArea, aMenuDock);
-}
-
-
-void XGUI_MainWindow::updateTitle()
-{
- QString aTitle = myTitle;
- if (!myCurrentDir.isNull())
- aTitle += " - " + myCurrentDir;
- if (myIsModified)
- aTitle += "*";
- setWindowTitle(aTitle);
-}
-
-void XGUI_MainWindow::setCurrentDir(const QString& theDir, bool toUpdate)
-{
- myCurrentDir = theDir;
- if (toUpdate)
- updateTitle();
-}
-
-void XGUI_MainWindow::setModifiedState(bool isModified, bool toUpdate)
-{
- myIsModified = isModified;
- if (toUpdate)
- updateTitle();
-}
-
-CloseEventWatcher::CloseEventWatcher(QObject* theParent)
- : QObject(theParent)
-{
-}
-
-bool CloseEventWatcher::eventFilter(QObject *obj, QEvent *event)
-{
- if (event->type() == QEvent::Close) {
- emit widgetClosed();
- event->ignore();
- return true;
- } else {
- // standard event processing
- return QObject::eventFilter(obj, event);
- }
-}
-
+++ /dev/null
-#ifndef XGUI_MAINWINDOW_H
-#define XGUI_MAINWINDOW_H
-
-#include "XGUI.h"
-#include <QMainWindow>
-
-class XGUI_MainMenu;
-class XGUI_Viewer;
-class XGUI_ActionsMgr;
-class XGUI_ViewWindow;
-class QMdiArea;
-class QMdiSubWindow;
-class PyConsole_EnhConsole;
-class QCloseEvent;
-
-/**\class XGUI_MainWindow
- * \ingroup GUI
- * \brief Main window of the application (Desktop).
- * It contains: Object Browser, 3d Viewer, Python console, property panel, main menu
- */
-class XGUI_EXPORT XGUI_MainWindow : public QMainWindow
-{
-Q_OBJECT
-
- public:
- XGUI_MainWindow(QWidget* parent = 0);
- virtual ~XGUI_MainWindow();
-
- //! Returns main menu object
- XGUI_MainMenu* menuObject() const
- {
- return myMenuBar;
- }
-
- //! Returns MDI area
- QMdiArea* mdiArea() const;
-
- //! Returns 3d viewer
- XGUI_Viewer* viewer() const
- {
- return myViewer;
- }
-
- public slots:
- void showPythonConsole();
- void hidePythonConsole();
- //! Python console can be a dock widget
- void dockPythonConsole();
- //! or can be a tab in the main menu.
- void undockPythonConsole();
-
- void createSubWindow();
-
- /// Add name of current directory into title of desktop window
- void setCurrentDir(const QString& theDir, bool toUpdate = true);
-
- /// Add asterisk to a title of the window
- void setModifiedState(bool isModified, bool toUpdate = true);
-
- /// Returns current state of modification
- bool isModifiedState() const { return myIsModified; }
-
- void updateTitle();
-
- private slots:
- void cascadeWindows();
- void onViewCreated(XGUI_ViewWindow* theWindow);
- void onDeleteView(XGUI_ViewWindow* theWindow);
- void activateView();
- void onViewActivated(QMdiSubWindow* theSubWnd);
-
-signals:
- void exitKeySequence();
-
- protected:
- void closeEvent(QCloseEvent* event);
- void createMainMenu();
-
- private:
- XGUI_MainMenu* myMenuBar;
- XGUI_Viewer* myViewer;
-
- QString myTitle;
- QString myCurrentDir;
- bool myIsModified;
-
- PyConsole_EnhConsole* myPythonConsole;
-};
-
-class XGUI_EXPORT CloseEventWatcher : public QObject
-{
-Q_OBJECT
-
- public:
- CloseEventWatcher(QObject* theParent);
-
-signals:
- void widgetClosed();
-
- protected:
- bool eventFilter(QObject *obj, QEvent *);
-
-};
-
-#endif
+++ /dev/null
-#include "XGUI_MenuGroupPanel.h"
-#include "XGUI_Command.h"
-
-#include <QLayout>
-#include <QPushButton>
-#include <QAction>
-#include <QResizeEvent>
-
-#include <math.h>
-#include <iostream>
-
-XGUI_MenuGroupPanel::XGUI_MenuGroupPanel(QWidget *parent)
- : QFrame(parent),
- myNewRow(0),
- myNewCol(0),
- myMaxRow(1)
-{
- myLayout = new QGridLayout(this);
- myLayout->setSpacing(0);
- myLayout->setMargin(0);
- myLayout->setContentsMargins(0, 0, 0, 0);
- setFrameShape(QFrame::NoFrame);
-}
-
-void XGUI_MenuGroupPanel::addCommand(XGUI_Command* theAction)
-{
- myActions.append(theAction);
- QWidget* aWdg = theAction->requestWidget(this);
- myActionWidget.append(aWdg);
- addWidget(aWdg);
-}
-
-void XGUI_MenuGroupPanel::placeWidget(QWidget* theWgt)
-{
- if (myMaxRow == myNewRow) {
- myNewRow = 0;
- myNewCol++;
- }
- myLayout->addWidget(theWgt, myNewRow, myNewCol);
- myLayout->setRowStretch(myNewRow, 0);
- myNewRow++;
-}
-
-void XGUI_MenuGroupPanel::addWidget(QWidget* theWgt)
-{
- placeWidget(theWgt);
-}
-
-void XGUI_MenuGroupPanel::resizeEvent(QResizeEvent* theEvent)
-{
- QWidget::resizeEvent(theEvent);
- if (myActions.size() == 0)
- return;
-
- int aH = theEvent->size().height();
- int aMaxRow = (int) floor(double(aH / MIN_BUTTON_HEIGHT));
- if (aMaxRow == myMaxRow)
- return;
-
- myMaxRow = aMaxRow;
- myNewRow = 0;
- myNewCol = 0;
- foreach(QWidget* eachWidget, myActionWidget)
- {
- placeWidget(eachWidget);
- }
- myLayout->setRowStretch(myMaxRow + 1, 1);
-}
-
-XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId,
- const QString& theTip,
- const QString& theTitle,
- const QIcon& theIcon,
- const QKeySequence& theKeys)
-{
- return addFeature(theId, theTip, theTitle, theIcon, QString(), theKeys, false);
-}
-
-XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId,
- const QString& theTitle,
- const QString& theTip,
- const QIcon& theIcon,
- const QString& theDocumentKind,
- const QKeySequence& theKeys,
- bool isCheckable)
-{
- XGUI_Command* aCommand = new XGUI_Command(theId, theDocumentKind, theIcon,
- theTitle, this, isCheckable);
- aCommand->setToolTip(theTip);
- if (!theKeys.isEmpty()) {
- aCommand->setShortcut(theKeys);
- }
- addCommand(aCommand);
- return aCommand;
-}
-
-XGUI_Command* XGUI_MenuGroupPanel::feature(const QString& theId) const
-{
- foreach (XGUI_Command* aCmd, myActions)
- {
- if (aCmd->data().toString() == theId)
- return aCmd;
- }
- return 0;
-}
+++ /dev/null
-#ifndef XGUI_MenuGroupPanel_H
-#define XGUI_MenuGroupPanel_H
-
-#include "XGUI.h"
-#include <QFrame>
-#include <QMap>
-
-class XGUI_Command;
-class QGridLayout;
-
-/**\class XGUI_MenuGroupPanel
- * \ingroup GUI
- * \brief Represents a one group in a page of main menu (workbench)
- */
-class XGUI_EXPORT XGUI_MenuGroupPanel : public QFrame
-{
-Q_OBJECT
-
- public:
- explicit XGUI_MenuGroupPanel(QWidget *parent = 0);
-
- //! Adding a new feature (Command) in the group
- XGUI_Command* addFeature(const QString& theId,
- const QString& theTip,
- const QString& theTitle,
- const QIcon& theIcon,
- const QKeySequence& theKeys = QKeySequence());
-
- XGUI_Command* addFeature(const QString& theId,
- const QString& theTip,
- const QString& theTitle,
- const QIcon& theIcon,
- const QString& theDocumentKind = QString(),
- const QKeySequence& theKeys = QKeySequence(),
- bool isCheckable = false);
-
- //! Returns already created command by its ID
- XGUI_Command* feature(const QString& theId) const;
-
- //! Returns list of created commands
- QList<XGUI_Command*> features() const
- {
- return myActions;
- }
-
- protected:
- virtual void resizeEvent(QResizeEvent *theEvent);
-
- private:
- void addWidget(QWidget* theWgt);
- void placeWidget(QWidget* theWgt);
- void addCommand(XGUI_Command* theAction);
-
- QList<XGUI_Command*> myActions;
- QWidgetList myActionWidget;
-
- QGridLayout* myLayout;
- int myNewRow;
- int myNewCol;
- int myMaxRow;
-};
-
-#endif
+++ /dev/null
-// File: XGUI_Preferences.cpp
-// Created: 07 Aug 2014
-// Author: Vitaly SMETANNIKOV
-
-#include "XGUI_Preferences.h"
-#include "XGUI_Constants.h"
-
-#include <Config_PropManager.h>
-
-#include <SUIT_ResourceMgr.h>
-#include <SUIT_PreferenceMgr.h>
-#include <Qtx.h>
-
-#include <QLayout>
-#include <QApplication>
-#include <QDialogButtonBox>
-#include <QPushButton>
-
-const QString XGUI_Preferences::VIEWER_SECTION = "Viewer";
-const QString XGUI_Preferences::MENU_SECTION = "Menu";
-
-SUIT_ResourceMgr* XGUI_Preferences::myResourceMgr = 0;
-
-SUIT_ResourceMgr* XGUI_Preferences::resourceMgr()
-{
- if (!myResourceMgr) {
- myResourceMgr = new SUIT_ResourceMgr("NewGeom");
- myResourceMgr->setCurrentFormat("xml");
- }
- return myResourceMgr;
-}
-
-bool XGUI_Preferences::editPreferences(XGUI_Prefs& theModified)
-{
- XGUI_PreferencesDlg aDlg(resourceMgr(), QApplication::activeWindow());
- aDlg.exec();
- if (aDlg.isChanged()) {
- aDlg.modified(theModified);
- resourceMgr()->save();
- return true;
- }
- return false;
-}
-
-void XGUI_Preferences::updateConfigByResources()
-{
- Config_Properties aProps = Config_PropManager::getProperties();
- Config_Properties::iterator aIt;
- for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
- Config_Prop* aProp = (*aIt);
- QString aVal = myResourceMgr->stringValue(QString(aProp->section().c_str()),
- QString(aProp->name().c_str()));
- if (!aVal.isEmpty()) {
- aProp->setValue(aVal.toStdString());
- }
- }
-}
-
-void XGUI_Preferences::updateResourcesByConfig()
-{
- Config_Properties aProps = Config_PropManager::getProperties();
- Config_Properties::iterator aIt;
- for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
- Config_Prop* aProp = (*aIt);
- myResourceMgr->setValue(QString(aProp->section().c_str()), QString(aProp->name().c_str()),
- QString(aProp->value().c_str()));
- }
-}
-
-void XGUI_Preferences::resetConfig()
-{
- Config_Properties aProps = Config_PropManager::getProperties();
- Config_Properties::iterator aIt;
- for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
- Config_Prop* aProp = (*aIt);
- aProp->setValue(aProp->defaultValue());
- }
-}
-
-void XGUI_Preferences::loadCustomProps()
-{
- if(!myResourceMgr)
- return;
- QStringList aSections = myResourceMgr->sections();
- foreach (QString aSection, aSections)
- {
- QStringList aParams = myResourceMgr->parameters(aSection);
- foreach (QString aParam, aParams)
- {
- Config_Prop* aProp = Config_PropManager::registerProp(aSection.toStdString(),
- aParam.toStdString(), "", Config_Prop::Disabled);
- aProp->setValue(myResourceMgr->stringValue(aSection, aParam).toStdString());
- }
- }
-}
-
-
-void XGUI_Preferences::createEditContent(XGUI_IPrefMgr* thePref, int thePage)
-{
- thePref->prefMgr()->setItemIcon(thePage, QIcon(":pictures/module.png"));
- createCustomPage(thePref, thePage);
-}
-
-
-void XGUI_Preferences::createCustomPage(XGUI_IPrefMgr* thePref, int thePageId)
-{
- SUIT_ResourceMgr* aResMgr = XGUI_Preferences::resourceMgr();
- bool isResModified = false;
-
- // Make a Tab from each section
- std::list<std::string> aSections = Config_PropManager::getSections();
- std::list<std::string>::const_iterator it;
- for (it = aSections.cbegin(); it != aSections.cend(); ++it) {
- Config_Properties aProps = Config_PropManager::getProperties(*it);
- int aTab = thePref->prefMgr()->addItem(QString((*it).c_str()), thePageId);
- thePref->prefMgr()->setItemProperty("columns", 2, aTab);
-
- Config_Properties::const_iterator aIt;
- for (aIt = aProps.cbegin(); aIt != aProps.cend(); ++aIt) {
- Config_Prop* aProp = (*aIt);
- // check that the property is defined
- QString aSection(aProp->section().c_str());
- QString aName(aProp->name().c_str());
- if (!aResMgr->hasValue(aSection, aName)) {
- aResMgr->setValue(aSection, aName, QString(aProp->value().c_str()));
- isResModified = true;
- }
- // Add item
- if (aProp->type() != Config_Prop::Disabled) {
- SUIT_PreferenceMgr::PrefItemType aPrefType = SUIT_PreferenceMgr::Auto;
- if (aProp->type() == Config_Prop::Directory) {
- aPrefType = SUIT_PreferenceMgr::File;
- } else {
- aPrefType = (SUIT_PreferenceMgr::PrefItemType) aProp->type();
- }
- int anId = thePref->addPreference(QObject::tr(aProp->title().c_str()), aTab, aPrefType,
- QString::fromStdString(aProp->section()),
- QString::fromStdString(aProp->name()));
- if(aProp->type() == Config_Prop::Directory) {
- thePref->setItemProperty("path_type", Qtx::PT_Directory, anId);
- }
- }
- }
- }
-}
-
-//**********************************************************
-//**********************************************************
-//**********************************************************
-class XGUI_PrefMgr: public XGUI_IPrefMgr
-{
-public:
- XGUI_PrefMgr(XGUI_PreferencesMgr* theMgr):myMgr(theMgr) {}
-
- virtual int addPreference(const QString& theLbl, int pId,
- SUIT_PreferenceMgr::PrefItemType theType,
- const QString& theSection, const QString& theName )
- {
- return myMgr->addItem(theLbl, pId, theType, theSection, theName);
- }
-
- virtual void setItemProperty( const QString& thePropName, const QVariant& theValue,
- const int theId = -1) {
- myMgr->setItemProperty(thePropName, theValue, theId);
- }
-
- virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
-
-private:
- XGUI_PreferencesMgr* myMgr;
-};
-
-//**********************************************************
-//**********************************************************
-//**********************************************************
-XGUI_PreferencesDlg::XGUI_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent)
- : QDialog(theParent),
- myIsChanged(false)
-{
- setWindowTitle(tr("Edit preferences"));
-
- QVBoxLayout* main = new QVBoxLayout(this);
- main->setMargin(5);
- main->setSpacing(5);
-
- myPreferences = new XGUI_PreferencesMgr(theResurces, this);
- main->addWidget(myPreferences);
-
- setFocusProxy(myPreferences);
- myPreferences->setFrameStyle(QFrame::Box | QFrame::Sunken);
-
- QDialogButtonBox* aBtnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
- QDialogButtonBox::Reset,
- Qt::Horizontal, this);
- QPushButton* aDefaultButton = aBtnBox->button(QDialogButtonBox::Reset);
- aDefaultButton->setText(tr("Default"));
- connect(aDefaultButton, SIGNAL(clicked()), this, SLOT(onDefault()));
-
- main->addWidget(aBtnBox);
- connect(aBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
- connect(aBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
- createEditors();
-
- myPreferences->retrieve();
- setMinimumSize(800, 200);
-}
-
-XGUI_PreferencesDlg::~XGUI_PreferencesDlg()
-{
-}
-
-void XGUI_PreferencesDlg::createEditors()
-{
- int aPage = myPreferences->addItem(tr("Desktop"));
- myPreferences->setItemIcon(aPage, QIcon(":pictures/view_prefs.png"));
-
- createMenuPage(aPage);
- createViewerPage(aPage);
-
- aPage = myPreferences->addItem(tr("Module"));
- myPreferences->setItemIcon(aPage, QIcon(":pictures/module.png"));
-
- XGUI_PrefMgr aMgr(myPreferences);
- XGUI_Preferences::createEditContent(&aMgr, aPage);
-}
-
-void XGUI_PreferencesDlg::createViewerPage(int thePageId)
-{
- int viewTab = myPreferences->addItem(tr("Viewer"), thePageId);
-
- QStringList gradList;
- gradList << tr("Horizontal gradient") << tr("Vertical gradient") << tr("First diagonal gradient")
- << tr("Second diagonal gradient") << tr("First corner gradient")
- << tr("Second corner gradient") << tr("Third corner gradient")
- << tr("Fourth corner gradient");
-
- QList<QVariant> idList;
- for (int i = 0; i < gradList.size(); i++)
- idList << i;
-
- int bgGroup = myPreferences->addItem(tr("Background"), viewTab);
-
- QString aImgFiles("Image files (*.bmp *.gif *.pix *.xwd *.rgb *.rs)");
-
- int bgId = myPreferences->addItem(tr("Viewer 3d"), bgGroup, SUIT_PreferenceMgr::Background,
- XGUI_Preferences::VIEWER_SECTION, "background");
- myPreferences->setItemProperty("gradient_names", gradList, bgId);
- myPreferences->setItemProperty("gradient_ids", idList, bgId);
- myPreferences->setItemProperty("texture_enabled", true, bgId);
- myPreferences->setItemProperty("texture_center_enabled", true, bgId);
- myPreferences->setItemProperty("texture_tile_enabled", true, bgId);
- myPreferences->setItemProperty("texture_stretch_enabled", true, bgId);
- myPreferences->setItemProperty("custom_enabled", false, bgId);
- myPreferences->setItemProperty("image_formats", aImgFiles, bgId);
-}
-
-void XGUI_PreferencesDlg::createMenuPage(int thePageId)
-{
- int aMenuTab = myPreferences->addItem(tr("Main menu"), thePageId);
-
- int aSizeGroup = myPreferences->addItem(tr("Size"), aMenuTab);
- myPreferences->setItemProperty("columns", 1, aSizeGroup);
-
- int aRowsNb = myPreferences->addItem(tr("Number of rows"), aSizeGroup,
- SUIT_PreferenceMgr::IntSpin, XGUI_Preferences::MENU_SECTION,
- "rows_number");
- myPreferences->setItemProperty("min", 1, aRowsNb);
- myPreferences->setItemProperty("max", 6, aRowsNb);
-}
-
-void XGUI_PreferencesDlg::accept()
-{
- myPreferences->store();
- myIsChanged = true;
-
- // Save custom properties
- XGUI_Preferences::updateConfigByResources();
- QDialog::accept();
-}
-
-void XGUI_PreferencesDlg::modified(XGUI_Prefs& theModified) const
-{
- theModified = myPreferences->modified();
-}
-
-void XGUI_PreferencesDlg::onDefault()
-{
- // reset main resources
-#ifdef SALOME_750 // until SALOME 7.5.0 is released
- QtxResourceMgr::WorkingMode aPrev =
- myPreferences->resourceMgr()->setWorkingMode(QtxResourceMgr::IgnoreUserValues);
- myPreferences->retrieve();
- myPreferences->resourceMgr()->setWorkingMode(aPrev);
-#endif
- // reset plugin's resources
- XGUI_Preferences::resetConfig();
- XGUI_Preferences::updateResourcesByConfig();
-
- myPreferences->retrieve();
-}
-
-//**********************************************************
-//**********************************************************
-//**********************************************************
-void XGUI_PreferencesMgr::changedResources(const ResourceMap& theMap)
-{
- myModified.clear();
- ResourceMap::ConstIterator it;
- QString sec, param;
- for (it = theMap.begin(); it != theMap.end(); ++it) {
- XGUI_Pref aPref;
- it.key()->resource(aPref.first, aPref.second);
- myModified.append(aPref);
- }
-}
+++ /dev/null
-// File: XGUI_Preferences.h
-// Created: 07 Aug 2014
-// Author: Vitaly SMETANNIKOV
-
-#ifndef XGUI_Preferences_H
-#define XGUI_Preferences_H
-
-#include "XGUI.h"
-#include "XGUI_IPrefMgr.h"
-
-#include <SUIT_PreferenceMgr.h>
-#include <QDialog>
-
-class SUIT_ResourceMgr;
-class QWidget;
-
-// Pair of values: section name, value name
-typedef QPair<QString, QString> XGUI_Pref;
-typedef QList<XGUI_Pref> XGUI_Prefs;
-
-//***********************************************************************
-/// Class for manipulation with preferences in the application
-class XGUI_EXPORT XGUI_Preferences
-{
- public:
- static const QString VIEWER_SECTION;
- static const QString MENU_SECTION;
-
- static bool editPreferences(XGUI_Prefs& theModified);
-
- /// Returns currently installed resource manager
- static SUIT_ResourceMgr* resourceMgr();
-
- /// Sets a resource manager
- /// It is used in case of necessity to define external resource manager (not NewGeom)
- static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
-
- /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
- static void updateConfigByResources();
-
- /// Updates SUIT_ResourceMgr values by Config_PropManager properties
- /// \param theUpdateOnlyInvalid flag to update only invalid values, if it is false, all are updated
- static void updateResourcesByConfig();
-
- /// Set default values to the Config_PropManager properties
- static void resetConfig();
-
- /// Loads properties defined by module to Config_PropManager
- static void loadCustomProps();
-
- ///
- static void createEditContent(XGUI_IPrefMgr* thePref, int thePage);
-
-private:
- /// Creates content of preferences editing widget
- static void createCustomPage(XGUI_IPrefMgr* thePref, int thePageId);
-
- static SUIT_ResourceMgr* myResourceMgr;
-};
-
-//***********************************************************************
-/// Manager of preferences
-class XGUI_EXPORT XGUI_PreferencesMgr : public SUIT_PreferenceMgr
-{
-Q_OBJECT
- public:
- XGUI_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
- : SUIT_PreferenceMgr(theResource, theParent)
- {
- }
-
- virtual ~XGUI_PreferencesMgr()
- {
- }
-
- XGUI_Prefs modified() const
- {
- return myModified;
- }
-
- protected:
- virtual void changedResources(const ResourceMap& theMap);
-
- private:
- XGUI_Prefs myModified;
-};
-
-//***********************************************************************
-/// Dialog box for preferences editing
-class XGUI_EXPORT XGUI_PreferencesDlg : public QDialog
-{
-Q_OBJECT
- public:
- XGUI_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
- virtual ~XGUI_PreferencesDlg();
-
- bool isChanged() const
- {
- return myIsChanged;
- }
-
- void modified(XGUI_Prefs& theModified) const;
-
- public slots:
- virtual void accept();
-
-protected slots:
- void onDefault();
-
- private:
- /// Create editors for aplication properties
- void createEditors();
-
- /// Create a viewer page in dialog box
- void createViewerPage(int thePageId);
-
- /// Create menu properties page in the dialog box
- void createMenuPage(int thePageId);
-
- XGUI_PreferencesMgr* myPreferences;
- bool myIsChanged;
-};
-
-#endif
*/
#include <XGUI_PropertyPanel.h>
-#include <XGUI_Constants.h>
+//#include <AppElements_Constants.h>
#include <ModuleBase_WidgetMultiSelector.h>
#include <QWidget>
{
this->setWindowTitle(tr("Property Panel"));
QAction* aViewAct = this->toggleViewAction();
- this->setObjectName(XGUI::PROP_PANEL);
+ this->setObjectName(PROP_PANEL);
setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
QWidget* aContent = new QWidget(this);
aBtnLay->addWidget(aBtn);
aBtnLay->addStretch(1);
aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
- aBtn->setObjectName(XGUI::PROP_PANEL_OK);
+ aBtn->setObjectName(PROP_PANEL_OK);
aBtn->setToolTip(tr("Ok"));
aBtn->setFlat(true);
aBtnLay->addWidget(aBtn);
aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
aBtn->setToolTip(tr("Cancel"));
- aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
+ aBtn->setObjectName(PROP_PANEL_CANCEL);
aBtn->setFlat(true);
aBtn->setShortcut(QKeySequence(Qt::Key_Escape));
aBtnLay->addWidget(aBtn);
if (!aControls.empty()) {
QWidget* aLastControl = aControls.last();
- QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
- QPushButton* aCancelBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
+ QPushButton* anOkBtn = findChild<QPushButton*>(PROP_PANEL_OK);
+ QPushButton* aCancelBtn = findChild<QPushButton*>(PROP_PANEL_CANCEL);
setTabOrder(aLastControl, anOkBtn);
setTabOrder(anOkBtn, aCancelBtn);
void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
{
- QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
+ QPushButton* anOkBtn = findChild<QPushButton*>(PROP_PANEL_OK);
anOkBtn->setEnabled(isEnabled);
}
class QKeyEvent;
class QVBoxLayout;
+const static char* PROP_PANEL = "property_panel_dock";
+const static char* PROP_PANEL_OK = "property_panel_ok";
+const static char* PROP_PANEL_CANCEL = "property_panel_cancel";
+
class XGUI_EXPORT XGUI_PropertyPanel : public ModuleBase_IPropertyPanel
{
Q_OBJECT
public:
+
+
XGUI_PropertyPanel(QWidget* theParent);
virtual ~XGUI_PropertyPanel();
+++ /dev/null
-#include "XGUI_RubberBand.h"\r
-\r
-#include <QBitmap>\r
-#include <QImage>\r
-#include <QPaintEvent>\r
-#include <QPainter>\r
-#include <QPalette>\r
-#include <QShowEvent>\r
-#include <QVectorIterator>\r
-\r
-/*!\r
- \class QtxAbstractRubberBand\r
- \brief Analog of class QRubberBand with possibility of creation non-rectangular contour for selection.\r
- \r
- Currently this class does not support Style functionality in full.\r
- */\r
-\r
-/*!\r
- \brief Constructor\r
- \param theParent parent widget\r
- */\r
-\r
-XGUI_AbstractRubberBand::XGUI_AbstractRubberBand(QWidget* theParent)\r
- : QWidget(theParent),\r
- myPoints(),\r
- myIsClosed(false)\r
-{\r
- setAttribute(Qt::WA_TransparentForMouseEvents);\r
-#ifndef WIN32\r
- setAttribute(Qt::WA_NoSystemBackground);\r
-#endif //WIN32\r
- setAttribute(Qt::WA_WState_ExplicitShowHide);\r
- setVisible(false);\r
- theParent->installEventFilter(this);\r
- setGeometry(QRect(QPoint(0, 0), theParent->size()));\r
-}\r
-\r
-/*!\r
- \brief Destructor\r
- */\r
-XGUI_AbstractRubberBand::~XGUI_AbstractRubberBand()\r
-{\r
-}\r
-\r
-void XGUI_AbstractRubberBand::clearGeometry()\r
-{\r
- myPoints.clear();\r
-}\r
-\r
-bool XGUI_AbstractRubberBand::isClosed()\r
-{\r
- return myIsClosed;\r
-}\r
-\r
-void XGUI_AbstractRubberBand::paintEvent(QPaintEvent* theEvent)\r
-{\r
- if (!myPoints.empty()) {\r
- QPixmap tiledPixmap(16, 16);\r
-\r
- QPainter pixmapPainter(&tiledPixmap);\r
- pixmapPainter.setPen(Qt::NoPen);\r
- pixmapPainter.setBrush(QBrush(Qt::black, Qt::Dense4Pattern));\r
- pixmapPainter.setBackground(QBrush(Qt::white));\r
- pixmapPainter.setBackgroundMode(Qt::OpaqueMode);\r
- pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());\r
- pixmapPainter.end();\r
- // ### workaround for borked XRENDER\r
- tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());\r
-\r
- QPainter aPainter(this);\r
- aPainter.setRenderHint(QPainter::Antialiasing);\r
- QRect r = myPoints.boundingRect();\r
- aPainter.setClipRegion(r.normalized().adjusted(-1, -1, 2, 2));\r
- aPainter.drawTiledPixmap(0, 0, width(), height(), tiledPixmap);\r
-\r
- aPainter.end();\r
- }\r
-}\r
-\r
-void XGUI_AbstractRubberBand::showEvent(QShowEvent* theEvent)\r
-{\r
- raise();\r
- theEvent->ignore();\r
-}\r
-\r
-void XGUI_AbstractRubberBand::moveEvent(QMoveEvent*)\r
-{\r
-}\r
-\r
-void XGUI_AbstractRubberBand::resizeEvent(QResizeEvent*)\r
-{\r
-}\r
-\r
-bool XGUI_AbstractRubberBand::eventFilter(QObject* obj, QEvent* e)\r
-{\r
- if (obj && obj == parent() && e->type() == QEvent::Resize) {\r
- QWidget* p = (QWidget*) parent();\r
- setGeometry(QRect(QPoint(0, 0), p->size()));\r
- }\r
- return QWidget::eventFilter(obj, e);\r
-}\r
-\r
-QRegion createRegion(const QPointF& p1, const QPointF& p2)\r
-{\r
- if (p1 == p2)\r
- return QRegion();\r
-\r
- QLineF n = QLineF(p1, p2).normalVector(); //.unitVector();\r
- n.setLength(1);\r
- n.translate(p1 * -1);\r
- QPointF nPoint = n.p2();\r
-\r
- QPolygonF p;\r
- p << p1 + nPoint << p2 + nPoint << p2 - nPoint << p1 - nPoint << p1 + nPoint;\r
-\r
- return QRegion(p.toPolygon());\r
-}\r
-\r
-void XGUI_AbstractRubberBand::updateMask()\r
-{\r
- QRegion r;\r
-\r
- QVectorIterator<QPoint> it(myPoints);\r
- while (it.hasNext()) {\r
- QPoint p = it.next();\r
- if (!it.hasNext())\r
- break;\r
-\r
- QPoint np = it.peekNext();\r
-\r
- if (p == np)\r
- continue;\r
-\r
- r += createRegion(p, np);\r
- }\r
-\r
- if (isClosed())\r
- r += createRegion(myPoints.last(), myPoints.first());\r
-\r
- if (!r.isEmpty())\r
- setMask(r);\r
-}\r
-\r
-//**********************************************************\r
-XGUI_RectRubberBand::XGUI_RectRubberBand(QWidget* parent)\r
- : XGUI_AbstractRubberBand(parent)\r
-{\r
- myPoints.resize(4);\r
- myIsClosed = true;\r
-}\r
-\r
-XGUI_RectRubberBand::~XGUI_RectRubberBand()\r
-{\r
-}\r
-\r
-void XGUI_RectRubberBand::initGeometry(const QRect& theRect)\r
-{\r
- myPoints.clear();\r
- myPoints << theRect.topLeft() << theRect.topRight() << theRect.bottomRight()\r
- << theRect.bottomLeft();\r
- //setMask( QRegion( myPoints ) );\r
- updateMask();\r
-}\r
-\r
-void XGUI_RectRubberBand::setStartPoint(const QPoint& thePoint)\r
-{\r
- myPoints[0] = thePoint;\r
- myPoints[1].setY(thePoint.y());\r
- myPoints[3].setX(thePoint.x());\r
- updateMask();\r
-}\r
-\r
-void XGUI_RectRubberBand::setEndPoint(const QPoint& thePoint)\r
-{\r
- myPoints[2] = thePoint;\r
- myPoints[1].setX(thePoint.x());\r
- myPoints[3].setY(thePoint.y());\r
- updateMask();\r
-}\r
-\r
-void XGUI_RectRubberBand::clearGeometry()\r
-{\r
- QMutableVectorIterator<QPoint> i(myPoints);\r
- while (i.hasNext()) {\r
- i.next();\r
- i.setValue(QPoint(-1, -1));\r
- }\r
-}\r
-\r
-//**********************************************************\r
-XGUI_PolyRubberBand::XGUI_PolyRubberBand(QWidget* parent)\r
- : XGUI_AbstractRubberBand(parent)\r
-{\r
-}\r
-\r
-XGUI_PolyRubberBand::~XGUI_PolyRubberBand()\r
-{\r
-}\r
-\r
-void XGUI_PolyRubberBand::initGeometry(const QPolygon& thePoints)\r
-{\r
- myPoints = thePoints;\r
- updateMask();\r
-}\r
-\r
-void XGUI_PolyRubberBand::initGeometry(const QPoint& thePoint)\r
-{\r
- myPoints.clear();\r
- myPoints << thePoint;\r
- updateMask();\r
-}\r
-\r
-void XGUI_PolyRubberBand::addNode(const QPoint& thePoint)\r
-{\r
- myPoints << thePoint;\r
- updateMask();\r
-}\r
-\r
-void XGUI_PolyRubberBand::replaceLastNode(const QPoint& thePoint)\r
-{\r
- if (!myPoints.empty()) {\r
- myPoints.pop_back();\r
- myPoints << thePoint;\r
- updateMask();\r
- }\r
-}\r
-\r
-void XGUI_PolyRubberBand::removeLastNode()\r
-{\r
- if (!myPoints.empty()) {\r
- myPoints.pop_back();\r
- updateMask();\r
- }\r
-}\r
-\r
-void XGUI_PolyRubberBand::setClosed(bool theFlag)\r
-{\r
- if (myIsClosed != theFlag) {\r
- myIsClosed = theFlag;\r
- updateMask();\r
- }\r
-}\r
+++ /dev/null
-#ifndef XGUI_RubberBand_H
-#define XGUI_RubberBand_H
-
-#include "XGUI.h"
-#include <QWidget>
-
-/*!
- \class XGUI_AbstractRubberBand
- \ingroup GUI
- \brief Analog of class QRubberBand with possibility of creation non-rectangular contour for selection.
-
- Currently this class does not support Style functionality in full.
- */
-class XGUI_EXPORT XGUI_AbstractRubberBand : public QWidget
-{
-Q_OBJECT
- protected:
- XGUI_AbstractRubberBand(QWidget*);
-
- public:
- virtual ~XGUI_AbstractRubberBand();
-
- virtual void clearGeometry();
-
- bool isClosed();
-
- protected:
- virtual void paintEvent(QPaintEvent*);
- virtual void showEvent(QShowEvent*);
- virtual void moveEvent(QMoveEvent*);
- virtual void resizeEvent(QResizeEvent*);
-
- virtual bool eventFilter(QObject*, QEvent*);
-
- virtual void updateMask();
-
- protected:
- QPolygon myPoints;
-
- bool myIsClosed;
-};
-
-/*!
- \class XGUI_RectRubberBand
- \ingroup GUI
- \brief Analog of class QRubberBand with possibility of creation non-rectangular contour for selection.
-
- Redefinition for rectangular rubber band
- */
-class XGUI_RectRubberBand : public XGUI_AbstractRubberBand
-{
-Q_OBJECT
-
- public:
- XGUI_RectRubberBand(QWidget*);
- virtual ~XGUI_RectRubberBand();
-
- void initGeometry(const QRect&);
- void setStartPoint(const QPoint&);
- void setEndPoint(const QPoint&);
-
- virtual void clearGeometry();
-};
-
-class XGUI_PolyRubberBand : public XGUI_AbstractRubberBand
-{
-Q_OBJECT
-
- public:
- XGUI_PolyRubberBand(QWidget*);
- virtual ~XGUI_PolyRubberBand();
-
- void initGeometry(const QPolygon&);
- void initGeometry(const QPoint&);
-
- void addNode(const QPoint&);
- void replaceLastNode(const QPoint&);
- void removeLastNode();
-
- void setClosed(bool);
-};
-
-#endif
#include "XGUI_SelectionMgr.h"
#include "XGUI_Workshop.h"
-#include "XGUI_MainWindow.h"
#include "XGUI_ObjectsBrowser.h"
#include "XGUI_SalomeConnector.h"
#include "XGUI_ViewerProxy.h"
#include "XGUI_Displayer.h"
#include "XGUI_Selection.h"
+#include <AppElements_MainWindow.h>
+
#include <ModelAPI_Feature.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_AttributeDocRef.h>
return QFileInfo(fPath).completeBaseName();
}
-//******************************************************************
-QString extension(const QString& path, bool full)
-{
- return full ? QFileInfo(path).completeSuffix() : QFileInfo(path).suffix();
-}
-
//******************************************************************
QString addSlash(const QString& path)
{
return res;
}
-//******************************************************************
-QRect makeRect(const int x1, const int y1, const int x2, const int y2)
-{
- return QRect(qMin(x1, x2), qMin(y1, y2), qAbs(x2 - x1), qAbs(y2 - y1));
-}
-
//******************************************************************
bool isModelObject(FeaturePtr theFeature)
{
*/
QString XGUI_EXPORT file(const QString& path, bool withExt = true);
-/*!
- \brief Return extension part of the file path.
-
- \param path file path
- \param full if true complete extension (all extensions, dot separated)
- is returned, otherwise (default) only last extension is returned
- \return extension part of the file path
- */
-QString XGUI_EXPORT extension(const QString& path, bool full = false);
-
/*!
\brief Add a slash (platform-specific) to the end of \a path
if it is not already there.
*/
QString XGUI_EXPORT addSlash(const QString& path);
-/*!
- Creates a rect with TopLeft = ( min(x1,x2), min(y1,y2) )
- and BottomRight = ( TopLeft + (x2-x1)(y2-y1) )
- */
-QRect XGUI_EXPORT makeRect(const int x1, const int y1, const int x2, const int y2);
-
/// The model concerning tools
/*!
+++ /dev/null
-#include "XGUI_ViewBackground.h"
-
-/*!
- \brief Default constructor.
- Creates invalid background data.
- */
-XGUI_ViewBackground::XGUI_ViewBackground()
- : myTextureMode(XGUI::CenterTexture),
- myGradientType(XGUI::NoGradient),
- myTextureShown(false)
-{
- setMode(XGUI::NoBackground);
-}
-
-/*!
- \brief Constructor.
- Creates background data initialized with the specified color
- \param c color
- */
-XGUI_ViewBackground::XGUI_ViewBackground(const QColor& theColor)
- : myTextureMode(XGUI::CenterTexture),
- myGradientType(XGUI::NoGradient),
- myTextureShown(false)
-{
- setColor(theColor);
-}
-
-/*!
- \brief Constructor.
- Creates background data initialized with the specified two-color gradient
- \param type gradient type identifier
- \param c1 first gradient color
- \param c2 second gradient color
- \note the interpretation of the gradient identifier should be done in the calling code
- */
-XGUI_ViewBackground::XGUI_ViewBackground(XGUI::GradientType type, const QColor& c1,
- const QColor& c2)
- : myTextureMode(XGUI::CenterTexture),
- myGradientType(XGUI::NoGradient),
- myTextureShown(false)
-{
- setGradient(type, c1, c2);
-}
-
-/*!
- \brief Constructor.
- Creates background data initialized with the arbirtary gradient data
- \param grad gradient data
- */
-XGUI_ViewBackground::XGUI_ViewBackground(const QGradient& grad)
- : myTextureMode(XGUI::CenterTexture),
- myGradientType(XGUI::NoGradient),
- myTextureShown(false)
-{
- setGradient(grad);
-}
-
-/*!
- \brief Destructor.
- */
-XGUI_ViewBackground::~XGUI_ViewBackground()
-{
-}
-
-/*!
- \brief Compares two background data objects
- */
-bool XGUI_ViewBackground::operator==(const XGUI_ViewBackground& other) const
-{
- return (myMode == other.myMode) && (myTextureMode == other.myTextureMode)
- && (myFileName == other.myFileName) && (myColors == other.myColors)
- && (myGradientType == other.myGradientType) && (myGradient == other.myGradient)
- && (myTextureShown == other.myTextureShown);
-}
-
-/*!
- \brief Returns \c false if background data is not set (invalid)
- \return \c true if background data is valid or \c false otherwise
- \sa mode()
- */
-bool XGUI_ViewBackground::isValid() const
-{
- return myMode != XGUI::NoBackground;
-}
-
-/*!
- \brief Get file name used as a texture image
- \return path to the texture image file
- \sa setTexture(), setTextureShown()
- */
-XGUI::TextureMode XGUI_ViewBackground::texture(QString& fileName) const
-{
- fileName = myFileName;
- return myTextureMode;
-}
-
-/*!
- \brief Set file name to be used as a texture image.
-
- \note To show texture image on the background it is necessary to call additionally
- setTextureShown() method.
-
- \param fileName path to the texture image file name
- \param m texture mode (CenterTexture by default)
- \sa texture(), setTextureShown()
- */
-void XGUI_ViewBackground::setTexture(const QString& fileName, const XGUI::TextureMode m)
-{
- myFileName = fileName;
- myTextureMode = m;
-}
-
-/*!
- \brief Check if "show texture" flag is switched on
- \return \c true if "show texture" flag is set or \c false otherwise
- \sa setTextureShown(), texture()
- */
-bool XGUI_ViewBackground::isTextureShown() const
-{
- return myTextureShown;
-}
-
-/*!
- \brief Specify if texture should be shown on the background or no.
- \param on \c true if texture should be shown or \c false otherwise
- \sa isTextureShown(), texture()
- */
-void XGUI_ViewBackground::setTextureShown(bool on)
-{
- myTextureShown = on;
-}
-
-/*!
- \brief Get background color. Returns null QColor if color is not set
- \return solid background color
- \sa setColor(), mode()
- */
-QColor XGUI_ViewBackground::color() const
-{
- return myColors.count() > 0 ? myColors[0] : QColor();
-}
-
-/*!
- \brief Set background color and switch to the ColorBackground mode
- \param c color
- \sa color(), mode()
- */
-void XGUI_ViewBackground::setColor(const QColor& c)
-{
- myColors.clear();
- myColors << c;
- setMode(XGUI::ColorBackground);
-}
-
-/*!
- \brief Get simple gradient data.
- Returns -1 and null QColor for \a c1 and \a c2 if gradient data is not set
- \param c1 first gradient color is returned via this parameter
- \param c2 second gradient color is returned via this parameter
- \return current two-colored gradient mode type identifier
- \note the interpretation of the gradient identifier should be done in the calling code
- \sa setGradient(int, const QColor&, const QColor&), mode()
- */
-int XGUI_ViewBackground::gradient(QColor& c1, QColor& c2) const
-{
- c1 = myColors.count() > 0 ? myColors[0] : QColor();
- c2 = myColors.count() > 1 ? myColors[1] : (myColors.count() > 0 ? myColors[0] : QColor());
- return myGradientType;
-}
-
-/*!
- \brief Set simple background gradient data and switch to the SimpleGradientBackground mode
- \param type two-colored gradient mode type identifier
- \param c1 first gradient color is returned via this parameter
- \param c2 second gradient color is returned via this parameter
- \note the interpretation of the gradient identifier should be done in the calling code
- \sa gradient(QColor&, QColor&), mode()
- */
-void XGUI_ViewBackground::setGradient(XGUI::GradientType type, const QColor& c1, const QColor& c2)
-{
- myColors.clear();
- myColors << c1 << c2;
- myGradientType = type;
- setMode(XGUI::SimpleGradientBackground);
-}
-
-/*!
- \brief Get complex gradient data.
- Returns QGradient of QGradient::NoGradient if gradient data is not set
- \note This function does not transform simple gradient data set with
- setGradient( const QString&, const QColor&, const QColor& ) to QGradient class
- \return gradient data
- \sa setGradient(const QGradient&), mode()
- */
-const QGradient* XGUI_ViewBackground::gradient() const
-{
- return &myGradient;
-}
-
-/*!
- \brief Set complex background gradient data and switch to the CustomGradientBackground mode
- \param grad gradient data (QLinearGradient, QRadialGradient or QConicalGradient)
- \sa gradient(), mode()
- */
-void XGUI_ViewBackground::setGradient(const QGradient& grad)
-{
- myGradient = grad;
- setMode(XGUI::CustomGradientBackground);
-}
+++ /dev/null
-#ifndef XGUI_ViewBackground_H
-#define XGUI_ViewBackground_H
-
-#include "XGUI.h"
-#include "XGUI_Constants.h"
-
-#include <QColor>
-#include <QGradient>
-#include <QString>
-#include <QCompleter>
-
-typedef QList<QColor> QColorList; //!< list of colors
-
-/*!
- \class XGUI_ViewBackground
- \brief Stores background data
-
- This class is used to store background data. Depending on the mode,
- the background can be specified by:
- - image (by assigning the file name to be used as background texture), see setTexture(), setTextureShown()
- - single color (by assigning any color), see setColor()
- - simple two-color gradient (with the gradient type id and two colors), see setGradient( int, const QColor&, const QColor& )
- - complex gradient (by assigning arbitrary gradient data), see setGradient( const QGradient& )
-
- The class stores all the data passed to it, so switching between different modes can be done
- just by calling setMode() function.
-
- \note Texture is used with combination of the background mode.
-
- \note Two-color gradient is specified by two colors and integer identifier. The interpretation of
- this identifier should be done in the calling code.
-
- \code
- XGUI_ViewBackground bg;
- bg.setColor( QColor(100, 100, 100) ); // bg is switched to ColorBackground mode
- bg.setGradient( Qt::Horizontal, Qt::gray, Qt::white ); // bg is switched to ColorBackground mode
- QLinearGradient grad( 0,0,1,1 );
- grad.setColorAt( 0.0, Qt::gray );
- grad.setColorAt( 0.5, Qt::white );
- grad.setColorAt( 1.0, Qt::green );
- grad.setSpread( QGradient::PadSpread );
- bg.setGradient( grad ); // bg is switched to CustomGradientBackground mode
- bg.setMode( ColorBackground ); // bg is switched back to ColorBackground mode
- bg.setTexture( "/data/images/background.png" ); // specify texture (in the centered mode by default)
- bg.setTextureShown( true ); // draw texture on the solid color background
- \endcode
- */
-class XGUI_EXPORT XGUI_ViewBackground
-{
- public:
- XGUI_ViewBackground();
- XGUI_ViewBackground(const QColor& theColor);
- XGUI_ViewBackground(XGUI::GradientType type, const QColor& theColor1, const QColor& theColor2);
- XGUI_ViewBackground(const QGradient&);
- virtual ~XGUI_ViewBackground();
-
- bool operator==(const XGUI_ViewBackground&) const;
- inline bool operator!=(const XGUI_ViewBackground& other) const
- {
- return !operator==(other);
- }
-
- bool isValid() const;
-
- /*!
- \brief Get background mode
- \return current background mode
- \sa setMode()
- */
- XGUI::BackgroundMode mode() const
- {
- return myMode;
- }
-
- /*!
- \brief Set background mode
- \param m background mode being set
- \sa mode()
- */
- void setMode(const XGUI::BackgroundMode m)
- {
- myMode = m;
- }
-
- XGUI::TextureMode texture(QString&) const;
- void setTexture(const QString&, XGUI::TextureMode = XGUI::CenterTexture);
- bool isTextureShown() const;
- void setTextureShown(bool);
-
- QColor color() const;
- void setColor(const QColor&);
-
- int gradient(QColor&, QColor&) const;
- void setGradient(XGUI::GradientType, const QColor&, const QColor&);
-
- const QGradient* gradient() const;
- void setGradient(const QGradient&);
-
- private:
- XGUI::BackgroundMode myMode;
- XGUI::TextureMode myTextureMode;
- QString myFileName;
- QColorList myColors;
- XGUI::GradientType myGradientType;
- QGradient myGradient;
- bool myTextureShown;
-};
-
-#endif
+++ /dev/null
-#include "XGUI_ViewPort.h"
-#include "XGUI_ViewWindow.h"
-#include "XGUI_Viewer.h"
-#include "XGUI_Constants.h"
-
-#include <QPaintEvent>
-#include <QPainter>
-#include <QFileInfo>
-#include <QApplication>
-
-#include <V3d_OrthographicView.hxx>
-#include <V3d_PerspectiveView.hxx>
-#include <Visual3d_View.hxx>
-#include <Graphic3d_GraphicDriver.hxx>
-
-#ifdef WIN32
-#include <WNT_Window.hxx>
-#else
-#include <Xw_Window.hxx>
-#endif
-
-#include <GL/gl.h>
-
-static double rx = 0.;
-static double ry = 0.;
-static int sx = 0;
-static int sy = 0;
-static Standard_Boolean zRotation = Standard_False;
-
-/*!
- Create native view window for CasCade view [ static ]
- */
-Handle(Aspect_Window) CreateCasWindow(const Handle(V3d_View)& view, WId winId)
-{
- Aspect_Handle aWindowHandle = (Aspect_Handle) winId;
-#ifdef WIN32
- Handle(WNT_Window) viewWindow = new WNT_Window(aWindowHandle);
-#else
- Handle(Aspect_DisplayConnection) aDispConnection = view->Viewer()->Driver()->GetDisplayConnection();
- Handle(Xw_Window) viewWindow = new Xw_Window( aDispConnection, aWindowHandle );
-#endif
- return viewWindow;
-}
-
-//************************************************************************
-//************************************************************************
-//************************************************************************
-XGUI_ViewPort::XGUI_ViewPort(XGUI_ViewWindow* theParent, const Handle(V3d_Viewer)& theViewer,
- V3d_TypeOfView theType)
- : QWidget(theParent),
- myPaintersRedrawing(false),
- myScale(1.0),
- myIsAdvancedZoomingEnabled(false),
- myBgImgHeight(0),
- myBgImgWidth(0)
-{
- setMouseTracking(true);
- setBackgroundRole(QPalette::NoRole);
-
- // set focus policy to threat QContextMenuEvent from keyboard
- setFocusPolicy(Qt::StrongFocus);
- setAttribute(Qt::WA_PaintOnScreen);
- setAttribute(Qt::WA_NoSystemBackground);
- setAutoFillBackground(false);
-
- if (theType == V3d_ORTHOGRAPHIC) {
- myOrthoView = new V3d_OrthographicView(theViewer);
- myActiveView = myOrthoView;
- myPerspView = 0;
- } else {
- myPerspView = new V3d_PerspectiveView(theViewer);
- myActiveView = myPerspView;
- }
- myActiveView->SetSurfaceDetail(V3d_TEX_ALL);
-}
-
-//***********************************************
-XGUI_ViewPort::~XGUI_ViewPort()
-{
-}
-
-//***********************************************
-bool XGUI_ViewPort::mapView(const Handle(V3d_View)& theView)
-{
- if (!setWindow(theView))
- return false;
-
- if (!mapped(theView)) {
- theView->SetWindow(myWindow);
- //if (theView != activeView())
- //theView->View()->Deactivate();
- }
-
- /* create static trihedron (16551: EDF PAL 501) */
- //OCCViewer_ViewWindow* aVW = dynamic_cast<OCCViewer_ViewWindow*>( parentWidget()->parentWidget()->parentWidget() );
- //if ( aVW ) {
- // OCCViewer_Viewer* aViewModel = dynamic_cast<OCCViewer_Viewer*>( aVW->getViewManager()->getViewModel() );
- // if ( aViewModel && aViewModel->isStaticTrihedronDisplayed() ){
- //theView->ZBufferTriedronSetup();
- theView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER);
- // }
- //}
-
- emit(vpMapped());
-
- return true;
-}
-
-//***********************************************
-bool XGUI_ViewPort::setWindow(const Handle(V3d_View)& theView)
-{
- if (!myWindow.IsNull())
- return true;
-
- if (theView.IsNull())
- return false;
-
- attachWindow(theView, CreateCasWindow(theView, winId()));
-
- myWindow = theView->Window();
- return !myWindow.IsNull();
-}
-
-//***********************************************
-bool XGUI_ViewPort::mapped(const Handle(V3d_View)& theView) const
-{
- return (!theView.IsNull() && theView->View()->IsDefined());
-}
-
-//***********************************************
-void XGUI_ViewPort::updateBackground()
-{
- if (activeView().IsNull())
- return;
- if (!myBackground.isValid())
- return;
-
- // VSR: Important note on below code.
- // In OCCT (in version 6.5.2), things about the background drawing
- // are not straightforward and not clearly understandable:
- // - Horizontal gradient is drawn vertically (!), well ok, from top side to bottom one.
- // - Vertical gradient is drawn horizontally (!), from right side to left one (!!!).
- // - First and second diagonal gradients are confused.
- // - Image texture, once set, can not be removed (!).
- // - Texture image fill mode Aspect_FM_NONE is not taken into account (and means the same
- // as Aspect_FM_CENTERED).
- // - The only way to cancel gradient background (and get back to single colored) is to
- // set gradient background style to Aspect_GFM_NONE while passing two colors is also needed
- // (see V3d_View::SetBgGradientColors() function).
- // - Also, it is impossible to draw texture image above the gradiented background (only above
- // single-colored).
- // In OCCT 6.5.3 all above mentioned problems are fixed; so, above comment should be removed as soon
- // as SALOME is migrated to OCCT 6.5.3. The same concerns #ifdef statements in the below code
- switch (myBackground.mode()) {
- case Qtx::ColorBackground: {
- QColor c = myBackground.color();
- if (c.isValid()) {
- // Unset texture should be done here
- // ...
- Quantity_Color qCol(c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB);
- activeView()->SetBgGradientStyle(Aspect_GFM_NONE); // cancel gradient background
- activeView()->SetBgImageStyle(Aspect_FM_NONE); // cancel texture background
- // then change background color
- activeView()->SetBackgroundColor(qCol);
- // update viewer
- activeView()->Update();
- }
- break;
- }
- case Qtx::SimpleGradientBackground: {
- QColor c1, c2;
- int type = myBackground.gradient(c1, c2);
- if (c1.isValid() && type >= XGUI::HorizontalGradient && type <= XGUI::LastGradient) {
- // Unset texture should be done here
- // ...
- // Get colors and set-up gradiented background
- if (!c2.isValid())
- c2 = c1;
- Quantity_Color qCol1(c1.red() / 255., c1.green() / 255., c1.blue() / 255.,
- Quantity_TOC_RGB);
- Quantity_Color qCol2(c2.red() / 255., c2.green() / 255., c2.blue() / 255.,
- Quantity_TOC_RGB);
- activeView()->SetBgImageStyle(Aspect_FM_NONE); // cancel texture background
- switch (type) {
- case XGUI::HorizontalGradient:
- activeView()->SetBgGradientColors(qCol1, qCol2, Aspect_GFM_HOR,
- Standard_True);
- break;
- case XGUI::VerticalGradient:
- activeView()->SetBgGradientColors(qCol1, qCol2, Aspect_GFM_VER,
- Standard_True);
- break;
- case XGUI::Diagonal1Gradient:
- activeView()->SetBgGradientColors(qCol1, qCol2, Aspect_GFM_DIAG1,
- Standard_True);
- break;
- case XGUI::Diagonal2Gradient:
- activeView()->SetBgGradientColors(qCol1, qCol2, Aspect_GFM_DIAG2,
- Standard_True);
- break;
- case XGUI::Corner1Gradient:
- activeView()->SetBgGradientColors(qCol1, qCol2, Aspect_GFM_CORNER1,
- Standard_True);
- break;
- case XGUI::Corner2Gradient:
- activeView()->SetBgGradientColors(qCol1, qCol2, Aspect_GFM_CORNER2,
- Standard_True);
- break;
- case XGUI::Corner3Gradient:
- activeView()->SetBgGradientColors(qCol1, qCol2, Aspect_GFM_CORNER3,
- Standard_True);
- break;
- case XGUI::Corner4Gradient:
- activeView()->SetBgGradientColors(qCol1, qCol2, Aspect_GFM_CORNER4,
- Standard_True);
- break;
- default:
- break;
- }
- }
- break;
- }
- case Qtx::CustomGradientBackground:
- // NOT IMPLEMENTED YET
- break;
- default:
- break;
- }
- // VSR: In OCCT before v6.5.3 below code can't be used because of very ugly bug - it has been impossible to
- // clear the background texture image as soon as it was once set to the viewer.
- if (myBackground.isTextureShown()) {
- QString fileName;
- int textureMode = myBackground.texture(fileName);
- QFileInfo fi(fileName);
- if (!fileName.isEmpty() && fi.exists()) {
- // set texture image: file name and fill mode
- switch (textureMode) {
- case XGUI::CenterTexture:
- activeView()->SetBackgroundImage(fi.absoluteFilePath().toLatin1().constData(),
- Aspect_FM_CENTERED);
- break;
- case XGUI::TileTexture:
- activeView()->SetBackgroundImage(fi.absoluteFilePath().toLatin1().constData(),
- Aspect_FM_TILED);
- break;
- case XGUI::StretchTexture:
- activeView()->SetBackgroundImage(fi.absoluteFilePath().toLatin1().constData(),
- Aspect_FM_STRETCH);
- break;
- default:
- break;
- }
- activeView()->Update();
- }
- }
-}
-
-//***********************************************
-void XGUI_ViewPort::attachWindow(const Handle(V3d_View)& theView,
- const Handle(Aspect_Window)& theWnd)
-{
- if (!theView.IsNull()) {
- theView->SetWindow(theWnd);
- updateBackground();
- }
-}
-
-//***********************************************
-void XGUI_ViewPort::paintEvent(QPaintEvent* theEvent)
-{
-#ifndef WIN32
- /* X11 : map before show doesn't work */
- if ( !mapped( activeView() ) )
- mapView( activeView() );
-#endif
- if (!myWindow.IsNull()) {
- QApplication::syncX();
- QRect rc = theEvent->rect();
- //if ( !myPaintersRedrawing ) {
- //activeView()->Redraw();
- activeView()->Redraw(rc.x(), rc.y(), rc.width(), rc.height());
- emit vpUpdated();
- //}
- }
- //if ( myPaintersRedrawing ) {
- // QPainter p( this );
- // //emit vpDrawExternal( &p );
- // myPaintersRedrawing = false;
- //}
-}
-
-//***********************************************
-void XGUI_ViewPort::resizeEvent(QResizeEvent* theEvent)
-{
-#ifdef WIN32
- /* Win32 : map before first show to avoid flicker */
- if (!mapped(activeView()))
- mapView(activeView());
-#endif
- QApplication::syncX();
- if (!activeView().IsNull()) {
- activeView()->MustBeResized();
- }
- emit resized();
-}
-
-//***********************************************
-QImage XGUI_ViewPort::dumpView(unsigned char*& theData, QRect theRect, bool toUpdate)
-{
- Handle(V3d_View) view = getView();
- if (view.IsNull())
- return QImage();
-
- int aWidth;
- int aHeight;
- if (theRect.isNull()) {
- aWidth = width();
- aHeight = height();
- } else {
- aWidth = theRect.width();
- aHeight = theRect.height();
- }
- QApplication::syncX();
-
- theData = new unsigned char[aWidth * aHeight * 4];
-
- QPoint p;
- if (theRect.isNull()) {
- if (toUpdate)
- view->Redraw();
- p = mapFromParent(geometry().topLeft());
- } else {
- if (toUpdate)
- view->Redraw(theRect.x(), theRect.y(), theRect.width(), theRect.height());
- p = theRect.topLeft();
- }
- glReadPixels(p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, theData);
-
- QImage anImage(theData, aWidth, aHeight, QImage::Format_ARGB32);
- anImage = anImage.mirrored();
- anImage = anImage.rgbSwapped();
- return anImage;
-}
-
-/*!
- Inits 'rotation' transformation.
- */
-void XGUI_ViewPort::startRotation(int x, int y, int theRotationPointType,
- const gp_Pnt& theSelectedPoint)
-{
- if (!activeView().IsNull()) {
- switch (theRotationPointType) {
- case XGUI::GRAVITY:
- activeView()->StartRotation(x, y, 0.45);
- break;
- case XGUI::SELECTED:
- sx = x;
- sy = y;
-
- double X, Y;
- activeView()->Size(X, Y);
- rx = Standard_Real(activeView()->Convert(X));
- ry = Standard_Real(activeView()->Convert(Y));
-
- activeView()->Rotate(0., 0., 0., theSelectedPoint.X(), theSelectedPoint.Y(),
- theSelectedPoint.Z(),
- Standard_True);
-
- Quantity_Ratio zRotationThreshold;
- zRotation = Standard_False;
- zRotationThreshold = 0.45;
- if (zRotationThreshold > 0.) {
- Standard_Real dx = Abs(sx - rx / 2.);
- Standard_Real dy = Abs(sy - ry / 2.);
- Standard_Real dd = zRotationThreshold * (rx + ry) / 2.;
- if (dx > dd || dy > dd)
- zRotation = Standard_True;
- }
- break;
- default:
- break;
- }
- activeView()->DepthFitAll();
- }
-}
-
-/*!
- Rotates the viewport.
- */
-void XGUI_ViewPort::rotate(int x, int y, int theRotationPointType, const gp_Pnt& theSelectedPoint)
-{
- if (!activeView().IsNull()) {
- switch (theRotationPointType) {
- case XGUI::GRAVITY:
- activeView()->Rotation(x, y);
- break;
- case XGUI::SELECTED:
- double dx, dy, dz;
- if (zRotation) {
- dz = atan2(Standard_Real(x) - rx / 2., ry / 2. - Standard_Real(y))
- - atan2(sx - rx / 2., ry / 2. - sy);
- dx = dy = 0.;
- } else {
- dx = (Standard_Real(x) - sx) * M_PI / rx;
- dy = (sy - Standard_Real(y)) * M_PI / ry;
- dz = 0.;
- }
-
- activeView()->Rotate(dx, dy, dz, theSelectedPoint.X(), theSelectedPoint.Y(),
- theSelectedPoint.Z(),
- Standard_False);
- break;
- default:
- break;
- }
- emit vpTransformed();
- }
- // setZSize( getZSize() );
-}
-
-/*!
- Resets the viewport after 'rotation'.
- */
-void XGUI_ViewPort::endRotation()
-{
- if (!activeView().IsNull()) {
- activeView()->ZFitAll(1.);
- activeView()->SetZSize(0.);
- activeView()->Update();
- emit vpTransformed();
- }
-}
-
-/*!
- Inits 'zoom' transformation.
- */
-void XGUI_ViewPort::startZoomAtPoint(int x, int y)
-{
- if (!activeView().IsNull()/* && isAdvancedZoomingEnabled() */)
- activeView()->StartZoomAtPoint(x, y);
-}
-
-/*!
- Centers the viewport.
- */
-void XGUI_ViewPort::setCenter(int x, int y)
-{
- if (!activeView().IsNull()) {
- activeView()->Place(x, y, myScale);
- emit vpTransformed();
- }
-}
-
-/*!
- Called at 'pan' transformation.
- */
-void XGUI_ViewPort::pan(int dx, int dy)
-{
- if (!activeView().IsNull()) {
- activeView()->Pan(dx, dy, 1.0);
- emit vpTransformed();
- }
-}
-
-/*!
- Called at 'window fit' transformation.
- */
-void XGUI_ViewPort::fitRect(const QRect& rect)
-{
- if (!activeView().IsNull()) {
- activeView()->WindowFit(rect.left(), rect.top(), rect.right(), rect.bottom());
- emit vpTransformed();
- }
-}
-
-/*!
- Called at 'zoom' transformation.
- */
-void XGUI_ViewPort::zoom(int x0, int y0, int x, int y)
-{
- if (!activeView().IsNull()) {
- if (isAdvancedZoomingEnabled())
- activeView()->ZoomAtPoint(x0, y0, x, y);
- else
- activeView()->Zoom(x0 + y0, 0, x + y, 0);
- emit vpTransformed();
- }
-}
-
-/*!
- Sets the background data
- */
-void XGUI_ViewPort::setBackground(const Qtx::BackgroundData& bgData)
-{
- if (bgData.isValid()) {
- myBackground = bgData;
- updateBackground();
- emit vpChangeBackground(myBackground);
- }
-}
-
-void XGUI_ViewPort::fitAll(bool theKeepScale, bool theWithZ, bool theUpd)
-{
- if (activeView().IsNull())
- return;
-
- if (theKeepScale)
- myScale = activeView()->Scale();
-
- Standard_Real aMargin = 0.01;
- activeView()->FitAll(aMargin, theWithZ, theUpd);
- activeView()->SetZSize(0.);
- emit vpTransformed();
-}
-
-void XGUI_ViewPort::syncronizeWith(const XGUI_ViewPort* ref)
-{
- Handle(V3d_View) refView = ref->getView();
- Handle(V3d_View) tgtView = getView();
-
- /* The following params are copied:
- - view type( ortho/persp )
- - position of view point
- - orientation of high point
- - position of the eye
- - projection vector
- - view center ( 2D )
- - view twist
- - view scale
- */
-
- /* we'll update after setting all params */
- tgtView->SetImmediateUpdate( Standard_False);
-
- /* perspective */
- if (refView->Type() == V3d_PERSPECTIVE)
- tgtView->SetFocale(refView->Focale());
-
- /* copy params */
- Standard_Real x, y, z;
- refView->At(x, y, z);
- tgtView->SetAt(x, y, z);
- refView->Up(x, y, z);
- tgtView->SetUp(x, y, z);
- refView->Eye(x, y, z);
- tgtView->SetEye(x, y, z);
- refView->Proj(x, y, z);
- tgtView->SetProj(x, y, z);
- refView->Center(x, y);
- tgtView->SetCenter(x, y);
- tgtView->SetScale(refView->Scale());
- tgtView->SetTwist(refView->Twist());
-
- /* update */
- tgtView->Update();
- tgtView->SetImmediateUpdate( Standard_True);
-}
+++ /dev/null
-#ifndef XGUI_ViewPort_H
-#define XGUI_ViewPort_H
-
-#include "XGUI.h"
-
-#include <Qtx.h>
-
-#include <QWidget>
-#include <V3d_Viewer.hxx>
-#include <V3d_View.hxx>
-#include <gp_Pnt.hxx>
-
-class XGUI_ViewWindow;
-
-class XGUI_EXPORT XGUI_ViewPort : public QWidget
-{
-Q_OBJECT
- public:
- XGUI_ViewPort(XGUI_ViewWindow* theParent, const Handle(V3d_Viewer)& theViewer,
- V3d_TypeOfView theType = V3d_ORTHOGRAPHIC);
- virtual ~XGUI_ViewPort();
-
- virtual QPaintEngine* paintEngine() const
- {
- return 0;
- }
-
- QImage dumpView(unsigned char*& theData, QRect theRect = QRect(), bool toUpdate = true);
-
- Handle(V3d_View) getView() const
- {
- return activeView();
- }
-
- void startRotation(int x, int y, int theRotationPointType, const gp_Pnt& theSelectedPoint);
- void rotate(int, int, int, const gp_Pnt&);
- void endRotation();
-
- // TRANSFORMATIONS
- void pan(int dx, int dy);
- void setCenter(int x, int y);
- void fitRect(const QRect& rect);
- void startZoomAtPoint(int x, int y);
- void zoom(int x0, int y0, int x, int y);
- void fitAll(bool theKeepScale = false, bool theWithZ = true, bool theUpd = true);
-
- void setAdvancedZoomingEnabled(const bool theState)
- {
- myIsAdvancedZoomingEnabled = theState;
- }
- bool isAdvancedZoomingEnabled() const
- {
- return myIsAdvancedZoomingEnabled;
- }
-
- Qtx::BackgroundData background() const
- {
- return myBackground;
- }
-
- void setBackground(const Qtx::BackgroundData& bgData);
-
- void syncronizeWith(const XGUI_ViewPort* ref);
-
-signals:
- void vpChangeBackground(const Qtx::BackgroundData&);
- void vpClosed();
- void vpMapped();
- void vpTransformed();
- void vpUpdated();
- void resized();
-
- protected:
- virtual void paintEvent(QPaintEvent*);
- virtual void resizeEvent(QResizeEvent*);
-
- private:
- Handle(V3d_View) activeView() const
- {
- return myActiveView;
- }
-
- bool mapView(const Handle(V3d_View)& theView);
- bool setWindow(const Handle(V3d_View)& theView);
- bool mapped(const Handle(V3d_View)& theView) const;
- void updateBackground();
- void attachWindow(const Handle(V3d_View)& theView, const Handle(Aspect_Window)& theWnd);
-
- Handle(V3d_View) myOrthoView;Handle(V3d_View) myPerspView;Handle(V3d_View) myActiveView;
-
- Handle(Aspect_Window) myWindow;
-
- bool myPaintersRedrawing;
- bool myIsAdvancedZoomingEnabled;
-
- double myScale;
-
- Qtx::BackgroundData myBackground;
- int myBgImgHeight;
- int myBgImgWidth;
-};
-
-#endif
+++ /dev/null
-#include "XGUI_ViewWindow.h"
-#include "XGUI_ViewPort.h"
-#include "XGUI_Viewer.h"
-#include "XGUI_Tools.h"
-#include "XGUI_RubberBand.h"
-
-#include <QLayout>
-#include <QLabel>
-#include <QToolBar>
-#include <QAction>
-#include <QResizeEvent>
-#include <QApplication>
-#include <QMdiArea>
-#include <QMdiSubWindow>
-#include <QPainter>
-#include <QTimer>
-#include <QFileDialog>
-#include <QStyleOptionToolBar>
-
-#include <TopoDS_Shape.hxx>
-#include <BRep_Tool.hxx>
-#include <TopoDS.hxx>
-#include <Visual3d_View.hxx>
-
-#include <math.h>
-
-#define BORDER_SIZE 2
-
-const char* imageZoomCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
- "................................", "................................",
- ".#######........................", "..aaaaaaa.......................",
- "................................", ".............#####..............",
- "...........##.aaaa##............", "..........#.aa.....a#...........",
- ".........#.a.........#..........", ".........#a..........#a.........",
- "........#.a...........#.........", "........#a............#a........",
- "........#a............#a........", "........#a............#a........",
- "........#a............#a........", ".........#...........#.a........",
- ".........#a..........#a.........", ".........##.........#.a.........",
- "........#####.....##.a..........", ".......###aaa#####.aa...........",
- "......###aa...aaaaa.......#.....", ".....###aa................#a....",
- "....###aa.................#a....", "...###aa...............#######..",
- "....#aa.................aa#aaaa.", ".....a....................#a....",
- "..........................#a....", "...........................a....",
- "................................", "................................",
- "................................", "................................" };
-
-const char* imageRotateCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
- "................................", "................................",
- "................................", "................................",
- "........#.......................", ".......#.a......................",
- "......#######...................", ".......#aaaaa#####..............",
- "........#..##.a#aa##........##..", ".........a#.aa..#..a#.....##.aa.",
- ".........#.a.....#...#..##.aa...", ".........#a.......#..###.aa.....",
- "........#.a.......#a..#aa.......", "........#a.........#..#a........",
- "........#a.........#a.#a........", "........#a.........#a.#a........",
- "........#a.........#a.#a........", ".........#.........#a#.a........",
- "........##a........#a#a.........", "......##.a#.......#.#.a.........",
- "....##.aa..##.....##.a..........", "..##.aa.....a#####.aa...........",
- "...aa.........aaa#a.............", "................#.a.............",
- "...............#.a..............", "..............#.a...............",
- "...............a................", "................................",
- "................................", "................................",
- "................................", "................................" };
-
-const char* imageCrossCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
- "................................", "................................",
- "................................", "................................",
- "................................", "................................",
- "................................", "...............#................",
- "...............#a...............", "...............#a...............",
- "...............#a...............", "...............#a...............",
- "...............#a...............", "...............#a...............",
- "...............#a...............", ".......#################........",
- "........aaaaaaa#aaaaaaaaa.......", "...............#a...............",
- "...............#a...............", "...............#a...............",
- "...............#a...............", "...............#a...............",
- "...............#a...............", "...............#a...............",
- "................a...............", "................................",
- "................................", "................................",
- "................................", "................................",
- "................................", "................................" };
-
-ViewerToolbar::ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort)
- : QToolBar(theParent),
- myVPort(thePort),
- myResize(false)
-{
- connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized()));
-}
-
-void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
-{
- //QToolBar::paintEvent(theEvent);
- // Paint background
- QPainter aPainter(this);
- QRect aRect = rect();
- QRect aVPRect = myVPort->rect();
- QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
- QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
-
- QRect aImgRect(
- QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
- unsigned char* aData = 0;
- QImage aImg = myVPort->dumpView(aData, aImgRect, myResize);
- if (!aImg.isNull())
- aPainter.drawImage(aRect, aImg);
- myResize = false;
-
- // Paint foreground
- QStyle *style = this->style();
- QStyleOptionToolBar aOpt;
- initStyleOption(&aOpt);
-
- aOpt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &aOpt, this);
- if (aOpt.rect.isValid())
- style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &aOpt, &aPainter, this);
- if (aData)
- delete aData;
-}
-
-//**************************************************************************
-ViewerLabel::ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort)
- : QLabel(theParent),
- myVPort(thePort),
- myResize(false)
-{
- connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized()));
-}
-
-void ViewerLabel::paintEvent(QPaintEvent* theEvent)
-{
- QRect aRect = rect();
- QRect aVPRect = myVPort->rect();
- QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
- QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
-
- QRect aImgRect(
- QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
- unsigned char* aData = 0;
- QImage aImg = myVPort->dumpView(aData, aImgRect, myResize);
- if (!aImg.isNull())
- QPainter(this).drawImage(aRect, aImg);
- myResize = false;
- QLabel::paintEvent(theEvent);
- if (aData)
- delete aData;
-}
-
-//**************************************************************************
-//**************************************************************************
-//**************************************************************************
-XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
- : QFrame(),
- myViewer(theViewer),
- myMoving(false),
- MinimizeIco(":pictures/wnd_minimize.png"),
- MaximizeIco(":pictures/wnd_maximize.png"),
- CloseIco(":pictures/wnd_close.png"),
- RestoreIco(":pictures/wnd_restore.png"),
- myInteractionStyle(XGUI::STANDARD),
- myRectBand(0),
- myIsKeyFree(false),
- my2dMode(XGUI::No2dMode),
- myCurrPointType(XGUI::GRAVITY),
- myPrevPointType(XGUI::GRAVITY),
- myRotationPointSelection(false),
- myClosable(true),
- myStartX(0),
- myStartY(0),
- myCurrX(0),
- myCurrY(0),
- myCurScale(0.0),
- myCurSketch(0),
- myDrawRect(false),
- myEnableDrawMode(false),
- myCursorIsHand(false),
- myEventStarted(false),
- myIsActive(false),
- myLastState(WindowNormalState),
- myOperation(NOTHING),
- myGripWgt(0),
- myPicture(0)
-{
- mySelectedPoint = gp_Pnt(0., 0., 0.);
- setFrameStyle(QFrame::Raised);
- setFrameShape(QFrame::Panel);
- setLineWidth(BORDER_SIZE);
- setMouseTracking(true);
-
- QVBoxLayout* aLay = new QVBoxLayout(this);
- aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
- myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
- myViewPort->installEventFilter(this);
- myViewPort->setCursor(Qt::ArrowCursor);
- aLay->addWidget(myViewPort);
-
- myPicture = new QLabel(this);
- myPicture->setFrameStyle(QFrame::Sunken);
- myPicture->setFrameShape(QFrame::Panel);
- myPicture->setMouseTracking(true);
- myPicture->installEventFilter(this);
- aLay->addWidget(myPicture);
- myPicture->hide();
-
- QVBoxLayout* aVPLay = new QVBoxLayout(myViewPort);
- aVPLay->setMargin(0);
- aVPLay->setSpacing(0);
- aVPLay->setContentsMargins(0, 0, 0, 0);
-
- QHBoxLayout* aToolLay = new QHBoxLayout();
- aToolLay->setMargin(0);
- aToolLay->setSpacing(0);
- aToolLay->setContentsMargins(0, 0, 0, 0);
- aVPLay->addLayout(aToolLay);
- aVPLay->addStretch();
-
- myGripWgt = new ViewerLabel(this, myViewPort);
- myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
- myGripWgt->setMouseTracking(true);
- myGripWgt->installEventFilter(this);
- myGripWgt->setCursor(Qt::OpenHandCursor);
- aToolLay->addWidget(myGripWgt);
-
- // Create Viewer management buttons
- myViewBar = new ViewerToolbar(this, myViewPort);
- myViewBar->setCursor(Qt::PointingHandCursor);
- aToolLay->addWidget(myViewBar);
- aToolLay->addStretch();
-
- QAction* aBtn;
-
- // Dump view
- aBtn = new QAction(QIcon(":pictures/occ_view_camera_dump.png"), tr("Dump view"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(dumpView()));
- myViewBar->addAction(aBtn);
- // Fit all
- aBtn = new QAction(QIcon(":pictures/occ_view_fitall.png"), tr("Fit all"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(fitAll()));
- myViewBar->addAction(aBtn);
- // Fit area
- aBtn = new QAction(QIcon(":pictures/occ_view_fitarea.png"), tr("Fit area"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(activateWindowFit()));
- myViewBar->addAction(aBtn);
- // Zoom
- aBtn = new QAction(QIcon(":pictures/occ_view_zoom.png"), tr("Zoom"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(activateZoom()));
- myViewBar->addAction(aBtn);
- // Pan
- aBtn = new QAction(QIcon(":pictures/occ_view_pan.png"), tr("Panning"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(activatePanning()));
- myViewBar->addAction(aBtn);
- // Global Panning
- aBtn = new QAction(QIcon(":pictures/occ_view_glpan.png"), tr("Global panning"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(activateGlobalPanning()));
- myViewBar->addAction(aBtn);
- // Rotation
- aBtn = new QAction(QIcon(":pictures/occ_view_rotate.png"), tr("Rotate"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(activateRotation()));
- myViewBar->addAction(aBtn);
- // Reset
- aBtn = new QAction(QIcon(":pictures/occ_view_reset.png"), tr("Reset"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(reset()));
- myViewBar->addAction(aBtn);
- // Front view
- aBtn = new QAction(QIcon(":pictures/occ_view_front.png"), tr("Front"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(frontView()));
- myViewBar->addAction(aBtn);
- // Back view
- aBtn = new QAction(QIcon(":pictures/occ_view_back.png"), tr("Back"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(backView()));
- myViewBar->addAction(aBtn);
- // Top view
- aBtn = new QAction(QIcon(":pictures/occ_view_top.png"), tr("Top"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(topView()));
- myViewBar->addAction(aBtn);
- // Bottom view
- aBtn = new QAction(QIcon(":pictures/occ_view_bottom.png"), tr("Bottom"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(bottomView()));
- myViewBar->addAction(aBtn);
- // Left view
- aBtn = new QAction(QIcon(":pictures/occ_view_left.png"), tr("Left"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(leftView()));
- myViewBar->addAction(aBtn);
- // Right view
- aBtn = new QAction(QIcon(":pictures/occ_view_right.png"), tr("Right"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(rightView()));
- myViewBar->addAction(aBtn);
- // Clone view
- aBtn = new QAction(QIcon(":pictures/occ_view_clone.png"), tr("Clone"), myViewBar);
- connect(aBtn, SIGNAL(triggered()), SLOT(cloneView()));
- myViewBar->addAction(aBtn);
-
- // Create Window management buttons
- myWindowBar = new ViewerToolbar(this, myViewPort);
- myWindowBar->setCursor(Qt::PointingHandCursor);
- aToolLay->addWidget(myWindowBar);
-
- myMinimizeBtn = new QAction(myWindowBar);
- myMinimizeBtn->setIcon(MinimizeIco);
- myWindowBar->addAction(myMinimizeBtn);
- connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize()));
-
- myMaximizeBtn = new QAction(myWindowBar);
- myMaximizeBtn->setIcon(MaximizeIco);
- myWindowBar->addAction(myMaximizeBtn);
- connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize()));
-
- aBtn = new QAction(myWindowBar);
- aBtn->setIcon(CloseIco);
- myWindowBar->addAction(aBtn);
- connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
-
- //Support copy of background on updating of viewer
- connect(myViewPort, SIGNAL(vpTransformed()), this, SLOT(updateToolBar()));
- connect(myViewPort, SIGNAL(vpUpdated()), this, SLOT(updateToolBar()));
- connect(this, SIGNAL(vpTransformationFinished(XGUI_ViewWindow::OperationType)), this,
- SLOT(updateToolBar()));
-}
-
-//****************************************************************
-XGUI_ViewWindow::~XGUI_ViewWindow()
-{
-}
-
-//****************************************************************
-void XGUI_ViewWindow::showEvent(QShowEvent* theEvent)
-{
- QFrame::showEvent(theEvent);
- myWindowBar->setFixedSize(myWindowBar->sizeHint());
-}
-
-//****************************************************************
-void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
-{
-
- if (theEvent->type() == QEvent::WindowStateChange) {
- if (isMinimized()) {
- if (myPicture->isHidden()) {
- myViewBar->hide();
- myGripWgt->hide();
- myWindowBar->hide();
- myViewPort->hide();
- myPicture->show();
- }
- } else {
- if (myPicture->isVisible()) {
- myPicture->hide();
- myViewPort->show();
- }
- if (isMaximized()) {
- myMinimizeBtn->setIcon(MinimizeIco);
- myMaximizeBtn->setIcon(RestoreIco);
- }
- myViewBar->setVisible(myIsActive);
- myWindowBar->setVisible(myIsActive);
- myGripWgt->setVisible(myIsActive && (!isMaximized()));
- }
- } else
- QWidget::changeEvent(theEvent);
-}
-
-//****************************************************************
-void XGUI_ViewWindow::windowActivated()
-{
- if (!(isMinimized() || parentWidget()->isMinimized())) {
- myIsActive = true;
- if (isMaximized() || parentWidget()->isMaximized()) {
- myMaximizeBtn->setIcon(RestoreIco);
- } else {
- myMaximizeBtn->setIcon(MaximizeIco);
- }
- myViewBar->show();
- myWindowBar->show();
- myGripWgt->setVisible(
- !(isMaximized() || isMinimized() || parentWidget()->isMaximized()
- || parentWidget()->isMinimized()));
- } else
- myIsActive = false;
-}
-
-//****************************************************************
-void XGUI_ViewWindow::windowDeactivated()
-{
- myIsActive = false;
- if (!(isMinimized() || parentWidget()->isMinimized())) {
- if (isMaximized() || parentWidget()->isMaximized()) {
- myMaximizeBtn->setIcon(RestoreIco);
- } else {
- myMaximizeBtn->setIcon(MaximizeIco);
- }
- myViewBar->hide();
- myWindowBar->hide();
- myGripWgt->hide();
- }
-}
-
-//****************************************************************
-void XGUI_ViewWindow::onClose()
-{
- if (parentWidget()) {
- emit tryClosing(this);
- if (closable()) {
- emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
- parentWidget()->close();
- }
- }
-}
-
-//****************************************************************
-void XGUI_ViewWindow::onMinimize()
-{
- unsigned char* aData = 0;
- QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView(aData));
- int aW = width();
- int aH = height();
- double aR = aW / 100.;
- int aNewH = int(aH / aR);
- myPicture->setPixmap(aPMap.scaled(100, aNewH));
-
- myLastState =
- (isMaximized() || parentWidget()->isMaximized()) ? MaximizedState : WindowNormalState;
- showMinimized();
- parentWidget()->showMinimized();
- parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 100, aNewH);
- parentWidget()->lower();
- windowDeactivated();
- myViewer->onWindowMinimized((QMdiSubWindow*) parentWidget());
- delete aData;
-}
-
-//****************************************************************
-void XGUI_ViewWindow::onMaximize()
-{
- if (isMaximized() || parentWidget()->isMaximized()) {
- myMaximizeBtn->setIcon(MaximizeIco);
- myGripWgt->show();
- showNormal();
- parentWidget()->showNormal();
- } else {
- myMaximizeBtn->setIcon(RestoreIco);
- myGripWgt->hide();
- showMaximized();
- parentWidget()->showMaximized();
- }
- parentWidget()->activateWindow();
- myMinimizeBtn->setIcon(MinimizeIco);
-
- // In order to avoid frosen background in toolbars when it shown as a second view
- QTimer::singleShot(50, parentWidget(), SLOT(setFocus()));
-}
-
-//****************************************************************
-bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
-{
- switch (theEvent->type()) {
- case QEvent::MouseButtonPress: {
- QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
- if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) {
- myMoving = true;
- myMousePnt = aEvent->globalPos();
- return true;
- }
- }
- break;
- case QEvent::MouseButtonRelease: {
- QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
- if ((aEvent->button() == Qt::LeftButton) && myMoving) {
- myMoving = false;
- return true;
- }
- }
- break;
- case QEvent::MouseMove: {
- QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
- if (myMoving) {
- QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
- QMdiArea* aMDIArea = aParent->mdiArea();
-
- QPoint aPnt = aEvent->globalPos();
- QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
- if (aMDIArea->rect().contains(aMDIPnt)) {
- int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
- int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
- aParent->move(aX, aY);
- myMousePnt = aPnt;
- }
- return true;
- }
- }
- break;
- case QEvent::MouseButtonDblClick:
- if (theObj == myPicture) {
- myMoving = false;
- if (myLastState == MaximizedState) {
- showMaximized();
- } else {
- showNormal();
- }
- myViewer->onWindowActivated((QMdiSubWindow*) parentWidget());
-
- // In order to avoid frosen background in toolbars when it shown as a second view
- QTimer::singleShot(20, parentWidget(), SLOT(setFocus()));
-
- return true;
- }
- }
- return false;
-}
-
-//****************************************************************
-bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
-{
- switch (theEvent->type()) {
- case QEvent::MouseButtonPress:
- vpMousePressEvent((QMouseEvent*) theEvent);
- return true;
-
- case QEvent::MouseButtonRelease:
- vpMouseReleaseEvent((QMouseEvent*) theEvent);
- return true;
-
- case QEvent::MouseMove:
- vpMouseMoveEvent((QMouseEvent*) theEvent);
- return true;
-
- case QEvent::MouseButtonDblClick:
- emit mouseDoubleClicked(this, (QMouseEvent*) theEvent);
- return true;
- case QEvent::Wheel: {
- QWheelEvent* aEvent = (QWheelEvent*) theEvent;
- myViewPort->startZoomAtPoint(aEvent->x(), aEvent->y());
- double aDelta = (double) (aEvent->delta()) / (15 * 8);
- int x = aEvent->x();
- int y = aEvent->y();
- int x1 = (int) (aEvent->x() + width() * aDelta / 100);
- int y1 = (int) (aEvent->y() + height() * aDelta / 100);
- myViewPort->zoom(x, y, x1, y1);
- }
- return true;
- }
- return false;
-}
-
-//****************************************************************
-bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
-{
- if ((theObj == myGripWgt) || (theObj == myPicture)) {
- if (processWindowControls(theObj, theEvent))
- return true;
- } else if (theObj == myViewPort) {
- if (processViewPort(theEvent)) {
- return true;
- }
- if (theEvent->type() == QEvent::KeyRelease) {
- emit keyReleased(this, (QKeyEvent*) theEvent);
- return true;
- }
- }
- return QFrame::eventFilter(theObj, theEvent);
-}
-
-//****************************************************************
-XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(
- QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle)
-{
- OperationType aOp = NOTHING;
- XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle) theInteractionStyle;
- if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM])
- && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]))
- aOp = ZOOMVIEW;
- else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN])
- && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]))
- aOp = PANVIEW;
- else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE])
- && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE])
- && (my2dMode == XGUI::No2dMode))
- aOp = ROTATE;
-
- return aOp;
-}
-
-//****************************************************************
-void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
-{
- myStartX = theEvent->x();
- myStartY = theEvent->y();
- XGUI::InteractionStyle anInteractionStyle = interactionStyle();
-
- // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
- // which are assigned for pan and rotate - these operations are activated immediately after pressing
- // of the first button, so it is necessary to switch to zoom when the second button is pressed
- bool aSwitchToZoom = false;
- if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
- aSwitchToZoom = getButtonState(theEvent, anInteractionStyle) == ZOOMVIEW;
- }
-
- switch (myOperation) {
- case WINDOWFIT:
- if (theEvent->button() == Qt::LeftButton)
- emit vpTransformationStarted(WINDOWFIT);
- break;
-
- case PANGLOBAL:
- if (theEvent->button() == Qt::LeftButton)
- emit vpTransformationStarted(PANGLOBAL);
- break;
-
- case ZOOMVIEW:
- if (theEvent->button() == Qt::LeftButton) {
- myViewPort->startZoomAtPoint(myStartX, myStartY);
- emit vpTransformationStarted(ZOOMVIEW);
- }
- break;
-
- case PANVIEW:
- if (aSwitchToZoom) {
- myViewPort->startZoomAtPoint(myStartX, myStartY);
- activateZoom();
- } else if (theEvent->button() == Qt::LeftButton)
- emit vpTransformationStarted(PANVIEW);
- break;
-
- case ROTATE:
- if (aSwitchToZoom) {
- myViewPort->startZoomAtPoint(myStartX, myStartY);
- activateZoom();
- } else if (theEvent->button() == Qt::LeftButton) {
- myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
- emit vpTransformationStarted(ROTATE);
- }
- break;
-
- default:
- /* Try to activate a transformation */
- OperationType aState;
- if (interactionStyle() == XGUI::STANDARD)
- aState = getButtonState(theEvent, anInteractionStyle);
- else {
- aState = XGUI_ViewWindow::NOTHING;
- myIsKeyFree = true;
- }
- switch (aState) {
- case ZOOMVIEW:
- myViewPort->startZoomAtPoint(myStartX, myStartY);
- activateZoom();
- break;
- case PANVIEW:
- activatePanning();
- break;
- case ROTATE:
- activateRotation();
- myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
- break;
- default:
- if (myRotationPointSelection) {
- if (theEvent->button() == Qt::LeftButton) {
- Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
- ic->Select();
- for (ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
- TopoDS_Shape aShape = ic->SelectedShape();
- if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) {
- gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
- /*if ( mySetRotationPointDlg ) {
- myRotationPointSelection = false;
- mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
- }*/
- } else {
- myCurrPointType = myPrevPointType;
- break;
- }
- }
- if (ic->NbSelected() == 0)
- myCurrPointType = myPrevPointType;
- //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
- //ic->CloseAllContexts();
- myOperation = NOTHING;
- myViewPort->setCursor(myCursor);
- myCursorIsHand = false;
- myRotationPointSelection = false;
- }
- } else
- emit mousePressed(this, theEvent);
- break;
- }
- /* notify that we start a transformation */
- if (transformRequested())
- emit vpTransformationStarted(myOperation);
- }
- if (transformRequested())
- setTransformInProcess(true);
-
- /* we may need it for sketching... */
- /* if ( l_mbPressEvent )
- delete l_mbPressEvent;
- l_mbPressEvent = new QMouseEvent( *theEvent );*/
-}
-
-//****************************************************************
-void XGUI_ViewWindow::contextMenuEvent(QContextMenuEvent* theEvent)
-{
- if (theEvent->modifiers() == Qt::NoModifier) {
- // Temporary: has to be removed when viewer popup will be defined
- //QFrame::contextMenuEvent(theEvent);
- emit contextMenuRequested(theEvent);
- }
-}
-
-//****************************************************************
-void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
-{
- switch (myOperation) {
- case NOTHING: {
- int prevState = myCurSketch;
- /* if(theEvent->button() == Qt::RightButton) {
- QList<OCCViewer_ViewSketcher*>::Iterator it;
- for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
- OCCViewer_ViewSketcher* sk = (*it);
- if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
- myCurSketch = -1;
- }
- }
- */
- emit mouseReleased(this, theEvent);
- }
- break;
- case ROTATE:
- myViewPort->endRotation();
- resetState();
- break;
-
- case PANVIEW:
- case ZOOMVIEW:
- resetState();
- break;
-
- case PANGLOBAL:
- if (theEvent->button() == Qt::LeftButton) {
- myViewPort->setCenter(theEvent->x(), theEvent->y());
- myViewPort->getView()->SetScale(myCurScale);
- resetState();
- }
- break;
-
- case WINDOWFIT:
- if (theEvent->button() == Qt::LeftButton) {
- myCurrX = theEvent->x();
- myCurrY = theEvent->y();
- drawRect();
- QRect rect = XGUI_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
- if (!rect.isEmpty())
- myViewPort->fitRect(rect);
- endDrawRect();
- resetState();
- }
- break;
- }
-
- // NOTE: viewer 3D detects a rectangle of selection using this event
- // so we must emit it BEFORE resetting the selection rectangle
- if (theEvent->button() == Qt::LeftButton && myDrawRect) {
- drawRect();
- endDrawRect();
- resetState();
- myViewPort->update();
- }
- /* if ( l_mbPressEvent ) {
- delete l_mbPressEvent;
- l_mbPressEvent = 0;
- }*/
-}
-
-//****************************************************************
-void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
-{
- if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) {
- myIsKeyFree = false;
- switch (getButtonState(theEvent, interactionStyle())) {
- case ZOOMVIEW:
- myViewPort->startZoomAtPoint(myStartX, myStartY);
- activateZoom();
- break;
- case PANVIEW:
- activatePanning();
- break;
- case ROTATE:
- activateRotation();
- myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
- break;
- default:
- break;
- }
- }
-
- myCurrX = theEvent->x();
- myCurrY = theEvent->y();
- switch (myOperation) {
- case ROTATE:
- myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
- break;
-
- case ZOOMVIEW:
- myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
- myStartX = myCurrX;
- myStartY = myCurrY;
- break;
-
- case PANVIEW:
- myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
- myStartX = myCurrX;
- myStartY = myCurrY;
- break;
-
- case PANGLOBAL:
- break;
-
- default:
- if (myRotationPointSelection /*|| isSketcherStyle()*/) {
- emit mouseMoving(this, theEvent);
- } else {
- int aState = theEvent->modifiers();
- int aButton = theEvent->buttons();
- int anInteractionStyle = interactionStyle();
- if (((anInteractionStyle == XGUI::STANDARD) && (aButton == Qt::LeftButton)
- && (aState == Qt::NoModifier || Qt::ShiftModifier))
- || ((anInteractionStyle == XGUI::KEY_FREE) && (aButton == Qt::LeftButton)
- && (aState == Qt::ControlModifier
- || aState == (Qt::ControlModifier | Qt::ShiftModifier)))) {
- myDrawRect = myEnableDrawMode;
- if (myDrawRect) {
- drawRect();
- if (!myCursorIsHand) { // we are going to sketch a rectangle
- QCursor handCursor(Qt::PointingHandCursor);
- myCursorIsHand = true;
- myCursor = cursor();
- myViewPort->setCursor(handCursor);
- }
- }
- emit mouseMoving(this, theEvent);
- } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
- (aButton == Qt::RightButton) &&
- ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
- ( (anInteractionStyle == XGUI::KEY_FREE) &&
- (aButton == Qt::RightButton) &&
- ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
- OCCViewer_ViewSketcher* sketcher = 0;
- QList<OCCViewer_ViewSketcher*>::Iterator it;
- for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
- OCCViewer_ViewSketcher* sk = (*it);
- if( sk->isDefault() && sk->sketchButton() == aButton )
- sketcher = sk;
- }
- if ( sketcher && myCurSketch == -1 ) {
- activateSketching( sketcher->type() );
- if ( mypSketcher ) {
- myCurSketch = mypSketcher->sketchButton();
-
- if ( l_mbPressEvent ) {
- QApplication::sendEvent( getViewPort(), l_mbPressEvent );
- delete l_mbPressEvent;
- l_mbPressEvent = 0;
- }
- QApplication::sendEvent( getViewPort(), theEvent );
- }
- }
- } */else
- emit mouseMoving(this, theEvent);
- }
- }
-}
-
-/*!
- \brief Draw rubber band rectangle.
- */
-void XGUI_ViewWindow::drawRect()
-{
- if (!myRectBand) {
- myRectBand = new XGUI_RectRubberBand(myViewPort);
- }
-
- myRectBand->setUpdatesEnabled(false);
- QRect aRect = XGUI_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
- myRectBand->initGeometry(aRect);
-
- if (!myRectBand->isVisible())
- myRectBand->show();
-
- myRectBand->setUpdatesEnabled(true);
-}
-
-/*!
- \brief Clear rubber band rectangle on the end on the dragging operation.
- */
-void XGUI_ViewWindow::endDrawRect()
-{
- if (myRectBand) {
- myRectBand->clearGeometry();
- myRectBand->hide();
- }
-}
-
-void XGUI_ViewWindow::activateZoom()
-{
- if (!transformRequested() && !myCursorIsHand)
- myCursor = cursor(); /* save old cursor */
-
- if (myOperation != ZOOMVIEW) {
- QPixmap zoomPixmap(imageZoomCursor);
- QCursor zoomCursor(zoomPixmap);
- if (setTransformRequested(ZOOMVIEW))
- myViewPort->setCursor(zoomCursor);
- }
-}
-
-bool XGUI_ViewWindow::transformRequested() const
-{
- return (myOperation != NOTHING);
-}
-
-/*!
- \brief Start delayed viewer operation.
- */
-bool XGUI_ViewWindow::setTransformRequested(OperationType op)
-{
- bool ok = transformEnabled(op);
- myOperation = ok ? op : NOTHING;
- myViewPort->setMouseTracking(myOperation == NOTHING);
- return ok;
-}
-
-/*!
- Set enabled state of transformation (rotate, zoom, etc)
- */
-void XGUI_ViewWindow::setTransformEnabled(const OperationType id, const bool on)
-{
- if (id != NOTHING)
- myStatus.insert(id, on);
-}
-
-/*!
- \return enabled state of transformation (rotate, zoom, etc)
- */
-bool XGUI_ViewWindow::transformEnabled(const OperationType id) const
-{
- return myStatus.contains(id) ? myStatus[id] : true;
-}
-
-/*!
- \brief Start panning operation.
-
- Sets the corresponding cursor for the widget.
- */
-void XGUI_ViewWindow::activatePanning()
-{
- if (!transformRequested() && !myCursorIsHand)
- myCursor = cursor(); // save old cursor
-
- if (myOperation != PANVIEW) {
- QCursor panCursor(Qt::SizeAllCursor);
- if (setTransformRequested(PANVIEW))
- myViewPort->setCursor(panCursor);
- }
-}
-
-/*!
- \brief Start global panning operation
-
- Sets the corresponding cursor for the widget.
- */
-void XGUI_ViewWindow::activateGlobalPanning()
-{
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull()) {
- QPixmap globalPanPixmap(imageCrossCursor);
- QCursor glPanCursor(globalPanPixmap);
- myCurScale = aView3d->Scale();
- aView3d->FitAll(0.01, false);
- myCursor = cursor(); // save old cursor
- myViewPort->fitAll(); // fits view before selecting a new scene center
- if (setTransformRequested(PANGLOBAL))
- myViewPort->setCursor(glPanCursor);
- }
-}
-
-/*!
- \brief Start rotation operation
-
- Sets the corresponding cursor for the widget.
- */
-void XGUI_ViewWindow::activateRotation()
-{
- if (!transformRequested() && !myCursorIsHand)
- myCursor = cursor(); // save old cursor
-
- if (myOperation != ROTATE) {
- QPixmap rotatePixmap(imageRotateCursor);
- QCursor rotCursor(rotatePixmap);
- if (setTransformRequested(ROTATE))
- myViewPort->setCursor(rotCursor);
- }
-}
-
-/*!
- \brief Reset the viewport to its initial state
- ( no transformations in process etc. )
- */
-void XGUI_ViewWindow::resetState()
-{
- myDrawRect = false;
-
- if (myRotationPointSelection) {
- QCursor handCursor(Qt::PointingHandCursor);
- myViewPort->setCursor(handCursor);
- } else {
- if (transformRequested() || myCursorIsHand)
- myViewPort->setCursor(myCursor);
- myCursorIsHand = false;
- }
-
- if (transformRequested())
- emit vpTransformationFinished(myOperation);
-
- setTransformInProcess(false);
- setTransformRequested(NOTHING);
-}
-
-Qtx::BackgroundData XGUI_ViewWindow::background() const
-{
- return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
-}
-
-void XGUI_ViewWindow::setBackground(const Qtx::BackgroundData& theBackground)
-{
- if (myViewPort)
- myViewPort->setBackground(theBackground);
-}
-
-/*!
- \brief Create one more window with same content.
- */
-void XGUI_ViewWindow::cloneView()
-{
- QMdiSubWindow* vw = myViewer->createView();
- XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
- aNewWnd->viewPort()->syncronizeWith(myViewPort);
-
- emit viewCloned(vw);
-
- // In order to avoid frosen background in toolbars when it shown as a second view
- QTimer::singleShot(20, vw, SLOT(setFocus()));
-}
-
-void XGUI_ViewWindow::dumpView()
-{
- QString aFilter(tr("Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps)"));
- QString aSelectedFilter;
- QString aFileName = QFileDialog::getSaveFileName(this, "Save picture", QString(), aFilter,
- &aSelectedFilter);
- if (!aFileName.isNull()) {
- QApplication::setOverrideCursor(Qt::WaitCursor);
- unsigned char* aData = 0;
- QImage aPicture = myViewPort->dumpView(aData);
-
- QString aFmt = XGUI_Tools::extension(aFileName).toUpper();
- if (aFmt.isEmpty())
- aFmt = QString("BMP"); // default format
- else if (aFmt == "JPG")
- aFmt = "JPEG";
-
- Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
- if (aFmt == "PS")
-#ifdef WIN32
- a3dView->Export(_strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
-#else
- a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
-#endif
- else if (aFmt == "EPS")
-#ifdef WIN32
- a3dView->Export(_strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
-#else
- a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
-#endif
- else
- aPicture.save(aFileName, aFmt.toLatin1());
- delete aData;
- QApplication::restoreOverrideCursor();
- }
-}
-
-void XGUI_ViewWindow::fitAll()
-{
- emit vpTransformationStarted(FITALLVIEW);
- myViewPort->fitAll();
- emit vpTransformationFinished(FITALLVIEW);
-}
-
-/*!
- \brief Starts fit operation.
-
- Sets the corresponding cursor for the widget.
- */
-void XGUI_ViewWindow::activateWindowFit()
-{
- if (!transformRequested() && !myCursorIsHand)
- myCursor = cursor(); /* save old cursor */
-
- if (myOperation != WINDOWFIT) {
- QCursor handCursor(Qt::PointingHandCursor);
- if (setTransformRequested(WINDOWFIT)) {
- myViewPort->setCursor(handCursor);
- myCursorIsHand = true;
- }
- }
-}
-
-/*!
- \brief Perform "front view" transformation.
- */
-void XGUI_ViewWindow::frontView()
-{
- emit vpTransformationStarted(FRONTVIEW);
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull())
- aView3d->SetProj(V3d_Xpos);
- myViewPort->fitAll();
- emit vpTransformationFinished(FRONTVIEW);
-}
-
-/*!
- \brief Perform "back view" transformation.
- */
-void XGUI_ViewWindow::backView()
-{
- emit vpTransformationStarted(BACKVIEW);
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull())
- aView3d->SetProj(V3d_Xneg);
- myViewPort->fitAll();
- emit vpTransformationFinished(BACKVIEW);
-}
-
-/*!
- \brief Perform "top view" transformation.
- */
-void XGUI_ViewWindow::topView()
-{
- emit vpTransformationStarted(TOPVIEW);
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull())
- aView3d->SetProj(V3d_Zpos);
- myViewPort->fitAll();
- emit vpTransformationFinished(TOPVIEW);
-}
-
-/*!
- \brief Perform "bottom view" transformation.
- */
-void XGUI_ViewWindow::bottomView()
-{
- emit vpTransformationStarted(BOTTOMVIEW);
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull())
- aView3d->SetProj(V3d_Zneg);
- myViewPort->fitAll();
- emit vpTransformationFinished(BOTTOMVIEW);
-}
-
-/*!
- \brief Perform "left view" transformation.
- */
-void XGUI_ViewWindow::leftView()
-{
- emit vpTransformationStarted(LEFTVIEW);
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull())
- aView3d->SetProj(V3d_Yneg);
- myViewPort->fitAll();
- emit vpTransformationFinished(LEFTVIEW);
-}
-
-/*!
- \brief Perform "right view" transformation.
- */
-void XGUI_ViewWindow::rightView()
-{
- emit vpTransformationStarted(RIGHTVIEW);
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull())
- aView3d->SetProj(V3d_Ypos);
- myViewPort->fitAll();
- emit vpTransformationFinished(RIGHTVIEW);
-}
-
-void XGUI_ViewWindow::reset()
-{
- emit vpTransformationStarted(RESETVIEW);
- bool upd = myViewPort->getView()->SetImmediateUpdate(false);
- myViewPort->getView()->Reset(false);
- myViewPort->fitAll(false, true, false);
- myViewPort->getView()->SetImmediateUpdate(upd);
- myViewPort->getView()->Update();
- emit vpTransformationFinished(RESETVIEW);
-}
-
-void XGUI_ViewWindow::updateToolBar()
-{
- myGripWgt->update();
- myViewBar->update();
- myWindowBar->update();
-}
-
-/*!
- \brief Update state of enable draw mode state.
- */
-void XGUI_ViewWindow::updateEnabledDrawMode()
-{
- myEnableDrawMode = myViewer->isSelectionEnabled() && myViewer->isMultiSelectionEnabled();
-}
-
-Handle(V3d_View) XGUI_ViewWindow::v3dView() const
-{
- return myViewPort->getView();
-}
\ No newline at end of file
+++ /dev/null
-#ifndef XGUI_ViewWindow_H
-#define XGUI_ViewWindow_H
-
-#include "XGUI.h"
-#include "XGUI_Constants.h"
-
-#include <ModuleBase_IViewWindow.h>
-
-#include <Qtx.h>
-
-#include <QFrame>
-#include <QIcon>
-#include <QToolBar>
-#include <QLabel>
-#include <QMap>
-
-//#include <V3d_View.hxx>
-//#include <V3d_Viewer.hxx>
-
-class XGUI_ViewPort;
-class XGUI_Viewer;
-class ViewerToolbar;
-class ViewerLabel;
-class XGUI_RectRubberBand;
-class QMdiSubWindow;
-
-/*!
- \class XGUI_ViewWindow
- \ingroup GUI
- \brief Implements a one view window of 3d viewer object.
- It contains a view port object (drawing area) and toolbars for view camera and window management.
- Also it managements events in view port
- */
-class XGUI_EXPORT XGUI_ViewWindow : public QFrame, public ModuleBase_IViewWindow
-{
-Q_OBJECT
- public:
- //! Types of viewer operations
- enum OperationType
- {
- NOTHING,
- PANVIEW,
- ZOOMVIEW,
- ROTATE,
- PANGLOBAL,
- WINDOWFIT,
- FITALLVIEW,
- RESETVIEW,
- FRONTVIEW,
- BACKVIEW,
- TOPVIEW,
- BOTTOMVIEW,
- LEFTVIEW,
- RIGHTVIEW,
- CLOCKWISEVIEW,
- ANTICLOCKWISEVIEW
- };
-
- XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType);
-
- virtual ~XGUI_ViewWindow();
-
- //! Returns view port object
- XGUI_ViewPort* viewPort() const
- {
- return myViewPort;
- }
-
- //! Retrurns current interaction style
- XGUI::InteractionStyle interactionStyle() const
- {
- return myInteractionStyle;
- }
-
- //! Disable or enable given operation type
- void setTransformEnabled(const OperationType, const bool);
-
- //! Returns true if the given operation type is enabled
- bool transformEnabled(const OperationType) const;
-
- //! Returns View background object
- Qtx::BackgroundData background() const;
-
- //! Sets View background object
- void setBackground(const Qtx::BackgroundData& theBackground);
-
- //! Returns true if the current view window can be closed
- bool closable() const
- {
- return myClosable;
- }
-
- //! Sets the current view window closable or not
- void setClosable(const bool isClosable)
- {
- myClosable = isClosable;
- }
-
- //! Enable/Disable drawing of ribbon line
- void enableDrawMode(bool toEnable)
- {
- myEnableDrawMode = toEnable;
- }
-
- //! Returns true if ribbon line drawing enabled
- bool isDrawModeEnabled() const
- {
- return myEnableDrawMode;
- }
-
- //! Updates drawing mode in the view window
- void updateEnabledDrawMode();
-
- /// Returns OCCT object which contains 3d view object
- virtual Handle(V3d_View) v3dView() const;
-
-signals:
- //! Emited whien view transformation operation is started
- void vpTransformationStarted(XGUI_ViewWindow::OperationType type);
-
- //! Emited whien view transformation operation is finished
- void vpTransformationFinished(XGUI_ViewWindow::OperationType type);
-
- //void Show(QShowEvent *);
- //void Hide(QHideEvent *);
- //void maximized(XGUI_ViewWindow*, bool);
- //void returnedTo3d();
-
- //! Emited before the window closing
- void tryClosing(XGUI_ViewWindow*);
-
- //! Emited when window is closing
- void closed(QMdiSubWindow*);
-
- //! Emited on mouse press in view port
- void mousePressed(XGUI_ViewWindow*, QMouseEvent*);
-
- //! Emited on mouse release in view port
- void mouseReleased(XGUI_ViewWindow*, QMouseEvent*);
-
- //! Emited on mouse double click in view port
- void mouseDoubleClicked(XGUI_ViewWindow*, QMouseEvent*);
-
- //! Emited on mouse moving in view port
- void mouseMoving(XGUI_ViewWindow*, QMouseEvent*);
-
- //! Emited on key press in view port
- void keyPressed(XGUI_ViewWindow*, QKeyEvent*);
-
- //! Emited on key release in view port
- void keyReleased(XGUI_ViewWindow*, QKeyEvent*);
-
- //! Emited on context menu request in view port
- void contextMenuRequested(QContextMenuEvent *e);
-
- //void viewModified(XGUI_ViewWindow*);
- void viewCloned(QMdiSubWindow* theView);
-
- public slots:
- //! Start zooming operation
- void activateZoom();
-
- //! Start rotation operation
- void activateRotation();
-
- //! Start panning operation
- void activatePanning();
-
- //! Start window fit operation
- void activateWindowFit();
-
- //! Start global panning operation
- void activateGlobalPanning();
-
- //! Clone the view window preserving a view point of the current view
- void cloneView();
-
- //! Dump the view window into external file (*.bmp *.png *.jpg *.jpeg *.eps *.ps)
- void dumpView();
-
- //! Fit all command
- void fitAll();
-
- //! Set front view
- void frontView();
-
- //! Set back view
- void backView();
-
- //! Set top view
- void topView();
-
- //! Set bottom view
- void bottomView();
-
- //! Set left view
- void leftView();
-
- //! Set right view
- void rightView();
-
- //! Reset point of view
- void reset();
-
- void windowActivated();
-
- void windowDeactivated();
-
- protected:
- virtual void changeEvent(QEvent* theEvent);
-
- virtual bool eventFilter(QObject *theObj, QEvent *theEvent);
-
- virtual void showEvent(QShowEvent* theEvent);
-
- virtual void contextMenuEvent(QContextMenuEvent* theEvent);
-
- private slots:
- void onClose();
- void onMinimize();
- void onMaximize();
-
- void updateToolBar();
-// void repaintToolBar();
-
- private:
- enum WindowState
- {
- MinimizedState,
- MaximizedState,
- WindowNormalState
- };
-
- bool processWindowControls(QObject *theObj, QEvent *theEvent);
- bool processViewPort(QEvent *theEvent);
-
- void vpMousePressEvent(QMouseEvent* theEvent);
- void vpMouseReleaseEvent(QMouseEvent* theEvent);
- void vpMouseMoveEvent(QMouseEvent* theEvent);
-
- OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle);
-
- void resetState();
- void drawRect();
- void endDrawRect();
-
- bool transformRequested() const;
- bool setTransformRequested(OperationType);
-
- // Transformation is selected and already started
- bool transformInProcess() const
- {
- return myEventStarted;
- }
- void setTransformInProcess(bool bOn)
- {
- myEventStarted = bOn;
- }
-
- private:
- XGUI_Viewer* myViewer;
-
- QLabel* myPicture;
- ViewerLabel* myGripWgt;
- XGUI_ViewPort* myViewPort;
- ViewerToolbar* myViewBar;
- ViewerToolbar* myWindowBar;
- QAction* myMinimizeBtn;
- QAction* myMaximizeBtn;
-
- QIcon MinimizeIco;
- QIcon MaximizeIco;
- QIcon CloseIco;
- QIcon RestoreIco;
-
- bool myMoving;
- QPoint myMousePnt;
-
- WindowState myLastState;
-
- int myStartX;
- int myStartY;
- int myCurrX;
- int myCurrY;
-
- XGUI::InteractionStyle myInteractionStyle;
- OperationType myOperation;
- XGUI::Mode2dType my2dMode;
-
- int myCurSketch;
- bool myDrawRect; // set when a rect is used for selection or magnify
- bool myEnableDrawMode;
- bool myRotationPointSelection;
- bool myCursorIsHand;
- bool myIsKeyFree;
- bool myEventStarted; // set when transformation is in process
- bool myClosable;
- bool myIsActive;
-
- QCursor myCursor;
-
- XGUI::RotationPointType myCurrPointType;
- XGUI::RotationPointType myPrevPointType;
-
- gp_Pnt mySelectedPoint;
-
- XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band
-
- typedef QMap<OperationType, bool> MapOfTransformStatus;
- MapOfTransformStatus myStatus;
-
- double myCurScale;
-};
-
-//******************************************************
-/*!
- \class ViewerToolbar
- \ingroup GUI
- \brief Provides a toolbar widget with treansparent background over OCCT View window
- */
-class ViewerToolbar : public QToolBar
-{
-Q_OBJECT
- public:
- ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort);
-
- protected slots:
- void onViewPortResized()
- {
- myResize = true;
- }
-
- protected:
- virtual void paintEvent(QPaintEvent* theEvent);
-
- private:
- XGUI_ViewPort* myVPort;
- bool myResize;
-};
-
-//******************************************************
-/*!
- \class ViewerToolbar
- \ingroup GUI
- \brief Provides a Label widget with treansparent background over OCCT View window
- */
-class ViewerLabel : public QLabel
-{
-Q_OBJECT
- public:
- ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort);
-
- protected slots:
- void onViewPortResized()
- {
- myResize = true;
- }
-
- protected:
- virtual void paintEvent(QPaintEvent* theEvent);
-
- private:
- XGUI_ViewPort* myVPort;
- bool myResize;
-};
-
-#endif
+++ /dev/null
-#include "XGUI_Viewer.h"
-#include "XGUI_MainWindow.h"
-#include "XGUI_ViewWindow.h"
-#include "XGUI_ViewPort.h"
-#include "XGUI_Preferences.h"
-
-#include <SUIT_ResourceMgr.h>
-
-#include <QMdiArea>
-#include <QMdiSubWindow>
-#include <QApplication>
-#include <QMouseEvent>
-#include <QMenu>
-
-#include <V3d_View.hxx>
-
-#include <Aspect_DisplayConnection.hxx>
-#include <Graphic3d.hxx>
-#include <Graphic3d_GraphicDriver.hxx>
-#include <Geom_Axis2Placement.hxx>
-#include <AIS_Drawer.hxx>
-#include <Prs3d_DatumAspect.hxx>
-#include <Prs3d_LineAspect.hxx>
-#include <V3d_View.hxx>
-#include <Visual3d_View.hxx>
-#include <AIS_ListOfInteractive.hxx>
-#include <AIS_ListIteratorOfListOfInteractive.hxx>
-#include <AIS_Shape.hxx>
-
-#ifdef WIN32
-#include <WNT_Window.hxx>
-#else
-#include <Xw_Window.hxx>
-#endif
-
-XGUI_Viewer::InteractionStyle2StatesMap XGUI_Viewer::myStateMap;
-XGUI_Viewer::InteractionStyle2ButtonsMap XGUI_Viewer::myButtonMap;
-static bool isInitialized = false;
-
-/*!
- Creates viewer 3d [ static ]
- */
-Handle(V3d_Viewer) CreateViewer(const Standard_ExtString name, const Standard_CString displayName,
- const Standard_CString domain, const Standard_Real viewSize,
- const V3d_TypeOfOrientation viewProjection,
- const Standard_Boolean computedMode,
- const Standard_Boolean defaultComputedMode)
-{
- static Handle(Graphic3d_GraphicDriver) aGraphicDriver;
- if (aGraphicDriver.IsNull()) {
- Handle(Aspect_DisplayConnection) aDisplayConnection;
-#ifndef WIN32
- aDisplayConnection = new Aspect_DisplayConnection( displayName );
-#else
- aDisplayConnection = new Aspect_DisplayConnection();
-#endif
- aGraphicDriver = Graphic3d::InitGraphicDriver(aDisplayConnection);
- }
-
- return new V3d_Viewer(aGraphicDriver, name, domain, viewSize, viewProjection, Quantity_NOC_GRAY30,
- V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT, computedMode, defaultComputedMode,
- V3d_TEX_NONE);
-}
-
-// VSR: Uncomment below line to allow texture background support in OCC viewer
-#define OCC_ENABLE_TEXTURED_BACKGROUND
-
-/*!
- Get data for supported background modes: gradient types, identifiers and supported image formats
- */
-QString XGUI_Viewer::backgroundData(QStringList& gradList, QIntList& idList, QIntList& txtList)
-{
- gradList << tr("Horizontal gradient") << tr("Vertical gradient") << tr("First diagonal gradient")
- << tr("Second diagonal gradient") << tr("First corner gradient")
- << tr("Second corner gradient") << tr("Third corner gradient")
- << tr("Fourth corner gradient");
- idList << XGUI::HorizontalGradient << XGUI::VerticalGradient << XGUI::Diagonal1Gradient
- << XGUI::Diagonal2Gradient << XGUI::Corner1Gradient << XGUI::Corner2Gradient
- << XGUI::Corner3Gradient << XGUI::Corner4Gradient;
-#ifdef OCC_ENABLE_TEXTURED_BACKGROUND
- txtList << XGUI::CenterTexture << XGUI::TileTexture << XGUI::StretchTexture;
-#endif
- return tr("Image files (*.bmp *.gif *.pix *.xwd *.rgb *.rs)");
-}
-
-XGUI_Viewer::XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron)
- : QObject(theParent),
- myMainWindow(theParent),
- myPreselectionEnabled(true),
- mySelectionEnabled(true),
- myMultiSelectionEnabled(true),
- myIsRelative(true),
- myInteractionStyle(XGUI::STANDARD),
- myTrihedronSize(100),
- myActiveView(0),
- myWndIdCount(0)
-{
- if (!isInitialized) {
- isInitialized = true;
-
- // standard interaction style
- XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::ZOOM] = Qt::ControlModifier;
- XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::ZOOM] = Qt::LeftButton;
-
- XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::PAN] = Qt::ControlModifier;
- XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::PAN] = Qt::MidButton;
-
- XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::ROTATE] = Qt::ControlModifier;
- XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::ROTATE] = Qt::RightButton;
-
- XGUI_Viewer::myStateMap[XGUI::STANDARD][XGUI::FIT_AREA] = Qt::ControlModifier;
- XGUI_Viewer::myButtonMap[XGUI::STANDARD][XGUI::FIT_AREA] = Qt::RightButton;
-
- // "key free" interaction style
- XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::ZOOM] = Qt::NoModifier;
- XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::ZOOM] = Qt::RightButton;
-
- XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::PAN] = Qt::NoModifier;
- XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::PAN] = Qt::MidButton;
-
- XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::ROTATE] = Qt::NoModifier;
- XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::ROTATE] = Qt::LeftButton;
-
- XGUI_Viewer::myStateMap[XGUI::KEY_FREE][XGUI::FIT_AREA] = Qt::NoModifier; // unused
- XGUI_Viewer::myButtonMap[XGUI::KEY_FREE][XGUI::FIT_AREA] = Qt::NoButton; // unused
- }
-
- // init CasCade viewers
- myV3dViewer = CreateViewer(TCollection_ExtendedString("Viewer3d").ToExtString(), "", "", 1000.0,
- V3d_XposYnegZpos, Standard_True, Standard_True);
- myV3dViewer->SetDefaultLights();
-
- // init selector
- myAISContext = new AIS_InteractiveContext(myV3dViewer);
- myAISContext->SelectionColor(Quantity_NOC_WHITE);
-
- // display isoline on planar faces (box for ex.)
- myAISContext->IsoOnPlane(true);
-
- if (DisplayTrihedron) {
- Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
- myTrihedron = new AIS_Trihedron(anAxis);
- myTrihedron->SetInfiniteState( Standard_True);
-
- Quantity_Color Col(193 / 255., 205 / 255., 193 / 255., Quantity_TOC_RGB);
- myTrihedron->SetArrowColor(Col.Name());
- myTrihedron->SetSize(myTrihedronSize);
- Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
- if (drawer->HasDatumAspect()) {
- Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
- daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
- daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
- daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
- }
- }
- // set zooming style to standard
- //myZoomingStyle = 0;
-
- QMdiArea* aMDI = myMainWindow->mdiArea();
- connect(aMDI, SIGNAL(subWindowActivated(QMdiSubWindow*)), this,
- SLOT(onWindowActivated(QMdiSubWindow*)));
-
-}
-
-XGUI_Viewer::~XGUI_Viewer(void)
-{
- myAISContext.Nullify();
- myV3dViewer.Nullify();
-}
-
-QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType)
-{
- // create view frame
- XGUI_ViewWindow* view = new XGUI_ViewWindow(this, theType);
- // get main view window (created by view frame)
- //OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW);
- // initialize main view window
- //initView( vw );
- // set default background for view window
- //vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
- // connect signal from viewport
- //connect(view->viewPort(), SIGNAL(vpClosed()), this, SLOT(onViewClosed()));
- //connect(view->viewPort(), SIGNAL(vpMapped()), this, SLOT(onViewMapped()));
- if (myViews.size() == 0)
- setTrihedronShown(true);
-
- Qtx::BackgroundData aBk = XGUI_Preferences::resourceMgr()->backgroundValue("Viewer",
- "background");
- view->setBackground(aBk);
- view->updateEnabledDrawMode();
-
- QMdiArea* aMDI = myMainWindow->mdiArea();
- QMdiSubWindow* aWnd = aMDI->addSubWindow(view, Qt::FramelessWindowHint);
- addView(aWnd);
- aWnd->setGeometry(0, 0, aMDI->width() / 2, aMDI->height() / 2);
- aWnd->show();
- aWnd->setWindowTitle(QString("Viewer #%1").arg(++myWndIdCount));
- emit viewCreated(view);
- return aWnd;
-}
-
-void XGUI_Viewer::updateFromResources()
-{
- Qtx::BackgroundData aBk = XGUI_Preferences::resourceMgr()->backgroundValue("Viewer",
- "background");
- foreach (QMdiSubWindow* aWnd, myViews)
- {
- XGUI_ViewWindow* aView = dynamic_cast<XGUI_ViewWindow*>(aWnd->widget());
- if (aView)
- aView->setBackground(aBk);
- }
-}
-
-XGUI_ViewWindow* XGUI_Viewer::activeViewWindow() const
-{
- if (myActiveView)
- return dynamic_cast<XGUI_ViewWindow*>(myActiveView->widget());
- return 0;
-}
-
-void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
-{
- theList.Clear();
- for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
- theList.Append(myAISContext->SelectedInteractive());
-}
-
-void XGUI_Viewer::getSelectedShapes(NCollection_List<TopoDS_Shape>& theList)
-{
- Handle(AIS_InteractiveContext) ic = AISContext();
-
- for (ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
- TopoDS_Shape aShape = ic->SelectedShape();
- if (!aShape.IsNull())
- theList.Append(aShape);
- }
-}
-
-void XGUI_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
-{
- AIS_ListIteratorOfListOfInteractive aIt;
- for (aIt.Initialize(theList); aIt.More(); aIt.Next())
- myAISContext->AddOrRemoveSelected(aIt.Value(), false);
- myAISContext->UpdateCurrentViewer();
-}
-
-/*! Sets hot button
- *\param theOper - hot operation
- *\param theState - adding state to state map operations.
- *\param theButton - adding state to button map operations.
- */
-void XGUI_Viewer::setHotButton(XGUI::InteractionStyle theInteractionStyle,
- XGUI::HotOperation theOper, Qt::KeyboardModifiers theState,
- Qt::MouseButtons theButton)
-{
- myStateMap[theInteractionStyle][theOper] = theState;
- myButtonMap[theInteractionStyle][theOper] = theButton;
-}
-
-/*! Gets hot button for operation \a theOper.
- *\param theOper - input hot operation
- *\param theState - output state from state map operations.
- *\param theButton - output state from button map operations.
- */
-void XGUI_Viewer::getHotButton(XGUI::InteractionStyle theInteractionStyle,
- XGUI::HotOperation theOper, Qt::KeyboardModifiers& theState,
- Qt::MouseButtons& theButton)
-{
- theState = myStateMap[theInteractionStyle][theOper];
- theButton = myButtonMap[theInteractionStyle][theOper];
-}
-
-/*!
- Changes visibility of trihedron to opposite
- */
-void XGUI_Viewer::toggleTrihedron()
-{
- setTrihedronShown(!isTrihedronVisible());
-}
-
-/*!
- \return true if trihedron is visible
- */
-bool XGUI_Viewer::isTrihedronVisible() const
-{
- return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed(myTrihedron);
-}
-
-/*!
- Sets visibility state of trihedron
- \param on - new state
- */
-
-void XGUI_Viewer::setTrihedronShown(bool on)
-{
- if (myTrihedron.IsNull())
- return;
-
- if (on) {
- myAISContext->Display(myTrihedron);
- myAISContext->Deactivate(myTrihedron);
- } else {
- myAISContext->Erase(myTrihedron);
- }
-}
-
-/*!
- \return trihedron size
- */
-double XGUI_Viewer::trihedronSize() const
-{
- double sz = 0;
- if (!myTrihedron.IsNull())
- sz = myTrihedron->Size();
- return sz;
-}
-
-/*!
- Changes trihedron size
- \param sz - new size
- */
-void XGUI_Viewer::setTrihedronSize(const double sz, bool isRelative)
-{
- if (myTrihedronSize != sz || isRelative != myIsRelative) {
- myTrihedronSize = sz;
- myIsRelative = isRelative;
- updateTrihedron();
- }
-}
-
-/*!
- * Update the size of the trihedron
- */
-void XGUI_Viewer::updateTrihedron()
-{
- if (myTrihedron.IsNull())
- return;
-
- if (myIsRelative) {
- double newSz, oldSz;
-
- if (computeTrihedronSize(newSz, oldSz))
- myTrihedron->SetSize(newSz);
-
- } else if (myTrihedron->Size() != myTrihedronSize) {
- myTrihedron->SetSize(myTrihedronSize);
- }
-}
-
-/*!
- Get new and current trihedron size corresponding to the current model size
- */
-bool XGUI_Viewer::computeTrihedronSize(double& theNewSize, double& theSize)
-{
- theNewSize = 100;
- theSize = 100;
-
- //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
- Handle(V3d_Viewer) viewer = v3dViewer();
- viewer->InitActiveViews();
- if (!viewer->MoreActiveViews())
- return false;
-
- Handle(V3d_View) view3d = viewer->ActiveView();
- //SRN: END of fix
-
- if (view3d.IsNull())
- return false;
-
- double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
- double aMaxSide;
-
- view3d->View()->MinMaxValues(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
-
- if (Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() || Xmax == RealLast()
- || Ymax == RealLast() || Zmax == RealLast())
- return false;
-
- aMaxSide = Xmax - Xmin;
- if (aMaxSide < Ymax - Ymin)
- aMaxSide = Ymax - Ymin;
- if (aMaxSide < Zmax - Zmin)
- aMaxSide = Zmax - Zmin;
-
- // IPAL21687
- // The boundary box of the view may be initialized but nullified
- // (case of infinite objects)
- if (aMaxSide < Precision::Confusion())
- return false;
-
- static float EPS = (float) 5.0E-3;
- theSize = trihedron()->Size();
- //theNewSize = aMaxSide*aSizeInPercents / 100.0;
-
- return fabs(theNewSize - theSize) > theSize * EPS || fabs(theNewSize - theSize) > theNewSize * EPS;
-}
-
-void XGUI_Viewer::onViewClosed(QMdiSubWindow* theView)
-{
- if (!theView)
- return;
-
- emit deleteView(static_cast<XGUI_ViewWindow*>(theView->widget()));
- removeView(theView);
-
- // if this is last view
- if (myViews.size() == 0) {
- Standard_Integer aViewsNb = 0;
- for (myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews();
- myV3dViewer->NextActiveViews())
- ++aViewsNb;
- if (aViewsNb < 2) {
- //clean up presentations before last view is closed
- myAISContext->RemoveAll(Standard_False);
- }
- }
-}
-
-/*!Remove view window \a theView from view manager.
- *And close the last view, if it has \a theView.
- */
-void XGUI_Viewer::removeView(QMdiSubWindow* theView)
-{
- XGUI_ViewWindow* aWindow = static_cast<XGUI_ViewWindow*>(theView->widget());
-
- aWindow->disconnect(this);
- myViews.removeAt(myViews.indexOf(theView));
- if (myActiveView == theView)
- myActiveView = 0;
- if (myViews.size() == 0)
- emit lastViewClosed();
-}
-
-/*void XGUI_Viewer::onViewMapped()
- {
- setTrihedronShown(true);
- }*/
-
-void XGUI_Viewer::addView(QMdiSubWindow* theView)
-{
- XGUI_ViewWindow* aWindow = dynamic_cast<XGUI_ViewWindow*>(theView->widget());
-
- connect(aWindow, SIGNAL(closed(QMdiSubWindow*)), this, SLOT(onViewClosed(QMdiSubWindow*)));
-
- connect(aWindow, SIGNAL(tryClosing(XGUI_ViewWindow*)), this,
- SIGNAL(tryCloseView(XGUI_ViewWindow*)));
-
- connect(aWindow, SIGNAL(mousePressed(XGUI_ViewWindow*, QMouseEvent*)), this,
- SLOT(onMousePressed(XGUI_ViewWindow*, QMouseEvent*)));
-
- connect(aWindow, SIGNAL(mouseDoubleClicked(XGUI_ViewWindow*, QMouseEvent*)), this,
- SIGNAL(mouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)));
-
- connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)), this,
- SIGNAL(mouseMove(XGUI_ViewWindow*, QMouseEvent*)));
-
- connect(aWindow, SIGNAL(keyPressed(XGUI_ViewWindow*, QKeyEvent*)), this,
- SIGNAL(keyPress(XGUI_ViewWindow*, QKeyEvent*)));
-
- connect(aWindow, SIGNAL(keyReleased(XGUI_ViewWindow*, QKeyEvent*)), this,
- SLOT(onKeyRelease(XGUI_ViewWindow*, QKeyEvent*)));
-
- //connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )),
- // this, SLOT (onContextMenuRequested( QContextMenuEvent* )));
- connect(aWindow, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
- SIGNAL(contextMenuRequested(QContextMenuEvent*)));
-
- connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)), this,
- SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
-
- connect(aWindow, SIGNAL(mouseReleased(XGUI_ViewWindow*, QMouseEvent*)), this,
- SLOT(onMouseReleased(XGUI_ViewWindow*, QMouseEvent*)));
-
- myViews.append(theView);
-}
-
-/*!
- Emit activated for view \a view.
- */
-void XGUI_Viewer::onWindowActivated(QMdiSubWindow* view)
-{
- if (view && (view != myActiveView) && (!view->isMinimized())) {
- myActiveView = view;
- ((XGUI_ViewWindow*) myActiveView->widget())->windowActivated();
- QList<QMdiSubWindow*>::iterator aIt;
- for (aIt = myViews.begin(); aIt != myViews.end(); ++aIt) {
- if ((*aIt) != myActiveView) {
- ((XGUI_ViewWindow*) (*aIt)->widget())->windowDeactivated();
- }
- }
- }
-}
-
-void XGUI_Viewer::onWindowMinimized(QMdiSubWindow* theWnd)
-{
- if (myActiveView == theWnd) {
- myActiveView = 0;
- QList<QMdiSubWindow*>::iterator aIt;
- for (aIt = myViews.begin(); aIt != myViews.end(); ++aIt) {
- if (!(*aIt)->widget()->isMinimized()) {
- (*aIt)->raise();
- onWindowActivated(*aIt);
- break;
- }
- }
- }
-}
-
-/*!
- SLOT: called on mouse button press, stores current mouse position as start point for transformations
- */
-void XGUI_Viewer::onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
-{
- myStartPnt.setX(theEvent->x());
- myStartPnt.setY(theEvent->y());
- emit mousePress(theWindow, theEvent);
-}
-
-/*!
- SLOT: called on mouse move, processes hilighting
- */
-void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
-{
- myCurPnt.setX(theEvent->x());
- myCurPnt.setY(theEvent->y());
- if (!mySelectionEnabled)
- return;
-
- Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
- if (!aView3d.IsNull()) {
- myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
- if (myAISContext->HasDetected())
- theWindow->viewPort()->setFocus(Qt::MouseFocusReason);
- }
-}
-
-/*!
- SLOT: called on mouse button release, finishes selection
- */
-void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
-{
- if (!mySelectionEnabled || theEvent->button() != Qt::LeftButton) {
- emit mouseRelease(theWindow, theEvent);
- return;
- }
-
- myEndPnt.setX(theEvent->x());
- myEndPnt.setY(theEvent->y());
- bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
-
- //if (!aHasShift)
- // emit deselection();
-
- if (myStartPnt == myEndPnt) {
- // the MoveTo is necessary for the second click in the same point. Otherwise the selection is lost.
- //Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
- //if (!aView3d.IsNull()) {
- // myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
- //}
- if (aHasShift && myMultiSelectionEnabled)
- myAISContext->ShiftSelect();
- else
- myAISContext->Select();
- } else {
- if (aHasShift && myMultiSelectionEnabled)
- myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(), myEndPnt.x(), myEndPnt.y(),
- theWindow->viewPort()->getView(), false);
- else
- myAISContext->Select(myStartPnt.x(), myStartPnt.y(), myEndPnt.x(), myEndPnt.y(),
- theWindow->viewPort()->getView(), false);
-
- int Nb = myAISContext->NbSelected();
- if (Nb > 1 && !myMultiSelectionEnabled) {
- myAISContext->InitSelected();
- Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
- if (!anOwner.IsNull()) {
- myAISContext->ClearSelected( Standard_False);
- myAISContext->AddOrRemoveSelected(anOwner, Standard_False);
- }
- }
-
- myAISContext->UpdateCurrentViewer();
- }
- emit mouseRelease(theWindow, theEvent);
- emit selectionChanged();
-}
-
-//******************************************************
-void XGUI_Viewer::setMultiSelectionEnabled(bool toEnable)
-{
- myMultiSelectionEnabled = toEnable;
- updateViewsDrawMode();
-}
-
-//******************************************************
-void XGUI_Viewer::setSelectionEnabled(bool toEnable)
-{
- mySelectionEnabled = toEnable;
- updateViewsDrawMode();
-}
-
-//******************************************************
-void XGUI_Viewer::updateViewsDrawMode() const
-{
- foreach(QMdiSubWindow* aWnd, myViews)
- {
- XGUI_ViewWindow* aView = static_cast<XGUI_ViewWindow*>(aWnd->widget());
- aView->updateEnabledDrawMode();
- }
-}
-
-//******************************************************
-void XGUI_Viewer::onKeyRelease(XGUI_ViewWindow* theView, QKeyEvent* theKey)
-{
- Handle(V3d_View) aView = theView->viewPort()->getView();
- bool noModifiers = (theKey->modifiers() == Qt::NoModifier);
- if ((theKey->key() == Qt::Key_N) && noModifiers) {
- myAISContext->HilightNextDetected(aView);
- } else if ((theKey->key() == Qt::Key_P) && noModifiers) {
- myAISContext->HilightPreviousDetected(aView);
- } else {
- emit keyRelease(theView, theKey);
- }
-}
-
-//******************************************************
-//void XGUI_Viewer::onContextMenuRequested(QContextMenuEvent* theEvent)
-//{
-// XGUI_ViewWindow* aWnd = dynamic_cast<XGUI_ViewWindow*>(sender());
-// if (!aWnd) return;
-//
-// QMenu aMenu;
-//
-// // Include Viewer actions
-// if (myActions.size() > 0) {
-// aMenu.addActions(myActions);
-// aMenu.addSeparator();
-// }
-// if (aWnd->actions().size() > 0) {
-// aMenu.addActions(aWnd->actions());
-// aMenu.addSeparator();
-// }
-//
-// QMdiArea* aMDI = myMainWindow->mdiArea();
-// if (aMenu.actions().size() > 0) {
-// QMenu* aSubMenu = aMenu.addMenu(tr("Windows"));
-// aSubMenu->addActions(aMDI->actions());
-// } else {
-// aMenu.addActions(aMDI->actions());
-// }
-// aMenu.exec(theEvent->globalPos());
-//}
+++ /dev/null
-#ifndef XGUI_Viewer_H
-#define XGUI_Viewer_H
-
-#include "XGUI.h"
-#include "XGUI_Constants.h"
-#include <ModuleBase_Definitions.h>
-
-#include <QObject>
-#include <QMap>
-#include <QList>
-#include <QPoint>
-#include <QAction>
-
-#include <V3d_Viewer.hxx>
-#include <AIS_InteractiveContext.hxx>
-#include <AIS_Trihedron.hxx>
-#include <NCollection_List.hxx>
-#include <TopoDS_Shape.hxx>
-
-class XGUI_MainWindow;
-class QMdiSubWindow;
-class XGUI_ViewWindow;
-class QMouseEvent;
-class QKeyEvent;
-
-class AIS_ListOfInteractive;
-
-/**\class XGUI_Viewer
- * \ingroup GUI
- * \brief Represents a 3d viewer. The viewer manages 3d scene and a set of view windows
- * when each of view window is a one point of view on this scene.
- */
-class XGUI_EXPORT XGUI_Viewer : public QObject
-{
-Q_OBJECT
- public:
- static QString backgroundData(QStringList&, QIntList&, QIntList&);
-
- XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true);
- ~XGUI_Viewer();
-
- //! Creates a new view window
- QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC);
-
- //! Return pointer on a main window - parent of the Viewer
- XGUI_MainWindow* mainWindow() const
- {
- return myMainWindow;
- }
-
- //! Returns OCCT object which manages 3d scene
- Handle(V3d_Viewer) v3dViewer() const
- {
- return myV3dViewer;
- }
-
- //! Returns OCCT object which manages displaying and selection in 3d scene
- Handle(AIS_InteractiveContext) AISContext() const
- {
- return myAISContext;
- }
-
- //! Returns an active view window or NULL
- XGUI_ViewWindow* activeViewWindow() const;
-
- /// Return objects selected in 3D viewer
- /// \param theList - list to be filled with selected objects
- void getSelectedObjects(AIS_ListOfInteractive& theList);
-
- /// Return shapes selected in 3D viewer
- /// \param theList - list to be filled with selected shapes
- void getSelectedShapes(NCollection_List<TopoDS_Shape>& theList);
-
- /// Selects objects in 3D viewer. Other selected objects are left as selected
- /// \param theList - list objects to be selected
- void setObjectsSelected(const AIS_ListOfInteractive& theList);
-
- /// Returns true if selection in the viewer is enabled
- bool isSelectionEnabled() const
- {
- return mySelectionEnabled;
- }
-
- /// Enable or disable selectioon in the viewer
- // \param toEnable - true or false (enable or disable selection)
- void setSelectionEnabled(bool toEnable);
-
- /// Returns true if multi-selection in the viewer is enabled
- bool isMultiSelectionEnabled() const
- {
- return myMultiSelectionEnabled;
- }
-
- /// Enable or disable selectioon in the viewer
- // \param toEnable - true or false (enable or disable selection)
- void setMultiSelectionEnabled(bool toEnable);
-
- /// Select the object in 3D viewer.
- /// \param theIO - list objects to be selected
- void setSelected(const Handle(AIS_InteractiveObject)& theIO)
- {
- myAISContext->SetSelected(theIO);
- }
-
- //! Trihedron 3d object shown in the viewer
- Handle(AIS_Trihedron) trihedron() const
- {
- return myTrihedron;
- }
-
- //! On/Off visibility of the trihedron object
- void toggleTrihedron();
-
- //! Returns true if trihedron is visible
- bool isTrihedronVisible() const;
-
- //! Returns true if trihedron is visible
- void setTrihedronShown(bool on);
-
- //! Returns trihedron size
- double trihedronSize() const;
-
- //! Sets trihedron size
- void setTrihedronSize(const double sz, bool isRelative);
-
- bool trihedronRelative() const
- {
- return myIsRelative;
- }
- //! Update trihedron
- void updateTrihedron();
-
- //! Compute trihedron size dependent on 3d scene size
- bool computeTrihedronSize(double& theNewSize, double& theSize);
-
- //! Add action to the viewer
- void addAction(QAction* theAction)
- {
- myActions.append(theAction);
- }
-
- void updateFromResources();
-
- static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
- Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
- static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
- Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
-
- typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
- typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
-
- typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
- typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
-
- static InteractionStyle2StatesMap myStateMap;
- static InteractionStyle2ButtonsMap myButtonMap;
-
-signals:
- void lastViewClosed();
- void tryCloseView(XGUI_ViewWindow* theWindow);
- void deleteView(XGUI_ViewWindow* theWindow);
- void viewCreated(XGUI_ViewWindow* theWindow);
- void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
- void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
- void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
- void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
- void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
- void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
- void activated(XGUI_ViewWindow* theWindow);
- void selectionChanged();
-
- void contextMenuRequested(QContextMenuEvent*);
-
- public slots:
- void onWindowMinimized(QMdiSubWindow*);
- void onWindowActivated(QMdiSubWindow*);
-
- private slots:
- void onViewClosed(QMdiSubWindow*);
- void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
- void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
- void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
- //void onContextMenuRequested(QContextMenuEvent* theEvent);
-
- void onKeyRelease(XGUI_ViewWindow* theView, QKeyEvent* theKey);
-
- private:
- void addView(QMdiSubWindow* theView);
-
- /*! Removes the View from internal Views list.*/
- void removeView(QMdiSubWindow* theView);
-
- void updateViewsDrawMode() const;
-
- private:
- XGUI_MainWindow* myMainWindow;
-
- Handle(V3d_Viewer) myV3dViewer;
- Handle(AIS_Trihedron) myTrihedron;
- Handle(AIS_InteractiveContext) myAISContext;
-
- XGUI::InteractionStyle myInteractionStyle;
-
- bool myPreselectionEnabled;
- bool mySelectionEnabled;
- bool myMultiSelectionEnabled;
- bool myIsRelative;
-
- double myTrihedronSize;
-
- QList<QMdiSubWindow*> myViews;
-
- QMdiSubWindow* myActiveView;
-
- /// Points used for selection management
- QPoint myStartPnt, myEndPnt, myCurPnt;
-
- /// A counter of created windows
- int myWndIdCount;
-
- /// List of Viewer actions
- QList<QAction*> myActions;
-};
-
-#endif
#include "XGUI_ViewerProxy.h"
#include "XGUI_Workshop.h"
-#include "XGUI_MainWindow.h"
-#include "XGUI_ViewPort.h"
-#include "XGUI_ViewWindow.h"
-#include "XGUI_Viewer.h"
#include "XGUI_SalomeConnector.h"
#include "XGUI_Displayer.h"
+#include <AppElements_MainWindow.h>
+#include <AppElements_ViewPort.h>
+#include <AppElements_ViewWindow.h>
+#include <AppElements_Viewer.h>
+
XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
: ModuleBase_IViewer(theParent),
myWorkshop(theParent)
if (myWorkshop->isSalomeMode()) {
return myWorkshop->salomeConnector()->viewer()->activeView();
} else {
- XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+ AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
return (aViewer->activeViewWindow()) ? aViewer->activeViewWindow()->viewPort()->getView() :
Handle(V3d_View)();
}
if (myWorkshop->isSalomeMode()) {
myWorkshop->salomeConnector()->viewer()->fitAll();
} else {
- XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+ AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
if (aViewer->activeViewWindow())
aViewer->activeViewWindow()->viewPort()->fitAll();
}
SIGNAL(contextMenuRequested(QContextMenuEvent*)));
} else {
- XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+ AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
- connect(aViewer, SIGNAL(tryCloseView(XGUI_ViewWindow*)),
- this, SLOT(onTryCloseView(XGUI_ViewWindow*)));
+ connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
+ this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
- connect(aViewer, SIGNAL(deleteView(XGUI_ViewWindow*)),
- this, SLOT(onDeleteView(XGUI_ViewWindow*)));
+ connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
+ this, SLOT(onDeleteView(AppElements_ViewWindow*)));
- connect(aViewer, SIGNAL(viewCreated(XGUI_ViewWindow*)),
- this, SLOT(onViewCreated(XGUI_ViewWindow*)));
+ connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
+ this, SLOT(onViewCreated(AppElements_ViewWindow*)));
- connect(aViewer, SIGNAL(activated(XGUI_ViewWindow*)),
- this, SLOT(onActivated(XGUI_ViewWindow*)));
+ connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
+ this, SLOT(onActivated(AppElements_ViewWindow*)));
- connect(aViewer, SIGNAL(mousePress(XGUI_ViewWindow*, QMouseEvent*)), this,
- SLOT(onMousePress(XGUI_ViewWindow*, QMouseEvent*)));
+ connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
+ SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
- connect(aViewer, SIGNAL(mouseRelease(XGUI_ViewWindow*, QMouseEvent*)), this,
- SLOT(onMouseRelease(XGUI_ViewWindow*, QMouseEvent*)));
+ connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
+ SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
- connect(aViewer, SIGNAL(mouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)), this,
- SLOT(onMouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)));
+ connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
+ SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
- connect(aViewer, SIGNAL(mouseMove(XGUI_ViewWindow*, QMouseEvent*)), this,
- SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
+ connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
+ SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
- connect(aViewer, SIGNAL(keyPress(XGUI_ViewWindow*, QKeyEvent*)), this,
- SLOT(onKeyPress(XGUI_ViewWindow*, QKeyEvent*)));
+ connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
+ SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
- connect(aViewer, SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)), this,
- SLOT(onKeyRelease(XGUI_ViewWindow*, QKeyEvent*)));
+ connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
+ SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
}
-void XGUI_ViewerProxy::onTryCloseView(XGUI_ViewWindow* theWnd)
+void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
{
emit tryCloseView(theWnd);
}
-void XGUI_ViewerProxy::onDeleteView(XGUI_ViewWindow* theWnd)
+void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
{
emit deleteView(theWnd);
}
-void XGUI_ViewerProxy::onViewCreated(XGUI_ViewWindow* theWnd)
+void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
{
emit viewCreated(theWnd);
}
-void XGUI_ViewerProxy::onActivated(XGUI_ViewWindow* theWnd)
+void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
{
emit activated(theWnd);
}
-void XGUI_ViewerProxy::onMousePress(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
+void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
{
emit mousePress(theWnd, theEvent);
}
-void XGUI_ViewerProxy::onMouseRelease(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
+void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
{
emit mouseRelease(theWnd, theEvent);
}
-void XGUI_ViewerProxy::onMouseDoubleClick(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
+void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
{
emit mouseDoubleClick(theWnd, theEvent);
}
-void XGUI_ViewerProxy::onMouseMove(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
+void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
{
emit mouseMove(theWnd, theEvent);
}
-void XGUI_ViewerProxy::onKeyPress(XGUI_ViewWindow* theWnd, QKeyEvent* theEvent)
+void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
{
emit keyPress(theWnd, theEvent);
}
-void XGUI_ViewerProxy::onKeyRelease(XGUI_ViewWindow* theWnd, QKeyEvent* theEvent)
+void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
{
emit keyRelease(theWnd, theEvent);
}
#include <ModuleBase_IViewer.h>
class XGUI_Workshop;
-class XGUI_ViewWindow;
+class AppElements_ViewWindow;
/**
* Proxy class which repersents or XGUI_Viewer or Salome Viewer
virtual void clearSelectionFilters();
private slots:
- void onTryCloseView(XGUI_ViewWindow*);
- void onDeleteView(XGUI_ViewWindow*);
- void onViewCreated(XGUI_ViewWindow*);
- void onActivated(XGUI_ViewWindow*);
-
- void onMousePress(XGUI_ViewWindow*, QMouseEvent*);
- void onMouseRelease(XGUI_ViewWindow*, QMouseEvent*);
- void onMouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*);
- void onMouseMove(XGUI_ViewWindow*, QMouseEvent*);
-
- void onKeyPress(XGUI_ViewWindow*, QKeyEvent*);
- void onKeyRelease(XGUI_ViewWindow*, QKeyEvent*);
+ void onTryCloseView(AppElements_ViewWindow*);
+ void onDeleteView(AppElements_ViewWindow*);
+ void onViewCreated(AppElements_ViewWindow*);
+ void onActivated(AppElements_ViewWindow*);
+
+ void onMousePress(AppElements_ViewWindow*, QMouseEvent*);
+ void onMouseRelease(AppElements_ViewWindow*, QMouseEvent*);
+ void onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*);
+ void onMouseMove(AppElements_ViewWindow*, QMouseEvent*);
+
+ void onKeyPress(AppElements_ViewWindow*, QKeyEvent*);
+ void onKeyRelease(AppElements_ViewWindow*, QKeyEvent*);
private:
XGUI_Workshop* myWorkshop;
+++ /dev/null
-#include "XGUI_Workbench.h"
-#include "XGUI_MenuGroupPanel.h"
-
-#include <QLayout>
-#include <QResizeEvent>
-#include <QPushButton>
-
-#define SCROLL_STEP 20
-
-//**************************************************
-class CommandsArea : public QScrollArea
-{
- public:
- CommandsArea(QWidget* theParent)
- : QScrollArea(theParent)
- {
- }
-
- protected:
- virtual void resizeEvent(QResizeEvent * theEvent);
-};
-
-void CommandsArea::resizeEvent(QResizeEvent* theEvent)
-{
- int x = widget()->x();
- QScrollArea::resizeEvent(theEvent);
- QRect aRect = widget()->childrenRect();
- QSize aNewSize = theEvent->size();
- if (aRect.width() > aNewSize.width())
- aNewSize.setWidth(aRect.width() * 2);
- widget()->resize(aNewSize);
- widget()->move(x, 0);
-}
-
-//**************************************************
-XGUI_Workbench::XGUI_Workbench(QWidget *theParent)
- : QWidget(theParent)
-{
- setMinimumHeight(30);
- QHBoxLayout* aMainLayout = new QHBoxLayout(this);
- aMainLayout->setSpacing(0);
- aMainLayout->setMargin(0);
- aMainLayout->setContentsMargins(0, 0, 0, 0);
-
- myLeftButton = new QPushButton("<", this);
- myLeftButton->setMaximumWidth(14);
- myLeftButton->setVisible(false);
- connect(myLeftButton, SIGNAL(clicked()), this, SLOT(onLeftScroll()));
- aMainLayout->addWidget(myLeftButton);
-
- myCommandsArea = new CommandsArea(this);
- aMainLayout->addWidget(myCommandsArea);
- myCommandsArea->viewport()->installEventFilter(this);
-
- myChildWidget = new QWidget(myCommandsArea);
- myCommandsArea->setWidget(myChildWidget);
- myCommandsArea->setAlignment(Qt::AlignLeft | Qt::AlignTop);
- myCommandsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- myCommandsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-
- myLayout = new QHBoxLayout(myChildWidget);
- myLayout->setSpacing(0);
- myLayout->setMargin(0);
- myLayout->setContentsMargins(0, 0, 0, 0);
-
- myRightButton = new QPushButton(">", this);
- myRightButton->setMaximumWidth(14);
- myRightButton->setVisible(false);
- connect(myRightButton, SIGNAL(clicked()), this, SLOT(onRightScroll()));
- aMainLayout->addWidget(myRightButton);
-
-}
-
-/*
- * Creates a new group in the workbench with given object name.
- */
-XGUI_MenuGroupPanel* XGUI_Workbench::addGroup(const QString& theId)
-{
- if (!myLayout->isEmpty()) {
- int aNb = myLayout->count();
- QLayoutItem* aItem = myLayout->itemAt(aNb - 1);
- myLayout->removeItem(aItem);
- }
- XGUI_MenuGroupPanel* aGroup = new XGUI_MenuGroupPanel(myChildWidget);
- aGroup->setObjectName(theId);
- myLayout->addWidget(aGroup);
- if (theId != "Default") {
- addSeparator();
- }
- myLayout->addStretch();
- myGroups.append(aGroup);
- return aGroup;
-}
-
-/*
- * Searches for already created group with given name.
- */
-XGUI_MenuGroupPanel* XGUI_Workbench::findGroup(const QString& theId)
-{
- XGUI_MenuGroupPanel* aPanel;
- foreach(aPanel, myGroups)
- {
- if (aPanel->objectName() == theId) {
- return aPanel;
- }
- }
- return NULL;
-}
-
-void XGUI_Workbench::addSeparator()
-{
- QFrame* aLine = new QFrame(myChildWidget);
- aLine->setFrameShape(QFrame::VLine);
- aLine->setFrameShadow(QFrame::Sunken);
- myLayout->addWidget(aLine);
-}
-
-void XGUI_Workbench::resizeEvent(QResizeEvent* theEvent)
-{
- QWidget::resizeEvent(theEvent);
- QSize aSize = theEvent->size();
- myLeftButton->setMinimumHeight(aSize.height() - 2);
- myRightButton->setMinimumHeight(aSize.height() - 2);
-
- QSize aS = myChildWidget->sizeHint();
- int aW = myChildWidget->width();
- if (aW < aS.width())
- myChildWidget->resize(aS.width(), myChildWidget->height());
-
- myLeftButton->setVisible(isExceedsLeft());
- myRightButton->setVisible(isExceedsRight());
-}
-
-void XGUI_Workbench::onLeftScroll()
-{
- if (!isExceedsLeft())
- return;
- myChildWidget->move(myChildWidget->pos().x() + SCROLL_STEP, 0);
- myLeftButton->setVisible(isExceedsLeft());
- myRightButton->setVisible(isExceedsRight());
-}
-
-void XGUI_Workbench::onRightScroll()
-{
- if (!isExceedsRight())
- return;
- myChildWidget->move(myChildWidget->pos().x() - SCROLL_STEP, 0);
- myLeftButton->setVisible(isExceedsLeft());
- myRightButton->setVisible(isExceedsRight());
-}
-
-bool XGUI_Workbench::isExceedsLeft()
-{
- QPoint aPos = myChildWidget->pos();
- return (aPos.x() < 0);
-}
-
-bool XGUI_Workbench::isExceedsRight()
-{
- QPoint aPos = myChildWidget->pos();
- int aVPWidth = myCommandsArea->viewport()->rect().width();
- int aWgtWidth = myChildWidget->childrenRect().width();
- return ((aVPWidth - aPos.x()) < aWgtWidth);
-}
-
-bool XGUI_Workbench::eventFilter(QObject *theObj, QEvent *theEvent)
-{
- if (theObj == myCommandsArea->viewport()) {
- if (theEvent->type() == QEvent::Resize) {
- myLeftButton->setVisible(isExceedsLeft());
- myRightButton->setVisible(isExceedsRight());
- }
- }
- return QWidget::eventFilter(theObj, theEvent);
-}
-
-XGUI_Command* XGUI_Workbench::feature(const QString& theId) const
-{
- QList<XGUI_MenuGroupPanel*>::const_iterator aIt;
- for (aIt = myGroups.constBegin(); aIt != myGroups.constEnd(); ++aIt) {
- XGUI_Command* aCmd = (*aIt)->feature(theId);
- if (aCmd)
- return aCmd;
- }
- return 0;
-}
-
-QList<XGUI_Command*> XGUI_Workbench::features() const
-{
- QList<XGUI_Command*> aList;
- foreach (XGUI_MenuGroupPanel* aGroup, myGroups)
- {
- aList.append(aGroup->features());
- }
- return aList;
-}
+++ /dev/null
-#ifndef XGUI_Workbench_H
-#define XGUI_Workbench_H
-
-#include "XGUI.h"
-#include <QWidget>
-#include <QScrollArea>
-#include <QList>
-
-class XGUI_Command;
-class XGUI_MenuGroupPanel;
-class CommandsArea;
-
-class QHBoxLayout;
-class QPushButton;
-
-class XGUI_EXPORT XGUI_Workbench : public QWidget
-{
-Q_OBJECT
- public:
- XGUI_Workbench(QWidget* theParent);
-
- XGUI_MenuGroupPanel* addGroup(const QString& theId);
- XGUI_MenuGroupPanel* findGroup(const QString& theName);
-
- //! Returns already created command by its ID
- XGUI_Command* feature(const QString& theId) const;
-
- //! Returns list of created commands
- QList<XGUI_Command*> features() const;
-
- private slots:
- void onLeftScroll();
- void onRightScroll();
-
- protected:
- virtual void resizeEvent(QResizeEvent * theEvent);
- virtual bool eventFilter(QObject *theObj, QEvent *theEvent);
-
- private:
- void addSeparator();
- bool isExceedsLeft();
- bool isExceedsRight();
-
- QWidget* myChildWidget;
- QHBoxLayout* myLayout;
- QList<XGUI_MenuGroupPanel*> myGroups;
-
- CommandsArea* myCommandsArea;
- QPushButton* myRightButton;
- QPushButton* myLeftButton;
-};
-
-#endif
-#include "ModuleBase_IModule.h"
-#include "XGUI_Constants.h"
-#include "XGUI_Command.h"
-#include "XGUI_MainMenu.h"
-#include "XGUI_MainWindow.h"
-#include "XGUI_MenuGroupPanel.h"
+//#include "XGUI_Constants.h"
#include "XGUI_Tools.h"
-#include "XGUI_Workbench.h"
#include "XGUI_Workshop.h"
-#include "XGUI_Viewer.h"
#include "XGUI_SelectionMgr.h"
#include "XGUI_Selection.h"
#include "XGUI_ObjectsBrowser.h"
#include "XGUI_PropertyPanel.h"
#include "XGUI_ContextMenuMgr.h"
#include "XGUI_ModuleConnector.h"
-#include "XGUI_Preferences.h"
#include <XGUI_QtEvents.h>
+#include <AppElements_Workbench.h>
+#include <AppElements_Viewer.h>
+#include <AppElements_Command.h>
+#include <AppElements_MainMenu.h>
+#include <AppElements_MainWindow.h>
+#include <AppElements_MenuGroupPanel.h>
+
+#include <ModuleBase_IModule.h>
+#include <ModuleBase_Preferences.h>
+
#include <ModelAPI_Events.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_ResultBody.h>
-#include <PartSetPlugin_Part.h>
+//#include <PartSetPlugin_Part.h>
#include <Events_Loop.h>
#include <Events_Error.h>
myUpdatePrefs(false),
myPartActivating(false)
{
- myMainWindow = mySalomeConnector ? 0 : new XGUI_MainWindow();
+ myMainWindow = mySalomeConnector ? 0 : new AppElements_MainWindow();
myDisplayer = new XGUI_Displayer(this);
registerValidators();
// Calling of loadCustomProps before activating module is required
// by Config_PropManger to restore user-defined path to plugins
- XGUI_Preferences::loadCustomProps();
+ ModuleBase_Preferences::loadCustomProps();
activateModule();
if (myMainWindow) {
myMainWindow->show();
return;
}
// File commands group
- XGUI_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
+ AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
- XGUI_Command* aCommand;
+ AppElements_Command* aCommand;
aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
QIcon(":pictures/save.png"), QKeySequence::Save);
}
//******************************************************
-XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
+AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
{
- XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
+ AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
return aMenuBar->addWorkbench(theName);
}
myModule->actionCreated(aAction);
} else {
- XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
- XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
+ AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
+ AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
if (!aPage) {
aPage = addWorkbench(aWchName);
}
//Find or create Group
QString aGroupName = QString::fromStdString(theMessage->groupId());
- XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
+ AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
if (!aGroup) {
aGroup = aPage->addGroup(aGroupName);
}
QKeySequence aHotKey = myActionsMgr->registerShortcut(
QString::fromStdString(theMessage->keysequence()));
// Create feature...
- XGUI_Command* aCommand = aGroup->addFeature(aFeatureId,
+ AppElements_Command* aCommand = aGroup->addFeature(aFeatureId,
QString::fromStdString(theMessage->text()),
QString::fromStdString(theMessage->tooltip()),
QIcon(theMessage->icon().c_str()),
if (isSalomeMode()) {
aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
} else {
- XGUI_MainMenu* aMenu = myMainWindow->menuObject();
+ AppElements_MainMenu* aMenu = myMainWindow->menuObject();
FeaturePtr aFeature = theOperation->feature();
if(aFeature)
aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
//******************************************************
void XGUI_Workshop::onPreferences()
{
- XGUI_Prefs aModif;
- XGUI_Preferences::editPreferences(aModif);
+ ModuleBase_Prefs aModif;
+ ModuleBase_Preferences::editPreferences(aModif);
if (aModif.size() > 0) {
QString aSection;
- foreach (XGUI_Pref aPref, aModif)
+ foreach (ModuleBase_Pref aPref, aModif)
{
aSection = aPref.first;
- if (aSection == XGUI_Preferences::VIEWER_SECTION) {
+ if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
if (!isSalomeMode())
myMainWindow->viewer()->updateFromResources();
- } else if (aSection == XGUI_Preferences::MENU_SECTION) {
+ } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
if (!isSalomeMode())
myMainWindow->menuObject()->updateFromResources();
}
if (isSalomeMode()) { // update commands in SALOME mode
aCommands = salomeConnector()->commandList();
} else {
- XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
- foreach (XGUI_Command* aCmd, aMenuBar->features())
+ AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
+ foreach (AppElements_Command* aCmd, aMenuBar->features())
aCommands.append(aCmd);
}
SessionPtr aMgr = ModelAPI_Session::get();
if (isSalomeMode()) { // update commands in SALOME mode
aCommands = salomeConnector()->commandList();
} else {
- XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
- foreach(XGUI_Command* aCmd, aMenuBar->features())
+ AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
+ foreach(AppElements_Command* aCmd, aMenuBar->features())
{
aCommands.append(aCmd);
}
aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
myPropertyPanel->installEventFilter(myOperationMgr);
- QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
+ QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(PROP_PANEL_OK);
connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
- QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
+ QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(PROP_PANEL_CANCEL);
connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
SLOT(onKeyReleased(QKeyEvent*)));
#define XGUI_WORKSHOP_H
#include "XGUI.h"
-#include "XGUI_Constants.h"
+//#include "XGUI_Constants.h"
#include <Events_Listener.h>
#include <ModuleBase_Definitions.h>
#include <ModelAPI_Document.h>
#include <QKeySequence>
#include <QIcon>
-class XGUI_MainWindow;
-class XGUI_Command;
-class XGUI_Workbench;
+class AppElements_MainWindow;
+class AppElements_Command;
+class AppElements_Workbench;
+
class XGUI_SelectionMgr;
class XGUI_Displayer;
class XGUI_OperationMgr;
void startApplication();
//! Returns main window (Desktop) of the application
- XGUI_MainWindow* mainWindow() const
+ AppElements_MainWindow* mainWindow() const
{
return myMainWindow;
}
}
//! Creates and adds a new workbench (menu group) with the given name and returns it
- XGUI_Workbench* addWorkbench(const QString& theName);
+ AppElements_Workbench* addWorkbench(const QString& theName);
//! Redefinition of Events_Listener method
virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
// Creates Dock widgets: Object browser and Property panel
void createDockWidgets();
- XGUI_MainWindow* myMainWindow;
+ AppElements_MainWindow* myMainWindow;
ModuleBase_IModule* myModule;
XGUI_ObjectsBrowser* myObjectBrowser;
XGUI_PropertyPanel* myPropertyPanel;
<file>pictures/undo.png</file>
<file>pictures/rebuild.png</file>
<file>pictures/preferences.png</file>
-
- <file>pictures/occ_view_back.png</file>
- <file>pictures/occ_view_bottom.png</file>
- <file>pictures/occ_view_camera_dump.png</file>
- <file>pictures/occ_view_clone.png</file>
- <file>pictures/occ_view_fitall.png</file>
- <file>pictures/occ_view_fitarea.png</file>
- <file>pictures/occ_view_front.png</file>
- <file>pictures/occ_view_left.png</file>
- <file>pictures/occ_view_pan.png</file>
- <file>pictures/occ_view_glpan.png</file>
- <file>pictures/occ_view_reset.png</file>
- <file>pictures/occ_view_right.png</file>
- <file>pictures/occ_view_rotate.png</file>
- <file>pictures/occ_view_top.png</file>
- <file>pictures/occ_view_zoom.png</file>
-
- <file>pictures/wnd_close.png</file>
- <file>pictures/wnd_minimize.png</file>
- <file>pictures/wnd_maximize.png</file>
- <file>pictures/wnd_restore.png</file>
- <file>pictures/wnd_grip.png</file>
<file>pictures/params_folder.png</file>
<file>pictures/constr_folder.png</file>
<file>pictures/button_help.png</file>
<file>pictures/button_ok.png</file>
- <file>pictures/cascade_views.png</file>
- <file>pictures/tile_views.png</file>
- <file>pictures/new_view.png</file>
<file>pictures/edit.png</file>
-
<file>pictures/exec_state_failed.png</file>
<file>pictures/exec_state_invalid_parameters.png</file>
-
<file>pictures/assembly.png</file>
<file>pictures/activate.png</file>
<file>pictures/delete.png</file>