From 2a0dd5ede9110d423fbd6b038c0445cb819163a9 Mon Sep 17 00:00:00 2001 From: Sergey Belash Date: Mon, 31 Mar 2014 14:24:42 +0400 Subject: [PATCH] Auto-formatting according to the defined code standard. --- src/Config/Config_FeatureMessage.cpp | 3 +- src/Config/Config_FeatureMessage.h | 90 +- src/Config/Config_FeatureReader.cpp | 23 +- src/Config/Config_ModuleReader.cpp | 8 +- src/Config/Config_XMLReader.cpp | 46 +- src/Config/Config_XMLReader.h | 4 +- src/Event/Event_Listener.cxx | 2 +- src/Event/Event_Listener.hxx | 3 +- src/Event/Event_Loop.cxx | 24 +- src/Event/Event_Loop.hxx | 15 +- src/Event/Event_Message.cxx | 4 +- src/Event/Event_Message.hxx | 35 +- src/Model/Model_Application.cxx | 12 +- src/Model/Model_Application.hxx | 20 +- src/Model/Model_Document.cxx | 138 +-- src/Model/Model_Document.hxx | 5 +- src/Model/Model_PluginManager.cxx | 5 +- src/Model/Model_PluginManager.hxx | 2 +- src/ModelAPI/ModelAPI_Document.hxx | 7 +- src/ModelAPI/ModelAPI_Feature.hxx | 4 +- src/ModelAPI/ModelAPI_Interface.hxx | 19 +- src/ModelAPI/ModelAPI_PluginManager.cxx | 8 +- src/PartSet/PartSet_Message.cpp | 3 +- src/PartSet/PartSet_Module.cpp | 9 +- src/PartSet/PartSet_Module.h | 19 +- src/XGUI/XGUI_Command.cpp | 60 +- src/XGUI/XGUI_Command.h | 28 +- src/XGUI/XGUI_Constants.h | 78 +- src/XGUI/XGUI_Main.cpp | 17 +- src/XGUI/XGUI_MainMenu.cpp | 54 +- src/XGUI/XGUI_MainMenu.h | 19 +- src/XGUI/XGUI_MainWindow.cpp | 317 +++--- src/XGUI/XGUI_MainWindow.h | 48 +- src/XGUI/XGUI_MenuGroupPanel.cpp | 77 +- src/XGUI/XGUI_MenuGroupPanel.h | 34 +- src/XGUI/XGUI_Module.h | 47 +- src/XGUI/XGUI_RubberBand.cpp | 476 ++++---- src/XGUI/XGUI_RubberBand.h | 62 +- src/XGUI/XGUI_Tools.cpp | 60 +- src/XGUI/XGUI_Tools.h | 90 +- src/XGUI/XGUI_ViewBackground.cpp | 227 ++-- src/XGUI/XGUI_ViewBackground.h | 171 +-- src/XGUI/XGUI_ViewPort.cpp | 809 +++++++------- src/XGUI/XGUI_ViewPort.h | 131 ++- src/XGUI/XGUI_ViewWindow.cpp | 1346 +++++++++++------------ src/XGUI/XGUI_ViewWindow.h | 294 ++--- src/XGUI/XGUI_Viewer.cpp | 361 +++--- src/XGUI/XGUI_Viewer.h | 124 ++- src/XGUI/XGUI_Workbench.cpp | 191 ++-- src/XGUI/XGUI_Workbench.h | 38 +- src/XGUI/XGUI_Workshop.cpp | 190 ++-- src/XGUI/XGUI_Workshop.h | 42 +- 52 files changed, 2942 insertions(+), 2957 deletions(-) diff --git a/src/Config/Config_FeatureMessage.cpp b/src/Config/Config_FeatureMessage.cpp index 896f62a13..3146e37c5 100644 --- a/src/Config/Config_FeatureMessage.cpp +++ b/src/Config/Config_FeatureMessage.cpp @@ -3,8 +3,7 @@ */ #include "Config_FeatureMessage.h" -Config_FeatureMessage::Config_FeatureMessage(const Event_ID theId, - const void* theParent) +Config_FeatureMessage::Config_FeatureMessage(const Event_ID theId, const void* theParent) : Event_Message(theId, theParent) { myId = ""; diff --git a/src/Config/Config_FeatureMessage.h b/src/Config/Config_FeatureMessage.h index ff14c46ae..1a0f99477 100644 --- a/src/Config/Config_FeatureMessage.h +++ b/src/Config/Config_FeatureMessage.h @@ -1,45 +1,45 @@ -#ifndef CONFIG_MESSAGE_H -#define CONFIG_MESSAGE_H - -#include "Config.h" - -#include -#include - -class CONFIG_EXPORT Config_FeatureMessage : public Event_Message -{ - - std::string myId; - std::string myText; - std::string myTooltip; - std::string myIcon; - std::string myKeysequence; - - std::string myGroupId; - std::string myWorkbenchId; - -public: - //const Event_ID theID, const void* theSender = 0 - Config_FeatureMessage(const Event_ID theId, const void* theParent = 0); - - //Auto-generated getters/setters - const std::string& icon() const; - const std::string& id() const; - const std::string& keysequence() const; - const std::string& text() const; - const std::string& tooltip() const; - - const std::string& groupId() const; - const std::string& workbenchId() const; - - void setIcon(const std::string& icon); - void setId(const std::string& id); - void setKeysequence(const std::string& keysequence); - void setText(const std::string& text); - void setTooltip(const std::string& tooltip); - - void setGroupId(const std::string& groupId); - void setWorkbenchId(const std::string& workbenchId); -}; - -#endif // CONFIG_MESSAGE_H +#ifndef CONFIG_MESSAGE_H +#define CONFIG_MESSAGE_H + +#include "Config.h" + +#include +#include + +class CONFIG_EXPORT Config_FeatureMessage: public Event_Message +{ + + std::string myId; + std::string myText; + std::string myTooltip; + std::string myIcon; + std::string myKeysequence; + + std::string myGroupId; + std::string myWorkbenchId; + +public: + //const Event_ID theID, const void* theSender = 0 + Config_FeatureMessage(const Event_ID theId, const void* theParent = 0); + + //Auto-generated getters/setters + const std::string& icon() const; + const std::string& id() const; + const std::string& keysequence() const; + const std::string& text() const; + const std::string& tooltip() const; + + const std::string& groupId() const; + const std::string& workbenchId() const; + + void setIcon(const std::string& icon); + void setId(const std::string& id); + void setKeysequence(const std::string& keysequence); + void setText(const std::string& text); + void setTooltip(const std::string& tooltip); + + void setGroupId(const std::string& groupId); + void setWorkbenchId(const std::string& workbenchId); +}; + +#endif // CONFIG_MESSAGE_H \ No newline at end of file diff --git a/src/Config/Config_FeatureReader.cpp b/src/Config/Config_FeatureReader.cpp index 53c0d6c88..03e5f3abd 100644 --- a/src/Config/Config_FeatureReader.cpp +++ b/src/Config/Config_FeatureReader.cpp @@ -32,17 +32,15 @@ const static char* FEATURE_TOOLTIP = "tooltip"; const static char* FEATURE_ICON = "icon"; const static char* FEATURE_KEYSEQUENCE = "keysequence"; - Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile) - : Config_XMLReader(theXmlFile), - m_fetchWidgetCfg(false) + : Config_XMLReader(theXmlFile), m_fetchWidgetCfg(false) { - #ifdef _DEBUG +#ifdef _DEBUG if(!Event_Loop::Loop()) { std::cout << "Config_FeatureReader::importWorkbench: " - << "No event loop registered" << std::endl; + << "No event loop registered" << std::endl; } - #endif +#endif } Config_FeatureReader::~Config_FeatureReader() @@ -59,11 +57,11 @@ std::string Config_FeatureReader::featureWidgetCfg(std::string theFeatureName) void Config_FeatureReader::processNode(xmlNodePtr theNode) { - if(isNode(theNode, NODE_FEATURE, NULL)) { - if(m_fetchWidgetCfg) { + if (isNode(theNode, NODE_FEATURE, NULL)) { + if (m_fetchWidgetCfg) { xmlBufferPtr buffer = xmlBufferCreate(); int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1); - m_widgetCfg = std::string((char*)buffer->content); + m_widgetCfg = std::string((char*) buffer->content); } else { Event_Loop* aEvLoop = Event_Loop::Loop(); Config_FeatureMessage aMessage(aEvLoop->EventByName("menu_item"), this); @@ -72,10 +70,10 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode) } } //The m_last* variables always defined before fillFeature() call. XML is a tree. - if(isNode(theNode, NODE_GROUP, NULL)) { + if (isNode(theNode, NODE_GROUP, NULL)) { m_lastGroup = getProperty(theNode, _ID); } - if(isNode(theNode, NODE_WORKBENCH, NULL)) { + if (isNode(theNode, NODE_WORKBENCH, NULL)) { m_lastWorkbench = getProperty(theNode, _ID); } } @@ -85,8 +83,7 @@ bool Config_FeatureReader::processChildren(xmlNodePtr theNode) return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL); } -void Config_FeatureReader::fillFeature(xmlNodePtr theRoot, - Config_FeatureMessage& outFtMessage) +void Config_FeatureReader::fillFeature(xmlNodePtr theRoot, Config_FeatureMessage& outFtMessage) { outFtMessage.setId(getProperty(theRoot, _ID)); outFtMessage.setText(getProperty(theRoot, FEATURE_TEXT)); diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index 1a6d1c7ce..5b536141d 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -25,10 +25,8 @@ const static char* PLUGINS_MODULE = "module"; const static char* PLUGIN_CONFIG = "configuration"; const static char* PLUGIN_LIBRARY = "library"; - Config_ModuleReader::Config_ModuleReader() - : Config_XMLReader("plugins.xml"), - m_isAutoImport(false) + : Config_XMLReader("plugins.xml"), m_isAutoImport(false) { } @@ -51,9 +49,9 @@ std::string Config_ModuleReader::getModuleName() */ void Config_ModuleReader::processNode(xmlNodePtr theNode) { - if(isNode(theNode, NODE_PLUGIN, NULL)) { + if (isNode(theNode, NODE_PLUGIN, NULL)) { std::string aPluginName = getProperty(theNode, PLUGIN_CONFIG); - if(m_isAutoImport) + if (m_isAutoImport) importPlugin(aPluginName); m_pluginsList.push_back(aPluginName); } diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index fd625fc3f..e9a31e207 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -20,7 +20,6 @@ #include #endif - Config_XMLReader::Config_XMLReader(const std::string& theXmlFileName) { std::string prefix; @@ -35,7 +34,7 @@ Config_XMLReader::Config_XMLReader(const std::string& theXmlFileName) prefix = std::string(char_path); //chop "bin\XGUI.exe" unsigned found = prefix.rfind("bin"); - if(found != std::string::npos) + if (found != std::string::npos) prefix.replace(found, prefix.length(), "plugins\\"); #else //TODO(sbh): Find full path to binary on linux @@ -45,7 +44,6 @@ Config_XMLReader::Config_XMLReader(const std::string& theXmlFileName) m_DocumentPath = prefix + theXmlFileName; } - Config_XMLReader::~Config_XMLReader() { } @@ -68,11 +66,11 @@ void Config_XMLReader::readAll() */ void Config_XMLReader::processNode(xmlNodePtr aNode) { - #ifdef _DEBUG - std::cout << "Config_XMLReader::processNode: " - << aNode->name << " content: " - << aNode->content << std::endl; - #endif +#ifdef _DEBUG + std::cout << "Config_XMLReader::processNode: " + << aNode->name << " content: " + << aNode->content << std::endl; +#endif } /* @@ -88,19 +86,19 @@ xmlNodePtr Config_XMLReader::findRoot() { xmlDocPtr aDoc; aDoc = xmlParseFile(m_DocumentPath.c_str()); - if(aDoc == NULL) { - #ifdef _DEBUG + if (aDoc == NULL) { +#ifdef _DEBUG std::cout << "Config_XMLReader::import: " << "Document " << m_DocumentPath - << " is not parsed successfully." << std::endl; - #endif + << " is not parsed successfully." << std::endl; +#endif return NULL; } xmlNodePtr aRoot = xmlDocGetRootElement(aDoc); - #ifdef _DEBUG +#ifdef _DEBUG if(aRoot == NULL) { std::cout << "Config_XMLReader::import: " << "Error: empty document"; } - #endif +#endif return aRoot; } @@ -113,12 +111,12 @@ void Config_XMLReader::readRecursively(xmlNodePtr theParent) { static Event_ID aFeatureEvent = Event_Loop::EventByName("Feature"); - if(!theParent) + if (!theParent) return; xmlNodePtr aNode = theParent->xmlChildrenNode; for(; aNode; aNode = aNode->next) { processNode(aNode); - if(processChildren(aNode)) { + if (processChildren(aNode)) { readRecursively(aNode); Config_FeatureMessage aMessage(aFeatureEvent, this); } @@ -140,7 +138,7 @@ std::string Config_XMLReader::getProperty(xmlNodePtr theNode, const char* name) { std::string result = ""; char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST name); - if(!aPropChars || aPropChars[0] == 0) + if (!aPropChars || aPropChars[0] == 0) return result; result = std::string(aPropChars); return result; @@ -153,23 +151,23 @@ bool Config_XMLReader::isNode(xmlNodePtr theNode, const char* theNodeName, ...) { bool result = false; const xmlChar* aName = theNode->name; - if(!aName || theNode->type != XML_ELEMENT_NODE) + if (!aName || theNode->type != XML_ELEMENT_NODE) return false; - if(!xmlStrcmp(aName, (const xmlChar *) theNodeName)) + if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) return true; va_list args; // define argument list variable - va_start (args, theNodeName); // init list; point to last defined argument + va_start(args, theNodeName); // init list; point to last defined argument while(true) { char *anArg = va_arg (args, char *); // get next argument - if(anArg == NULL) + if (anArg == NULL) break; - if(!xmlStrcmp(aName, (const xmlChar *) anArg)) { - va_end (args); // cleanup the system stack + if (!xmlStrcmp(aName, (const xmlChar *) anArg)) { + va_end(args); // cleanup the system stack return true; } } - va_end (args); // cleanup the system stack + va_end(args); // cleanup the system stack return false; } diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index 798a975d2..785dca9c2 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -19,8 +19,8 @@ typedef struct _xmlNode xmlNode; typedef xmlNode *xmlNodePtr; struct _xmlNode; - -class CONFIG_EXPORT Config_XMLReader { +class CONFIG_EXPORT Config_XMLReader +{ public: Config_XMLReader(const std::string& theXmlFile); virtual ~Config_XMLReader(); diff --git a/src/Event/Event_Listener.cxx b/src/Event/Event_Listener.cxx index 44f907552..633dd4ad8 100644 --- a/src/Event/Event_Listener.cxx +++ b/src/Event/Event_Listener.cxx @@ -2,4 +2,4 @@ // Created: Thu Mar 13 2014 // Author: Mikhail PONIKAROV -#include \ No newline at end of file +#include diff --git a/src/Event/Event_Listener.hxx b/src/Event/Event_Listener.hxx index 8a17122d9..87bf0464a 100644 --- a/src/Event/Event_Listener.hxx +++ b/src/Event/Event_Listener.hxx @@ -15,7 +15,8 @@ class Event_Message; * If some object wants to listen some events it must inherit * this class and register in the Loop. */ -class EVENT_EXPORT Event_Listener { +class EVENT_EXPORT Event_Listener +{ public: //! This method is called by loop when the event is started to process. diff --git a/src/Event/Event_Loop.cxx b/src/Event/Event_Loop.cxx index d5981a823..558edd0da 100644 --- a/src/Event/Event_Loop.cxx +++ b/src/Event/Event_Loop.cxx @@ -24,7 +24,7 @@ Event_ID Event_Loop::EventByName(const char* theName) if (aFound == CREATED_EVENTS.end()) { //not created yet aResult = strdup(theName); // copy to make unique internal pointer CREATED_EVENTS[aName] = aResult; - } else + } else aResult = aFound->second; return Event_ID(aResult); @@ -34,11 +34,11 @@ void Event_Loop::Send(Event_Message& theMessage) { // TO DO: make it in thread and wit husage of semaphores - map > >::iterator aFindID = - myListeners.find(theMessage.EventID().EventText()); + map > >::iterator aFindID = myListeners.find( + theMessage.EventID().EventText()); if (aFindID != myListeners.end()) { - map >::iterator aFindSender = - aFindID->second.find(theMessage.Sender()); + map >::iterator aFindSender = aFindID->second.find( + theMessage.Sender()); if (aFindSender != aFindID->second.end()) { list& aListeners = aFindSender->second; for(list::iterator aL = aListeners.begin(); aL != aListeners.end(); aL++) @@ -55,18 +55,17 @@ void Event_Loop::Send(Event_Message& theMessage) } } -void Event_Loop::RegisterListener( - Event_Listener* theListener, const Event_ID theID, void* theSender) +void Event_Loop::RegisterListener(Event_Listener* theListener, const Event_ID theID, + void* theSender) { - map > >::iterator aFindID = - myListeners.find(theID.EventText()); + map > >::iterator aFindID = myListeners.find( + theID.EventText()); if (aFindID == myListeners.end()) { // create container associated with ID myListeners[theID.EventText()] = map >(); aFindID = myListeners.find(theID.EventText()); } - map >::iterator aFindSender = - aFindID->second.find(theSender); + map >::iterator aFindSender = aFindID->second.find(theSender); if (aFindSender == aFindID->second.end()) { // create container associated with sender aFindID->second[theSender] = list(); aFindSender = aFindID->second.find(theSender); @@ -74,7 +73,8 @@ void Event_Loop::RegisterListener( // check that listener was not registered wit hsuch parameters before list& aListeners = aFindSender->second; for(list::iterator aL = aListeners.begin(); aL != aListeners.end(); aL++) - if (*aL == theListener) return; // avoid duplicates + if (*aL == theListener) + return; // avoid duplicates aListeners.push_back(theListener); } diff --git a/src/Event/Event_Loop.hxx b/src/Event/Event_Loop.hxx index 3d57ec45c..d50e6633f 100644 --- a/src/Event/Event_Loop.hxx +++ b/src/Event/Event_Loop.hxx @@ -21,12 +21,15 @@ * Performing of events is processed in separated thread, so, sender takes * control back immideately. */ -class Event_Loop { - std::map > > - myListeners; ///< map from event ID to sender pointer to listeners that must be called for this +class Event_Loop +{ + std::map > > myListeners; ///< map from event ID to sender pointer to listeners that must be called for this //! The empty constructor, will be called at startup of the application, only once - Event_Loop() {}; + Event_Loop() + { + } + ; public: ///! Returns the main object of the loop, one per application. EVENT_EXPORT static Event_Loop* Loop(); @@ -39,8 +42,8 @@ public: //! Registers (or adds if such listener is already registered) a listener //! that will be called on the event and from the defined sender - EVENT_EXPORT void RegisterListener(Event_Listener* theListener, const Event_ID theID, - void* theSender = 0); + EVENT_EXPORT void RegisterListener(Event_Listener* theListener, const Event_ID theID, + void* theSender = 0); }; #endif diff --git a/src/Event/Event_Message.cxx b/src/Event/Event_Message.cxx index 53186da31..96097b409 100644 --- a/src/Event/Event_Message.cxx +++ b/src/Event/Event_Message.cxx @@ -4,7 +4,7 @@ #include -Event_Message::Event_Message(const Event_ID theID, const void* theSender) : -myEventId(theID), mySender((void*)theSender) +Event_Message::Event_Message(const Event_ID theID, const void* theSender) + : myEventId(theID), mySender((void*) theSender) { } diff --git a/src/Event/Event_Message.hxx b/src/Event/Event_Message.hxx index bb700a75d..66346be3a 100644 --- a/src/Event/Event_Message.hxx +++ b/src/Event/Event_Message.hxx @@ -17,17 +17,27 @@ * used as an identifier (this is usefull for debugging of the events * with log files and in debugger). */ -class EVENT_EXPORT Event_ID { +class EVENT_EXPORT Event_ID +{ char* myID; ///< pointer to the text-identifier of the event, unique pointer for all events of such type - Event_ID(char* theID) {myID = theID;} + Event_ID(char* theID) + { + myID = theID; + } friend class Event_Loop; public: /// Returns the text-identifier of the event (for debugging reasons) - char* EventText() const {return myID;} + char* EventText() const + { + return myID; + } /// Allows to compare identifiers - bool operator==(const Event_ID& theID) const {return myID == theID.myID;} + bool operator==(const Event_ID& theID) const + { + return myID == theID.myID; + } }; /**\class Event_Message @@ -35,7 +45,8 @@ public: * \brief Message for communication between sender and listener of event. * Normally it is inherited by the higher-level */ -class EVENT_EXPORT Event_Message { +class EVENT_EXPORT Event_Message +{ Event_ID myEventId; ///< identifier of the event void* mySender; ///< the sender object @@ -43,13 +54,21 @@ public: //! Creates the message Event_Message(const Event_ID theID, const void* theSender = 0); - virtual ~Event_Message() {} + virtual ~Event_Message() + { + } //! Returns identifier of the message - const Event_ID& EventID() const {return myEventId;} + const Event_ID& EventID() const + { + return myEventId; + } //! Returns sender of the message or NULL if it is anonymous message - void* Sender() {return mySender;} + void* Sender() + { + return mySender; + } }; #endif diff --git a/src/Model/Model_Application.cxx b/src/Model/Model_Application.cxx index 093b57816..dab193d13 100644 --- a/src/Model/Model_Application.cxx +++ b/src/Model/Model_Application.cxx @@ -5,8 +5,8 @@ #include #include -IMPLEMENT_STANDARD_HANDLE(Model_Application,TDocStd_Application) -IMPLEMENT_STANDARD_RTTIEXT(Model_Application,TDocStd_Application) +IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application) +IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application) static Handle_Model_Application TheApplication = new Model_Application; @@ -14,7 +14,7 @@ static Handle_Model_Application TheApplication = new Model_Application; //function : getApplication //purpose : //======================================================================= -Handle_Model_Application Model_Application::GetApplication() +Handle_Model_Application Model_Application::GetApplication() { return TheApplication; } @@ -36,7 +36,7 @@ ModelAPI_Document* Model_Application::GetMainDocument() //function : OCAFApp_Application //purpose : //======================================================================= -Model_Application::Model_Application () +Model_Application::Model_Application() { // store handle to the application to avoid nullification static Handle(Model_Application) TheKeepHandle; @@ -47,9 +47,9 @@ Model_Application::Model_Application () //function : Formats //purpose : //======================================================================= -void Model_Application::Formats(TColStd_SequenceOfExtendedString& theFormats) +void Model_Application::Formats(TColStd_SequenceOfExtendedString& theFormats) { - theFormats.Append(TCollection_ExtendedString ("BinOcaf")); // standard binary schema + theFormats.Append(TCollection_ExtendedString("BinOcaf")); // standard binary schema } //======================================================================= diff --git a/src/Model/Model_Application.hxx b/src/Model/Model_Application.hxx index 78d6ec106..77d669257 100644 --- a/src/Model/Model_Application.hxx +++ b/src/Model/Model_Application.hxx @@ -11,38 +11,40 @@ #include // Define handle class -DEFINE_STANDARD_HANDLE(Model_Application,TDocStd_Application) +DEFINE_STANDARD_HANDLE(Model_Application, TDocStd_Application) - /**\class Model_Application +/**\class Model_Application * \ingroup DataModel * \brief Realization of Open CASCADE application abstraction. Class for internal use only. * Application supports the formats and document management. It is uses OCAF-lke * architecture and just implements specific features of the module. */ -class Model_Application : public TDocStd_Application, public ModelAPI_Application +class Model_Application: public TDocStd_Application, public ModelAPI_Application { -public: // useful methods inside of the module +public: + // useful methods inside of the module // CASCADE RTTI - DEFINE_STANDARD_RTTI(Model_Application); + DEFINE_STANDARD_RTTI(Model_Application) + ; //! Retuns the application: one per process - MODEL_EXPORT static Handle_Model_Application GetApplication(); + MODEL_EXPORT static Handle_Model_Application GetApplication(); //! Returns the main document (on first call creates it) MODEL_EXPORT ModelAPI_Document* GetMainDocument(); -public: // Redefined OCAF methods +public: + // Redefined OCAF methods //! Return name of resource (i.e. "Standard") Standard_CString ResourcesName(); //! Return format (i.e "MDTV-Standard") //! \param theFormats sequence of allowed formats for input/output - virtual void Formats(TColStd_SequenceOfExtendedString& theFormats); + virtual void Formats(TColStd_SequenceOfExtendedString& theFormats); //! Constructor //! Use method GetInstance() method to obtain //! the static instance of the object (or derive your own application) Model_Application(); - private: Handle_Model_Document myMainDoc; ///< main document of an application diff --git a/src/Model/Model_Document.cxx b/src/Model/Model_Document.cxx index eec9755ab..ed000dea6 100644 --- a/src/Model/Model_Document.cxx +++ b/src/Model/Model_Document.cxx @@ -7,8 +7,8 @@ #include -IMPLEMENT_STANDARD_HANDLE(Model_Document,MMgt_TShared) -IMPLEMENT_STANDARD_RTTIEXT(Model_Document,MMgt_TShared) +IMPLEMENT_STANDARD_HANDLE(Model_Document, MMgt_TShared) +IMPLEMENT_STANDARD_RTTIEXT(Model_Document, MMgt_TShared) static const int UNDO_LIMIT = 10; // number of possible undo operations in the module @@ -23,40 +23,40 @@ bool Model_Document::Load(const char* theFileName) { bool myIsError = Standard_False; /* - TCollection_ExtendedString aPath ((const Standard_CString)theFileName); - PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1; - try - { - Handle(TDocStd_Document) aDoc = this; - aStatus = Model_Application::GetApplication()->Open(aPath, aDoc); - } - catch (Standard_Failure) - {} - myIsError = aStatus != PCDM_RS_OK; - if (myIsError) - { - switch (aStatus) - { - case PCDM_RS_UnknownDocument: cout<<"OCAFApp_Appl_RUnknownDocument"<Open(aPath, aDoc); + } + catch (Standard_Failure) + {} + myIsError = aStatus != PCDM_RS_OK; + if (myIsError) + { + switch (aStatus) + { + case PCDM_RS_UnknownDocument: cout<<"OCAFApp_Appl_RUnknownDocument"<SaveAs (aDoc, aPath); - } - catch (Standard_Failure) { - Handle(Standard_Failure) aFail = Standard_Failure::Caught(); - cout<<"OCAFApp_Engine:save Error: "<GetMessageString()<SaveAs (aDoc, aPath); + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + cout<<"OCAFApp_Engine:save Error: "<GetMessageString()<( theMessage ); - if(aMsg) { + const Config_FeatureMessage* aMsg = dynamic_cast(theMessage); + if (aMsg) { // proccess the plugin info, load plugin } } diff --git a/src/Model/Model_PluginManager.hxx b/src/Model/Model_PluginManager.hxx index 584eb63c5..b41ee74e8 100644 --- a/src/Model/Model_PluginManager.hxx +++ b/src/Model/Model_PluginManager.hxx @@ -16,7 +16,7 @@ * the feature functionality request. */ -class MODEL_EXPORT Model_PluginManager : public ModelAPI_PluginManager, public Event_Listener +class MODEL_EXPORT Model_PluginManager: public ModelAPI_PluginManager, public Event_Listener { public: /// Creates the feature object using plugins functionality diff --git a/src/ModelAPI/ModelAPI_Document.hxx b/src/ModelAPI/ModelAPI_Document.hxx index cc8aa70df..5232771a5 100644 --- a/src/ModelAPI/ModelAPI_Document.hxx +++ b/src/ModelAPI/ModelAPI_Document.hxx @@ -53,10 +53,13 @@ public: //! Returns True if there are available Redos MODELAPI_EXPORT virtual bool CanRedo() = 0; //! Redoes last operation - MODELAPI_EXPORT virtual void Redo() = 0; + MODELAPI_EXPORT virtual void Redo() = 0; /// Only for SWIG wrapping it is here - MODELAPI_EXPORT ModelAPI_Document() {}; + MODELAPI_EXPORT ModelAPI_Document() + { + } + ; }; #endif diff --git a/src/ModelAPI/ModelAPI_Feature.hxx b/src/ModelAPI/ModelAPI_Feature.hxx index ea84802cc..f29a3a73c 100644 --- a/src/ModelAPI/ModelAPI_Feature.hxx +++ b/src/ModelAPI/ModelAPI_Feature.hxx @@ -24,7 +24,9 @@ public: /// Use plugin manager for features creation: this method is /// defined here only for SWIG-wrapping - ModelAPI_Feature() {} + ModelAPI_Feature() + { + } }; #endif diff --git a/src/ModelAPI/ModelAPI_Interface.hxx b/src/ModelAPI/ModelAPI_Interface.hxx index 377b7eab7..6fdb28dbc 100644 --- a/src/ModelAPI/ModelAPI_Interface.hxx +++ b/src/ModelAPI/ModelAPI_Interface.hxx @@ -18,17 +18,26 @@ class MODELAPI_EXPORT ModelAPI_Interface public: /// None - constructor - virtual ModelAPI_Interface() {myImpl = 0;} + virtual ModelAPI_Interface() + { + myImpl = 0; + } /// Constructor by the implementation pointer (used for internal needs) - virtual ModelAPI_Interface(void* theImpl) {myImpl = theImpl;} + virtual ModelAPI_Interface(void* theImpl) + { + myImpl = theImpl; + } /// Copy-constructor - virtual ModelAPI_Interface(ModelAPI_Interface& theOrig) - {myImpl = theOrig.theImpl; Duplicate();} + virtual ModelAPI_Interface(ModelAPI_Interface& theOrig) + { + myImpl = theOrig.theImpl; + Duplicate(); + } virtual ModelAPI_Interface& operator=(ModelAPI_Interface& const theOrig) - {myImpl = theOrig.theImpl; Duplicate(); return *this;} + { myImpl = theOrig.theImpl; Duplicate(); return *this;} /// Duplicates the objet pointed by myImpl (loosing the old one) virtual void Duplicate() = 0; diff --git a/src/ModelAPI/ModelAPI_PluginManager.cxx b/src/ModelAPI/ModelAPI_PluginManager.cxx index 889b6e7d6..2afb0ceb8 100644 --- a/src/ModelAPI/ModelAPI_PluginManager.cxx +++ b/src/ModelAPI/ModelAPI_PluginManager.cxx @@ -11,16 +11,16 @@ /// Manager that will be initialized from Model package, one per application boost::shared_ptr MY_MANAGER; -ModelAPI_PluginManager::ModelAPI_PluginManager() -{} +ModelAPI_PluginManager::ModelAPI_PluginManager() +{ +} boost::shared_ptr ModelAPI_PluginManager::Get() { return MY_MANAGER; } -void ModelAPI_PluginManager::SetPluginManager( - boost::shared_ptr theManager) +void ModelAPI_PluginManager::SetPluginManager(boost::shared_ptr theManager) { MY_MANAGER = theManager; } diff --git a/src/PartSet/PartSet_Message.cpp b/src/PartSet/PartSet_Message.cpp index 0c3d72cbe..7ac2400e3 100644 --- a/src/PartSet/PartSet_Message.cpp +++ b/src/PartSet/PartSet_Message.cpp @@ -7,8 +7,7 @@ #include -PartSet_Message::PartSet_Message(const Event_ID theId, - const void* theParent) +PartSet_Message::PartSet_Message(const Event_ID theId, const void* theParent) : Event_Message(theId, theParent) { diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 6b02152ce..908587d52 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -16,13 +16,11 @@ extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop) return new PartSet_Module(theWshop); } - PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop) { - myWorkshop = theWshop; + myWorkshop = theWshop; } - PartSet_Module::~PartSet_Module() { } @@ -38,7 +36,7 @@ void PartSet_Module::createFeatures() void PartSet_Module::featureCreated(XGUI_Command* theFeature) { QString aFtId = theFeature->getId(); - if(aFtId == "new_point") { + if (aFtId == "new_point") { theFeature->connectTo(this, SLOT(onCommandTriggered())); } } @@ -50,7 +48,6 @@ void PartSet_Module::onCommandTriggered() std::string aPluginName = aModuleReader.pluginsList().front(); Config_FeatureReader* aReader = new Config_FeatureReader(aPluginName); XGUI_Command* aCmd = dynamic_cast(sender()); - std::string aXMLWidgetCfg = - aReader->featureWidgetCfg(aCmd->getId().toStdString()); + std::string aXMLWidgetCfg = aReader->featureWidgetCfg(aCmd->getId().toStdString()); delete aReader; } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 049e3e424..db601db2f 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -1,4 +1,3 @@ - #ifndef PartSet_Module_H #define PartSet_Module_H @@ -9,22 +8,22 @@ #include -class PARTSET_EXPORT PartSet_Module : public QObject, public XGUI_Module +class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module { - Q_OBJECT +Q_OBJECT public: - PartSet_Module(XGUI_Workshop* theWshop); - virtual ~PartSet_Module(); + PartSet_Module(XGUI_Workshop* theWshop); + virtual ~PartSet_Module(); - virtual void createFeatures(); - virtual void featureCreated(XGUI_Command* theFeature); + virtual void createFeatures(); + virtual void featureCreated(XGUI_Command* theFeature); public slots: - void onCommandTriggered(); + void onCommandTriggered(); private: - QString myMenuXML; - XGUI_Workshop* myWorkshop; + QString myMenuXML; + XGUI_Workshop* myWorkshop; }; #endif diff --git a/src/XGUI/XGUI_Command.cpp b/src/XGUI/XGUI_Command.cpp index 3ba1689a3..5ec79621f 100644 --- a/src/XGUI/XGUI_Command.cpp +++ b/src/XGUI/XGUI_Command.cpp @@ -2,61 +2,61 @@ #include -XGUI_Command::XGUI_Command(const QString& theId, QObject * parent) : - QWidgetAction(parent), myId(theId) +XGUI_Command::XGUI_Command(const QString& theId, QObject * parent) + : QWidgetAction(parent), myId(theId) { } -XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent): - QWidgetAction(parent), myId(theId) +XGUI_Command::XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, + QObject* parent) + : QWidgetAction(parent), myId(theId) { - setIcon(icon); - setText(text); + setIcon(icon); + setText(text); } - XGUI_Command::~XGUI_Command() { } QWidget* XGUI_Command::createWidget(QWidget* theParent) { - if (theParent->inherits("XGUI_MenuGroupPanel")) { - QPushButton* aBtn = new QPushButton(theParent); - aBtn->setIcon(icon()); - aBtn->setText(text()); - QKeySequence aKeys = shortcut(); - QString aToolTip = toolTip(); - if (!aKeys.isEmpty()) - aToolTip = aToolTip + " (" + aKeys.toString() + ")"; - if (!aToolTip.isEmpty()) - aBtn->setToolTip(aToolTip); - - aBtn->addAction(this); - connect(aBtn, SIGNAL(clicked()), this, SLOT(trigger())); - aBtn->setFlat(true); - aBtn->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT); - return aBtn; - } - return QWidgetAction::createWidget(theParent); + if (theParent->inherits("XGUI_MenuGroupPanel")) { + QPushButton* aBtn = new QPushButton(theParent); + aBtn->setIcon(icon()); + aBtn->setText(text()); + QKeySequence aKeys = shortcut(); + QString aToolTip = toolTip(); + if (!aKeys.isEmpty()) + aToolTip = aToolTip + " (" + aKeys.toString() + ")"; + if (!aToolTip.isEmpty()) + aBtn->setToolTip(aToolTip); + + aBtn->addAction(this); + connect(aBtn, SIGNAL(clicked()), this, SLOT(trigger())); + aBtn->setFlat(true); + aBtn->setMinimumSize(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT); + return aBtn; + } + return QWidgetAction::createWidget(theParent); } bool XGUI_Command::enabled() const { - return isEnabled(); + return isEnabled(); } void XGUI_Command::enable() { - setEnabled(true); + setEnabled(true); } void XGUI_Command::disable() { - setEnabled(false); + setEnabled(false); } void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot) { - connect(this, SIGNAL(triggered()), theResiver, theSlot); -} \ No newline at end of file + connect(this, SIGNAL(triggered()), theResiver, theSlot); +} diff --git a/src/XGUI/XGUI_Command.h b/src/XGUI/XGUI_Command.h index 180395501..855dbb91f 100644 --- a/src/XGUI/XGUI_Command.h +++ b/src/XGUI/XGUI_Command.h @@ -6,27 +6,29 @@ #define MIN_BUTTON_HEIGHT 18 #define MIN_BUTTON_WIDTH 40 - -class XGUI_Command : public QWidgetAction +class XGUI_Command: public QWidgetAction { - Q_OBJECT +Q_OBJECT public: - XGUI_Command(const QString& theId, QObject * parent); - XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent); - ~XGUI_Command(); + XGUI_Command(const QString& theId, QObject * parent); + XGUI_Command(const QString& theId, const QIcon& icon, const QString& text, QObject* parent); + ~XGUI_Command(); - virtual bool enabled() const; - virtual void enable(); - virtual void disable(); - virtual QString getId() const { return myId; } + virtual bool enabled() const; + virtual void enable(); + virtual void disable(); + virtual QString getId() const + { + return myId; + } - virtual void connectTo(const QObject* theResiver, const char* theSlot); + virtual void connectTo(const QObject* theResiver, const char* theSlot); protected: - virtual QWidget* createWidget(QWidget* theParent); + virtual QWidget* createWidget(QWidget* theParent); private: - QString myId; + QString myId; }; #endif diff --git a/src/XGUI/XGUI_Constants.h b/src/XGUI/XGUI_Constants.h index ceb93cc1f..53f9a4d05 100644 --- a/src/XGUI/XGUI_Constants.h +++ b/src/XGUI/XGUI_Constants.h @@ -1,51 +1,71 @@ - #ifndef XGUI_Constants_H #define XGUI_Constants_H #include -typedef QList QIntList; //!< list of int values -typedef QList QShortList; //!< list of short int values +typedef QList QIntList; //!< list of int values +typedef QList QShortList; //!< list of short int values typedef QList QDoubleList; //!< list of double values - namespace XGUI { -enum GradientType { - NoGradient = -1, - HorizontalGradient, VerticalGradient, - Diagonal1Gradient, Diagonal2Gradient, - Corner1Gradient, Corner2Gradient, - Corner3Gradient, Corner4Gradient, - LastGradient = Corner4Gradient +enum GradientType +{ + NoGradient = -1, + HorizontalGradient, + VerticalGradient, + Diagonal1Gradient, + Diagonal2Gradient, + Corner1Gradient, + Corner2Gradient, + Corner3Gradient, + Corner4Gradient, + LastGradient = Corner4Gradient }; -enum RotationPointType{ GRAVITY, SELECTED }; - -enum SketchingType { NoSketching, Rect, Polygon }; - -enum HotOperation { PAN, ZOOM, ROTATE, FIT_AREA }; +enum RotationPointType +{ + GRAVITY, SELECTED +}; -enum InteractionStyle { STANDARD, KEY_FREE }; +enum SketchingType +{ + NoSketching, Rect, Polygon +}; -enum Mode2dType { No2dMode, XYPlane, XZPlane, YZPlane}; +enum HotOperation +{ + PAN, ZOOM, ROTATE, FIT_AREA +}; -enum BackgroundMode { - NoBackground, // no (invalid) background data - ColorBackground, // single color - SimpleGradientBackground, // simple two-color gradient - CustomGradientBackground // custom (complex) gradient +enum InteractionStyle +{ + STANDARD, KEY_FREE }; - //! Texture mode -enum TextureMode { - CenterTexture, // center texture - TileTexture, // tile texture - StretchTexture, // stretch texture +enum Mode2dType +{ + No2dMode, XYPlane, XZPlane, YZPlane }; +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 }; -#endif \ No newline at end of file +} +; + +#endif diff --git a/src/XGUI/XGUI_Main.cpp b/src/XGUI/XGUI_Main.cpp index c709f31b3..f851637d6 100644 --- a/src/XGUI/XGUI_Main.cpp +++ b/src/XGUI/XGUI_Main.cpp @@ -1,19 +1,18 @@ - #include "XGUI_Workshop.h" #include #include int main(int argc, char *argv[]) { - QApplication app(argc, argv); + QApplication app(argc, argv); - // Install translator - QTranslator aTranslator; - aTranslator.load(app.applicationDirPath() + "\\XGUI_msg_en.qm"); - app.installTranslator(&aTranslator); + // Install translator + QTranslator aTranslator; + aTranslator.load(app.applicationDirPath() + "\\XGUI_msg_en.qm"); + app.installTranslator(&aTranslator); - XGUI_Workshop aWorkshop; - aWorkshop.startApplication(); + XGUI_Workshop aWorkshop; + aWorkshop.startApplication(); - return app.exec(); + return app.exec(); } diff --git a/src/XGUI/XGUI_MainMenu.cpp b/src/XGUI/XGUI_MainMenu.cpp index 04033692e..f6b703611 100644 --- a/src/XGUI/XGUI_MainMenu.cpp +++ b/src/XGUI/XGUI_MainMenu.cpp @@ -7,42 +7,40 @@ #include #include -XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent) : - QObject(parent), myDesktop(parent) +XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent) + : QObject(parent), myDesktop(parent) { - parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North); + parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North); } - XGUI_MainMenu::~XGUI_MainMenu(void) { } -XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, - const QString& theTitle) +XGUI_Workbench* XGUI_MainMenu::addWorkbench(const QString& theId, const QString& theTitle) { - QDockWidget* aDock = new QDockWidget(myDesktop); - aDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar); - aDock->setAllowedAreas(Qt::TopDockWidgetArea); - QString aTitle = theTitle; - if(aTitle.isEmpty()){ - aTitle = tr(theId.toLatin1().constData()); - } - aDock->setWindowTitle(aTitle); - aDock->setMinimumHeight(30); - aDock->setContentsMargins(0, 0, 0, 0); - - XGUI_Workbench* aPage = new XGUI_Workbench(aDock); - aPage->setObjectName(theId); - aDock->setWidget(aPage); - - myDesktop->addDockWidget(Qt::TopDockWidgetArea, aDock); - if (myMenuTabs.length() > 1) { - myDesktop->tabifyDockWidget(myMenuTabs.last(), aDock); - } - - myMenuTabs.append(aDock); - return aPage; + QDockWidget* aDock = new QDockWidget(myDesktop); + aDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar); + aDock->setAllowedAreas(Qt::TopDockWidgetArea); + QString aTitle = theTitle; + if (aTitle.isEmpty()) { + aTitle = tr(theId.toLatin1().constData()); + } + aDock->setWindowTitle(aTitle); + aDock->setMinimumHeight(30); + aDock->setContentsMargins(0, 0, 0, 0); + + XGUI_Workbench* aPage = new XGUI_Workbench(aDock); + aPage->setObjectName(theId); + aDock->setWidget(aPage); + + myDesktop->addDockWidget(Qt::TopDockWidgetArea, aDock); + if (myMenuTabs.length() > 1) { + myDesktop->tabifyDockWidget(myMenuTabs.last(), aDock); + } + + myMenuTabs.append(aDock); + return aPage; } /* diff --git a/src/XGUI/XGUI_MainMenu.h b/src/XGUI/XGUI_MainMenu.h index 3a00d4c66..42db895d6 100644 --- a/src/XGUI/XGUI_MainMenu.h +++ b/src/XGUI/XGUI_MainMenu.h @@ -14,22 +14,19 @@ class QLabel; class QAction; class QDockWidget; - - -class XGUI_MainMenu : public QObject +class XGUI_MainMenu: public QObject { - Q_OBJECT +Q_OBJECT public: - XGUI_MainMenu(XGUI_MainWindow *parent); - virtual ~XGUI_MainMenu(); + XGUI_MainMenu(XGUI_MainWindow *parent); + virtual ~XGUI_MainMenu(); - XGUI_Workbench* addWorkbench(const QString& theId, - const QString& theText = ""); - XGUI_Workbench* findWorkbench(const QString& theId); + XGUI_Workbench* addWorkbench(const QString& theId, const QString& theText = ""); + XGUI_Workbench* findWorkbench(const QString& theId); private: - XGUI_MainWindow* myDesktop; - QList myMenuTabs; + XGUI_MainWindow* myDesktop; + QList myMenuTabs; }; #endif diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index cbf8aa475..7ab8aafdf 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -20,41 +20,41 @@ #include #include -XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) : - QMainWindow(parent), myObjectBrowser(0) +XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) + : QMainWindow(parent), myObjectBrowser(0) { - setWindowTitle(tr("WINDOW_TITLE")); - myMenuBar = new XGUI_MainMenu(this); - - QDockWidget* aDoc = new QDockWidget(this); - aDoc->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - aDoc->setWindowTitle(tr("OBJECT_BROWSER_TITLE")); - myObjectBrowser = new QTreeWidget(aDoc); - myObjectBrowser->setColumnCount(1); - myObjectBrowser->setHeaderHidden(true); - aDoc->setWidget(myObjectBrowser); - addDockWidget(Qt::LeftDockWidgetArea, aDoc); - //aDoc->hide(); - - aDoc = new QDockWidget(this); - aDoc->setFeatures(QDockWidget::AllDockWidgetFeatures | QDockWidget::DockWidgetVerticalTitleBar); - aDoc->setMinimumHeight(0); - aDoc->setWindowTitle("Console"); - QTextEdit* aTextEdt = new QTextEdit(aDoc); - aTextEdt->setText(">>>"); - aDoc->setWidget(aTextEdt); - aTextEdt->setMinimumHeight(0); - addDockWidget(Qt::BottomDockWidgetArea, aDoc); - - QMdiArea* aMdiArea = new QMdiArea(this); - setCentralWidget(aMdiArea); - - myViewer = new XGUI_Viewer(this); - //aMdiArea->addSubWindow(new XGUI_ViewWindow(), Qt::FramelessWindowHint); - //aMdiArea->addSubWindow(new XGUI_ViewWindow(), Qt::FramelessWindowHint); - - fillObjectBrowser(); - addPropertyPanel(); + setWindowTitle(tr("WINDOW_TITLE")); + myMenuBar = new XGUI_MainMenu(this); + + QDockWidget* aDoc = new QDockWidget(this); + aDoc->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + aDoc->setWindowTitle(tr("OBJECT_BROWSER_TITLE")); + myObjectBrowser = new QTreeWidget(aDoc); + myObjectBrowser->setColumnCount(1); + myObjectBrowser->setHeaderHidden(true); + aDoc->setWidget(myObjectBrowser); + addDockWidget(Qt::LeftDockWidgetArea, aDoc); + //aDoc->hide(); + + aDoc = new QDockWidget(this); + aDoc->setFeatures(QDockWidget::AllDockWidgetFeatures | QDockWidget::DockWidgetVerticalTitleBar); + aDoc->setMinimumHeight(0); + aDoc->setWindowTitle("Console"); + QTextEdit* aTextEdt = new QTextEdit(aDoc); + aTextEdt->setText(">>>"); + aDoc->setWidget(aTextEdt); + aTextEdt->setMinimumHeight(0); + addDockWidget(Qt::BottomDockWidgetArea, aDoc); + + QMdiArea* aMdiArea = new QMdiArea(this); + setCentralWidget(aMdiArea); + + myViewer = new XGUI_Viewer(this); + //aMdiArea->addSubWindow(new XGUI_ViewWindow(), Qt::FramelessWindowHint); + //aMdiArea->addSubWindow(new XGUI_ViewWindow(), Qt::FramelessWindowHint); + + fillObjectBrowser(); + addPropertyPanel(); } XGUI_MainWindow::~XGUI_MainWindow(void) @@ -64,148 +64,145 @@ XGUI_MainWindow::~XGUI_MainWindow(void) //****************************************************** QMdiArea* XGUI_MainWindow::mdiArea() const { - return static_cast(centralWidget()); + return static_cast(centralWidget()); } - //****************************************************** void XGUI_MainWindow::showObjectBrowser() { - myObjectBrowser->parentWidget()->show(); + myObjectBrowser->parentWidget()->show(); } //****************************************************** void XGUI_MainWindow::hideObjectBrowser() { - myObjectBrowser->parentWidget()->hide(); + myObjectBrowser->parentWidget()->hide(); } //****************************************************** void XGUI_MainWindow::fillObjectBrowser() { - QStringList aNames; - aNames << "Parameters" << "Constructions"; - aNames << "Part 1" << "Part 2" << "Part 3"; - aNames << "Properties"; - - QStringList aIcons; - aIcons << ":pictures/params_folder.png"; - aIcons << ":pictures/constr_folder.png"; - aIcons << ":pictures/part_ico.png"; - aIcons << ":pictures/part_ico.png"; - aIcons << ":pictures/part_ico.png"; - aIcons << ":pictures/properties.png"; - - QList aItems; - foreach(QString aName, aNames) { - QTreeWidgetItem* aItem = new QTreeWidgetItem(myObjectBrowser); - aItem->setText(0, aName); - aItems.append(aItem); - } - for(int i = 0; i < aItems.length(); i++) { - aItems[i]->setIcon(0, QIcon(aIcons[i])); - } - myObjectBrowser->addTopLevelItems(aItems); - - for (int i = 2; i < 5; i++) { - QTreeWidgetItem* aItem = new QTreeWidgetItem(aItems[i]); - aItem->setText(0, "Parameters"); - aItem->setIcon(0, QIcon(":pictures/params_folder.png")); - - aItem = new QTreeWidgetItem(aItems[i]); - aItem->setText(0, "Construction"); - aItem->setIcon(0, QIcon(":pictures/constr_folder.png")); - - aItem = new QTreeWidgetItem(aItems[i]); - aItem->setText(0, "Bodies"); - aItem->setIcon(0, QIcon(":pictures/part_ico.png")); - - aItem = new QTreeWidgetItem(aItems[i]); - aItem->setText(0, "Features"); - aItem->setIcon(0, QIcon(":pictures/features.png")); - } + QStringList aNames; + aNames << "Parameters" << "Constructions"; + aNames << "Part 1" << "Part 2" << "Part 3"; + aNames << "Properties"; + + QStringList aIcons; + aIcons << ":pictures/params_folder.png"; + aIcons << ":pictures/constr_folder.png"; + aIcons << ":pictures/part_ico.png"; + aIcons << ":pictures/part_ico.png"; + aIcons << ":pictures/part_ico.png"; + aIcons << ":pictures/properties.png"; + + QList aItems; + foreach(QString aName, aNames) + { + QTreeWidgetItem* aItem = new QTreeWidgetItem(myObjectBrowser); + aItem->setText(0, aName); + aItems.append(aItem); + } + for(int i = 0; i < aItems.length(); i++) { + aItems[i]->setIcon(0, QIcon(aIcons[i])); + } + myObjectBrowser->addTopLevelItems(aItems); + + for(int i = 2; i < 5; i++) { + QTreeWidgetItem* aItem = new QTreeWidgetItem(aItems[i]); + aItem->setText(0, "Parameters"); + aItem->setIcon(0, QIcon(":pictures/params_folder.png")); + + aItem = new QTreeWidgetItem(aItems[i]); + aItem->setText(0, "Construction"); + aItem->setIcon(0, QIcon(":pictures/constr_folder.png")); + + aItem = new QTreeWidgetItem(aItems[i]); + aItem->setText(0, "Bodies"); + aItem->setIcon(0, QIcon(":pictures/part_ico.png")); + + aItem = new QTreeWidgetItem(aItems[i]); + aItem->setText(0, "Features"); + aItem->setIcon(0, QIcon(":pictures/features.png")); + } } - void XGUI_MainWindow::addPropertyPanel() { - QDockWidget* aPropPanel = new QDockWidget(this); - aPropPanel->setWindowTitle("Point"); - - QWidget* aContent = new QWidget(aPropPanel); - QVBoxLayout* aMainLay = new QVBoxLayout(aContent); - aMainLay->setContentsMargins(3,3,3,3); - aPropPanel->setWidget(aContent); - - /*QWidget* aNameWgt = new QWidget(aContent); - QHBoxLayout* aNameLay = new QHBoxLayout(aNameWgt); - aNameLay->setContentsMargins(0,0,0,0); - aMainLay->addWidget(aNameWgt); - - aNameLay->addWidget(new QLabel("Name", aNameWgt)); - aNameLay->addWidget(new QLineEdit(aNameWgt));*/ - - QComboBox* aCombo = new QComboBox(aContent); - aCombo->addItem("By coordinates"); - aMainLay->addWidget(aCombo); - - QWidget* aGrpBox1 = new QWidget(aContent); - //aGrpBox1->setFlat(true); - QFormLayout* aFrmLay = new QFormLayout(aGrpBox1); - aFrmLay->setContentsMargins(0, 6, 0, 0); - aMainLay->addWidget(aGrpBox1); - - - QLabel* aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/x_point.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/y_point.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/z_point.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - - -/* aGrpBox1 = new QGroupBox("Normal vector", aContent); - aGrpBox1->setFlat(true); - aFrmLay = new QFormLayout(aGrpBox1); - aFrmLay->setContentsMargins(0, 6, 0, 0); - aMainLay->addWidget(aGrpBox1); - - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/x_size.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/y_size.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); - - aLbl = new QLabel(aGrpBox1); - aLbl->setPixmap(QPixmap(":pictures/z_size.png")); - aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));*/ - - aMainLay->addStretch(1); - - QFrame* aFrm = new QFrame(aContent); - aFrm->setFrameStyle(QFrame::Sunken); - aFrm->setFrameShape(QFrame::Panel); - QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm); - aBtnLay->setContentsMargins(0, 0, 0, 0); - aMainLay->addWidget(aFrm); - - QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm); - aBtn->setFlat(true); - aBtnLay->addWidget(aBtn); - aBtnLay->addStretch(1); - aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm); - aBtn->setFlat(true); - aBtnLay->addWidget(aBtn); - aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm); - aBtn->setFlat(true); - aBtnLay->addWidget(aBtn); - - addDockWidget(Qt::RightDockWidgetArea, aPropPanel); -} \ No newline at end of file + QDockWidget* aPropPanel = new QDockWidget(this); + aPropPanel->setWindowTitle("Point"); + + QWidget* aContent = new QWidget(aPropPanel); + QVBoxLayout* aMainLay = new QVBoxLayout(aContent); + aMainLay->setContentsMargins(3, 3, 3, 3); + aPropPanel->setWidget(aContent); + + /*QWidget* aNameWgt = new QWidget(aContent); + QHBoxLayout* aNameLay = new QHBoxLayout(aNameWgt); + aNameLay->setContentsMargins(0,0,0,0); + aMainLay->addWidget(aNameWgt); + + aNameLay->addWidget(new QLabel("Name", aNameWgt)); + aNameLay->addWidget(new QLineEdit(aNameWgt));*/ + + QComboBox* aCombo = new QComboBox(aContent); + aCombo->addItem("By coordinates"); + aMainLay->addWidget(aCombo); + + QWidget* aGrpBox1 = new QWidget(aContent); + //aGrpBox1->setFlat(true); + QFormLayout* aFrmLay = new QFormLayout(aGrpBox1); + aFrmLay->setContentsMargins(0, 6, 0, 0); + aMainLay->addWidget(aGrpBox1); + + QLabel* aLbl = new QLabel(aGrpBox1); + aLbl->setPixmap(QPixmap(":pictures/x_point.png")); + aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); + + aLbl = new QLabel(aGrpBox1); + aLbl->setPixmap(QPixmap(":pictures/y_point.png")); + aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); + + aLbl = new QLabel(aGrpBox1); + aLbl->setPixmap(QPixmap(":pictures/z_point.png")); + aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); + + /* aGrpBox1 = new QGroupBox("Normal vector", aContent); + aGrpBox1->setFlat(true); + aFrmLay = new QFormLayout(aGrpBox1); + aFrmLay->setContentsMargins(0, 6, 0, 0); + aMainLay->addWidget(aGrpBox1); + + aLbl = new QLabel(aGrpBox1); + aLbl->setPixmap(QPixmap(":pictures/x_size.png")); + aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); + + aLbl = new QLabel(aGrpBox1); + aLbl->setPixmap(QPixmap(":pictures/y_size.png")); + aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1)); + + aLbl = new QLabel(aGrpBox1); + aLbl->setPixmap(QPixmap(":pictures/z_size.png")); + aFrmLay->addRow(aLbl, new QDoubleSpinBox(aGrpBox1));*/ + + aMainLay->addStretch(1); + + QFrame* aFrm = new QFrame(aContent); + aFrm->setFrameStyle(QFrame::Sunken); + aFrm->setFrameShape(QFrame::Panel); + QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm); + aBtnLay->setContentsMargins(0, 0, 0, 0); + aMainLay->addWidget(aFrm); + + QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm); + aBtn->setFlat(true); + aBtnLay->addWidget(aBtn); + aBtnLay->addStretch(1); + aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm); + aBtn->setFlat(true); + aBtnLay->addWidget(aBtn); + aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm); + aBtn->setFlat(true); + aBtnLay->addWidget(aBtn); + + addDockWidget(Qt::RightDockWidgetArea, aPropPanel); +} diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index 3b318389e..a4b05f3d9 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -8,36 +8,44 @@ class XGUI_Viewer; class QTreeWidget; class QMdiArea; -class XGUI_MainWindow : public QMainWindow +class XGUI_MainWindow: public QMainWindow { - Q_OBJECT +Q_OBJECT public: - XGUI_MainWindow(QWidget* parent = 0); - virtual ~XGUI_MainWindow(); + XGUI_MainWindow(QWidget* parent = 0); + virtual ~XGUI_MainWindow(); - XGUI_MainMenu* menuObject() const { return myMenuBar; } - - QTreeWidget* objectBrowser() const { return myObjectBrowser; } - void showObjectBrowser(); - void hideObjectBrowser(); + XGUI_MainMenu* menuObject() const + { + return myMenuBar; + } - QMdiArea* mdiArea() const; + QTreeWidget* objectBrowser() const + { + return myObjectBrowser; + } + void showObjectBrowser(); + void hideObjectBrowser(); - XGUI_Viewer* viewer() const { return myViewer; } + QMdiArea* mdiArea() const; -private: - //!! For test purposes only - //QWidget* getSubWindow(); + XGUI_Viewer* viewer() const + { + return myViewer; + } - void fillObjectBrowser(); - void addPropertyPanel(); +private: + //!! For test purposes only + //QWidget* getSubWindow(); + void fillObjectBrowser(); + void addPropertyPanel(); - XGUI_MainMenu* myMenuBar; - QTreeWidget* myObjectBrowser; + XGUI_MainMenu* myMenuBar; + QTreeWidget* myObjectBrowser; - XGUI_Viewer* myViewer; + XGUI_Viewer* myViewer; }; -#endif \ No newline at end of file +#endif diff --git a/src/XGUI/XGUI_MenuGroupPanel.cpp b/src/XGUI/XGUI_MenuGroupPanel.cpp index 3173f97aa..4be66cee3 100644 --- a/src/XGUI/XGUI_MenuGroupPanel.cpp +++ b/src/XGUI/XGUI_MenuGroupPanel.cpp @@ -8,68 +8,65 @@ #include -XGUI_MenuGroupPanel::XGUI_MenuGroupPanel(QWidget *parent) : - QWidget(parent), myNewRow(0), myNewCol(0), myMaxRow(1) +XGUI_MenuGroupPanel::XGUI_MenuGroupPanel(QWidget *parent) + : QWidget(parent), myNewRow(0), myNewCol(0), myMaxRow(1) { - myLayout = new QGridLayout(this); - myLayout->setSpacing(0); - myLayout->setMargin(0); - myLayout->setContentsMargins(0,0,0,0); + myLayout = new QGridLayout(this); + myLayout->setSpacing(0); + myLayout->setMargin(0); + myLayout->setContentsMargins(0, 0, 0, 0); } - void XGUI_MenuGroupPanel::addCommand(XGUI_Command* theAction) { - myActions[theAction] = theAction->requestWidget(this); - addWidget(myActions[theAction]); + myActions[theAction] = theAction->requestWidget(this); + addWidget(myActions[theAction]); } void XGUI_MenuGroupPanel::placeWidget(QWidget* theWgt) { - if (myMaxRow == myNewRow) { - myNewRow = 0; - myNewCol++; - } - myLayout->addWidget(theWgt, myNewRow, myNewCol, Qt::AlignLeft); - myNewRow++; + if (myMaxRow == myNewRow) { + myNewRow = 0; + myNewCol++; + } + myLayout->addWidget(theWgt, myNewRow, myNewCol, Qt::AlignLeft); + myNewRow++; } void XGUI_MenuGroupPanel::addWidget(QWidget* theWgt) { - placeWidget(theWgt); + placeWidget(theWgt); } - void XGUI_MenuGroupPanel::resizeEvent(QResizeEvent* theEvent) { - QWidget::resizeEvent(theEvent); - if (myActions.size() == 0) - return; + 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; + int aH = theEvent->size().height(); + int aMaxRow = (int) floor(double(aH / MIN_BUTTON_HEIGHT)); + if (aMaxRow == myMaxRow) + return; - myMaxRow = aMaxRow; - QListIterator aIt(myActions.values()); - myNewRow = 0; - myNewCol = 0; - while (aIt.hasNext()) { - placeWidget(aIt.next()); - } + myMaxRow = aMaxRow; + QListIterator aIt(myActions.values()); + myNewRow = 0; + myNewCol = 0; + while(aIt.hasNext()) { + placeWidget(aIt.next()); + } } -XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, const QString& theTitle, - const QString& theTip, - const QIcon& theIcon, +XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, const QString& theTitle, + const QString& theTip, const QIcon& theIcon, const QKeySequence& theKeys) { - XGUI_Command* aCommand = new XGUI_Command(theId, theIcon, theTitle, this); - aCommand->setToolTip(theTip); - if (!theKeys.isEmpty()) - aCommand->setShortcut(theKeys); + XGUI_Command* aCommand = new XGUI_Command(theId, theIcon, theTitle, this); + aCommand->setToolTip(theTip); + if (!theKeys.isEmpty()) + aCommand->setShortcut(theKeys); - addCommand(aCommand); - return aCommand; + addCommand(aCommand); + return aCommand; } diff --git a/src/XGUI/XGUI_MenuGroupPanel.h b/src/XGUI/XGUI_MenuGroupPanel.h index 9c72384d1..87f061b6e 100644 --- a/src/XGUI/XGUI_MenuGroupPanel.h +++ b/src/XGUI/XGUI_MenuGroupPanel.h @@ -1,4 +1,3 @@ - #ifndef XGUI_MenuGroupPanel_H #define XGUI_MenuGroupPanel_H @@ -8,31 +7,28 @@ class XGUI_Command; class QGridLayout; -class XGUI_MenuGroupPanel : public QWidget +class XGUI_MenuGroupPanel: public QWidget { - Q_OBJECT +Q_OBJECT public: - explicit XGUI_MenuGroupPanel(QWidget *parent = 0); + explicit XGUI_MenuGroupPanel(QWidget *parent = 0); - XGUI_Command* addFeature(const QString& theId, - const QString& theTitle, - const QString& theTip, - const QIcon& theIcon, - const QKeySequence& theKeys = QKeySequence()); + XGUI_Command* addFeature(const QString& theId, const QString& theTitle, const QString& theTip, + const QIcon& theIcon, const QKeySequence& theKeys = QKeySequence()); protected: - virtual void resizeEvent(QResizeEvent *theEvent); + virtual void resizeEvent(QResizeEvent *theEvent); private: - void addWidget(QWidget* theWgt); - void placeWidget(QWidget* theWgt); - void addCommand(XGUI_Command* theAction); - - QMap myActions; - QGridLayout* myLayout; - int myNewRow; - int myNewCol; - int myMaxRow; + void addWidget(QWidget* theWgt); + void placeWidget(QWidget* theWgt); + void addCommand(XGUI_Command* theAction); + + QMap myActions; + QGridLayout* myLayout; + int myNewRow; + int myNewCol; + int myMaxRow; }; #endif diff --git a/src/XGUI/XGUI_Module.h b/src/XGUI/XGUI_Module.h index cfb4d314e..1860462e2 100644 --- a/src/XGUI/XGUI_Module.h +++ b/src/XGUI/XGUI_Module.h @@ -1,24 +1,23 @@ -#ifndef XGUI_Module_H -#define XGUI_Module_H - -#include - -class XGUI_Command; - -class XGUI_Module -{ -public: - virtual void createFeatures() = 0; - virtual void featureCreated(XGUI_Command*) = 0; -}; - -//! This function must return a new module instance. -extern "C" -{ - typedef XGUI_Module* (*CREATE_FUNC)(XGUI_Workshop*); -} - -#define CREATE_MODULE "createModule" - - -#endif //XGUI_Module +#ifndef XGUI_Module_H +#define XGUI_Module_H + +#include + +class XGUI_Command; + +class XGUI_Module +{ +public: + virtual void createFeatures() = 0; + virtual void featureCreated(XGUI_Command*) = 0; +}; + +//! This function must return a new module instance. +extern "C" +{ +typedef XGUI_Module* (*CREATE_FUNC)(XGUI_Workshop*); +} + +#define CREATE_MODULE "createModule" + +#endif //XGUI_Module \ No newline at end of file diff --git a/src/XGUI/XGUI_RubberBand.cpp b/src/XGUI/XGUI_RubberBand.cpp index 64b3948e6..66140015b 100644 --- a/src/XGUI/XGUI_RubberBand.cpp +++ b/src/XGUI/XGUI_RubberBand.cpp @@ -1,240 +1,236 @@ -#include "XGUI_RubberBand.h" - -#include -#include -#include -#include -#include -#include -#include - -/*! - \class QtxAbstractRubberBand - \brief Analog of class QRubberBand with possibility of creation non-rectangular contour for selection. - - Currently this class does not support Style functionality in full. -*/ - -/*! - \brief Constructor - \param theParent parent widget - */ - -XGUI_AbstractRubberBand::XGUI_AbstractRubberBand( QWidget* theParent) - : QWidget( theParent ), - myPoints(), - myIsClosed( false ) -{ - setAttribute(Qt::WA_TransparentForMouseEvents); -#ifndef WIN32 - setAttribute(Qt::WA_NoSystemBackground); -#endif //WIN32 - setAttribute(Qt::WA_WState_ExplicitShowHide); - setVisible(false); - theParent->installEventFilter(this); - setGeometry( QRect(QPoint(0,0), theParent->size() ) ); -} - -/*! - \brief Destructor - */ -XGUI_AbstractRubberBand::~XGUI_AbstractRubberBand() -{ -} - -void XGUI_AbstractRubberBand::clearGeometry() -{ - myPoints.clear(); -} - -bool XGUI_AbstractRubberBand::isClosed() -{ - return myIsClosed; -} - -void XGUI_AbstractRubberBand::paintEvent( QPaintEvent* theEvent ) -{ - if ( !myPoints.empty() ) { - QPixmap tiledPixmap(16, 16); - - QPainter pixmapPainter(&tiledPixmap); - pixmapPainter.setPen(Qt::NoPen); - pixmapPainter.setBrush(QBrush( Qt::black, Qt::Dense4Pattern )); - pixmapPainter.setBackground(QBrush( Qt::white )); - pixmapPainter.setBackgroundMode(Qt::OpaqueMode); - pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height()); - pixmapPainter.end(); - // ### workaround for borked XRENDER - tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage()); - - QPainter aPainter( this ); - aPainter.setRenderHint( QPainter::Antialiasing ); - QRect r = myPoints.boundingRect(); - aPainter.setClipRegion( r.normalized().adjusted( -1, -1, 2, 2 ) ); - aPainter.drawTiledPixmap( 0, 0, width(), height(), tiledPixmap); - - aPainter.end(); - } -} - -void XGUI_AbstractRubberBand::showEvent( QShowEvent* theEvent ) -{ - raise(); - theEvent->ignore(); -} - -void XGUI_AbstractRubberBand::moveEvent( QMoveEvent* ) -{ -} - -void XGUI_AbstractRubberBand::resizeEvent( QResizeEvent* ) -{ -} - -bool XGUI_AbstractRubberBand::eventFilter( QObject* obj, QEvent* e ) -{ - if ( obj && obj == parent() && e->type() == QEvent::Resize ) { - QWidget* p = (QWidget*)parent(); - setGeometry( QRect(QPoint(0,0), p->size() ) ); - } - return QWidget::eventFilter( obj, e ); -} - -QRegion createRegion( const QPointF& p1, const QPointF& p2 ) -{ - if ( p1 == p2 ) - return QRegion(); - - QLineF n = QLineF( p1, p2 ).normalVector();//.unitVector(); - n.setLength( 1 ); - n.translate( p1 * -1 ); - QPointF nPoint = n.p2(); - - QPolygonF p; - p << p1 + nPoint << p2 + nPoint << p2 - nPoint << p1 - nPoint << p1 + nPoint; - - return QRegion( p.toPolygon() ); -} - -void XGUI_AbstractRubberBand::updateMask() -{ - QRegion r; - - QVectorIterator it(myPoints); - while( it.hasNext() ) { - QPoint p = it.next(); - if( !it.hasNext() ) - break; - - QPoint np = it.peekNext(); - - if ( p == np ) continue; - - r += createRegion( p, np ); - } - - if ( isClosed() ) - r += createRegion( myPoints.last(), myPoints.first() ); - - setMask( r ); -} - - -//********************************************************** -XGUI_RectRubberBand::XGUI_RectRubberBand(QWidget* parent) - :XGUI_AbstractRubberBand( parent ) -{ - myPoints.resize( 4 ); - myIsClosed = true; -} - -XGUI_RectRubberBand::~XGUI_RectRubberBand() -{ -} - -void XGUI_RectRubberBand::initGeometry( const QRect& theRect ) -{ - myPoints.clear(); - myPoints << theRect.topLeft() << theRect.topRight() << theRect.bottomRight() << theRect.bottomLeft(); - //setMask( QRegion( myPoints ) ); - updateMask(); -} - -void XGUI_RectRubberBand::setStartPoint( const QPoint& thePoint ) -{ - myPoints[0] = thePoint; - myPoints[1].setY( thePoint.y() ); - myPoints[3].setX( thePoint.x() ); - updateMask(); -} - -void XGUI_RectRubberBand::setEndPoint( const QPoint& thePoint) -{ - myPoints[2] = thePoint; - myPoints[1].setX( thePoint.x() ); - myPoints[3].setY( thePoint.y() ); - updateMask(); -} - -void XGUI_RectRubberBand::clearGeometry() -{ - QMutableVectorIterator i(myPoints); - while (i.hasNext()) { - i.next(); - i.setValue( QPoint( -1, -1 ) ); - } -} - -//********************************************************** -XGUI_PolyRubberBand::XGUI_PolyRubberBand(QWidget* parent) - :XGUI_AbstractRubberBand( parent ) -{ -} - -XGUI_PolyRubberBand::~XGUI_PolyRubberBand() -{ -} - -void XGUI_PolyRubberBand::initGeometry( const QPolygon& thePoints ) -{ - myPoints = thePoints; - updateMask(); -} - -void XGUI_PolyRubberBand::initGeometry( const QPoint& thePoint ) -{ - myPoints.clear(); - myPoints << thePoint; - updateMask(); -} - -void XGUI_PolyRubberBand::addNode( const QPoint& thePoint ) -{ - myPoints << thePoint; - updateMask(); -} - -void XGUI_PolyRubberBand::replaceLastNode( const QPoint& thePoint ) -{ - if ( !myPoints.empty() ) { - myPoints.pop_back(); - myPoints << thePoint; - updateMask(); - } -} - -void XGUI_PolyRubberBand::removeLastNode() -{ - if ( !myPoints.empty() ) { - myPoints.pop_back(); - updateMask(); - } -} - -void XGUI_PolyRubberBand::setClosed( bool theFlag ) -{ - if (myIsClosed != theFlag ) { - myIsClosed = theFlag; - updateMask(); - } -} +#include "XGUI_RubberBand.h" + +#include +#include +#include +#include +#include +#include +#include + +/*! + \class QtxAbstractRubberBand + \brief Analog of class QRubberBand with possibility of creation non-rectangular contour for selection. + + Currently this class does not support Style functionality in full. + */ + +/*! + \brief Constructor + \param theParent parent widget + */ + +XGUI_AbstractRubberBand::XGUI_AbstractRubberBand(QWidget* theParent) + : QWidget(theParent), myPoints(), myIsClosed(false) +{ + setAttribute(Qt::WA_TransparentForMouseEvents); +#ifndef WIN32 + setAttribute(Qt::WA_NoSystemBackground); +#endif //WIN32 setAttribute(Qt::WA_WState_ExplicitShowHide); setVisible(false); theParent->installEventFilter(this); + setGeometry(QRect(QPoint(0, 0), theParent->size())); +} + +/*! + \brief Destructor + */ +XGUI_AbstractRubberBand::~XGUI_AbstractRubberBand() +{ +} + +void XGUI_AbstractRubberBand::clearGeometry() +{ + myPoints.clear(); +} + +bool XGUI_AbstractRubberBand::isClosed() +{ + return myIsClosed; +} + +void XGUI_AbstractRubberBand::paintEvent(QPaintEvent* theEvent) +{ + if (!myPoints.empty()) { + QPixmap tiledPixmap(16, 16); + + QPainter pixmapPainter(&tiledPixmap); + pixmapPainter.setPen(Qt::NoPen); + pixmapPainter.setBrush(QBrush(Qt::black, Qt::Dense4Pattern)); + pixmapPainter.setBackground(QBrush(Qt::white)); + pixmapPainter.setBackgroundMode(Qt::OpaqueMode); + pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height()); + pixmapPainter.end(); + // ### workaround for borked XRENDER + tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage()); + + QPainter aPainter(this); + aPainter.setRenderHint(QPainter::Antialiasing); + QRect r = myPoints.boundingRect(); + aPainter.setClipRegion(r.normalized().adjusted(-1, -1, 2, 2)); + aPainter.drawTiledPixmap(0, 0, width(), height(), tiledPixmap); + + aPainter.end(); + } +} + +void XGUI_AbstractRubberBand::showEvent(QShowEvent* theEvent) +{ + raise(); + theEvent->ignore(); +} + +void XGUI_AbstractRubberBand::moveEvent(QMoveEvent*) +{ +} + +void XGUI_AbstractRubberBand::resizeEvent(QResizeEvent*) +{ +} + +bool XGUI_AbstractRubberBand::eventFilter(QObject* obj, QEvent* e) +{ + if (obj && obj == parent() && e->type() == QEvent::Resize) { + QWidget* p = (QWidget*) parent(); + setGeometry(QRect(QPoint(0, 0), p->size())); + } + return QWidget::eventFilter(obj, e); +} + +QRegion createRegion(const QPointF& p1, const QPointF& p2) +{ + if (p1 == p2) + return QRegion(); + + QLineF n = QLineF(p1, p2).normalVector(); //.unitVector(); + n.setLength(1); + n.translate(p1 * -1); + QPointF nPoint = n.p2(); + + QPolygonF p; + p << p1 + nPoint << p2 + nPoint << p2 - nPoint << p1 - nPoint << p1 + nPoint; + + return QRegion(p.toPolygon()); +} + +void XGUI_AbstractRubberBand::updateMask() +{ + QRegion r; + + QVectorIterator it(myPoints); + while(it.hasNext()) { + QPoint p = it.next(); + if (!it.hasNext()) + break; + + QPoint np = it.peekNext(); + + if (p == np) + continue; + + r += createRegion(p, np); + } + + if (isClosed()) + r += createRegion(myPoints.last(), myPoints.first()); + + setMask(r); +} + +//********************************************************** +XGUI_RectRubberBand::XGUI_RectRubberBand(QWidget* parent) + : XGUI_AbstractRubberBand(parent) +{ + myPoints.resize(4); + myIsClosed = true; +} + +XGUI_RectRubberBand::~XGUI_RectRubberBand() +{ +} + +void XGUI_RectRubberBand::initGeometry(const QRect& theRect) +{ + myPoints.clear(); + myPoints << theRect.topLeft() << theRect.topRight() << theRect.bottomRight() + << theRect.bottomLeft(); + //setMask( QRegion( myPoints ) ); + updateMask(); +} + +void XGUI_RectRubberBand::setStartPoint(const QPoint& thePoint) +{ + myPoints[0] = thePoint; + myPoints[1].setY(thePoint.y()); + myPoints[3].setX(thePoint.x()); + updateMask(); +} + +void XGUI_RectRubberBand::setEndPoint(const QPoint& thePoint) +{ + myPoints[2] = thePoint; + myPoints[1].setX(thePoint.x()); + myPoints[3].setY(thePoint.y()); + updateMask(); +} + +void XGUI_RectRubberBand::clearGeometry() +{ + QMutableVectorIterator i(myPoints); + while(i.hasNext()) { + i.next(); + i.setValue(QPoint(-1, -1)); + } +} + +//********************************************************** +XGUI_PolyRubberBand::XGUI_PolyRubberBand(QWidget* parent) + : XGUI_AbstractRubberBand(parent) +{ +} + +XGUI_PolyRubberBand::~XGUI_PolyRubberBand() +{ +} + +void XGUI_PolyRubberBand::initGeometry(const QPolygon& thePoints) +{ + myPoints = thePoints; + updateMask(); +} + +void XGUI_PolyRubberBand::initGeometry(const QPoint& thePoint) +{ + myPoints.clear(); + myPoints << thePoint; + updateMask(); +} + +void XGUI_PolyRubberBand::addNode(const QPoint& thePoint) +{ + myPoints << thePoint; + updateMask(); +} + +void XGUI_PolyRubberBand::replaceLastNode(const QPoint& thePoint) +{ + if (!myPoints.empty()) { + myPoints.pop_back(); + myPoints << thePoint; + updateMask(); + } +} + +void XGUI_PolyRubberBand::removeLastNode() +{ + if (!myPoints.empty()) { + myPoints.pop_back(); + updateMask(); + } +} + +void XGUI_PolyRubberBand::setClosed(bool theFlag) +{ + if (myIsClosed != theFlag) { + myIsClosed = theFlag; + updateMask(); + } +} diff --git a/src/XGUI/XGUI_RubberBand.h b/src/XGUI/XGUI_RubberBand.h index 2f620996e..7d9fc43b4 100644 --- a/src/XGUI/XGUI_RubberBand.h +++ b/src/XGUI/XGUI_RubberBand.h @@ -1,72 +1,68 @@ - #ifndef XGUI_RubberBand_H #define XGUI_RubberBand_H #include - -class XGUI_AbstractRubberBand : public QWidget +class XGUI_AbstractRubberBand: public QWidget { - Q_OBJECT +Q_OBJECT protected: - XGUI_AbstractRubberBand( QWidget* ); + XGUI_AbstractRubberBand(QWidget*); public: virtual ~XGUI_AbstractRubberBand(); - virtual void clearGeometry(); + virtual void clearGeometry(); - bool isClosed(); + bool isClosed(); protected: - virtual void paintEvent( QPaintEvent* ); - virtual void showEvent( QShowEvent* ); - virtual void moveEvent( QMoveEvent* ); - virtual void resizeEvent( QResizeEvent* ); + virtual void paintEvent(QPaintEvent*); + virtual void showEvent(QShowEvent*); + virtual void moveEvent(QMoveEvent*); + virtual void resizeEvent(QResizeEvent*); - virtual bool eventFilter( QObject*, QEvent* ); + virtual bool eventFilter(QObject*, QEvent*); - virtual void updateMask(); + virtual void updateMask(); protected: - QPolygon myPoints; + QPolygon myPoints; - bool myIsClosed; + bool myIsClosed; }; - class XGUI_RectRubberBand: public XGUI_AbstractRubberBand { - Q_OBJECT +Q_OBJECT public: - XGUI_RectRubberBand( QWidget* ); + XGUI_RectRubberBand(QWidget*); virtual ~XGUI_RectRubberBand(); - void initGeometry( const QRect& ); - void setStartPoint( const QPoint& ); - void setEndPoint( const QPoint& ); - - virtual void clearGeometry(); + void initGeometry(const QRect&); + void setStartPoint(const QPoint&); + void setEndPoint(const QPoint&); + + virtual void clearGeometry(); }; class XGUI_PolyRubberBand: public XGUI_AbstractRubberBand { - Q_OBJECT +Q_OBJECT public: - XGUI_PolyRubberBand( QWidget* ); + XGUI_PolyRubberBand(QWidget*); virtual ~XGUI_PolyRubberBand(); - void initGeometry( const QPolygon& ); - void initGeometry( const QPoint& ); + void initGeometry(const QPolygon&); + void initGeometry(const QPoint&); - void addNode( const QPoint& ); - void replaceLastNode( const QPoint& ); - void removeLastNode(); + void addNode(const QPoint&); + void replaceLastNode(const QPoint&); + void removeLastNode(); - void setClosed( bool ); + void setClosed(bool); }; - -#endif \ No newline at end of file +#endif diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 5a6edb29d..bc462b800 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -1,83 +1,79 @@ - #include "XGUI_Tools.h" #include - //****************************************************************** -QString library( const QString& str ) +QString library(const QString& str) { - QString path = dir( str, false ); - QString name = file( str, false ); - QString ext = extension( str ); + QString path = dir(str, false); + QString name = file(str, false); + QString ext = extension(str); #ifndef WIN32 if ( !name.startsWith( "lib" ) ) - name = QString( "lib" ) + name; + name = QString( "lib" ) + name; #endif #ifdef WIN32 - QString libExt( "dll" ); + QString libExt("dll"); #else QString libExt( "so" ); #endif - if ( ext.toLower() != QString( "so" ) && ext.toLower() != QString( "dll" ) ) - { - if ( !name.isEmpty() && !ext.isEmpty() ) - name += QString( "." ); + if (ext.toLower() != QString("so") && ext.toLower() != QString("dll")) { + if (!name.isEmpty() && !ext.isEmpty()) + name += QString("."); name += ext; } ext = libExt; - QString fileName = addSlash( path ) + name + QString( "." ) + ext; + QString fileName = addSlash(path) + name + QString(".") + ext; return fileName; } //****************************************************************** -QString dir( const QString& path, bool isAbs ) +QString dir(const QString& path, bool isAbs) { - QDir aDir = QFileInfo( path ).dir(); + QDir aDir = QFileInfo(path).dir(); QString dirPath = isAbs ? aDir.absolutePath() : aDir.path(); - if ( dirPath == QString( "." ) ) + if (dirPath == QString(".")) dirPath = QString(); return dirPath; } - //****************************************************************** -QString file( const QString& path, bool withExt ) +QString file(const QString& path, bool withExt) { QString fPath = path; - while ( !fPath.isEmpty() && ( fPath[fPath.length() - 1] =='\\' || fPath[fPath.length() - 1] == '/' ) ) - fPath.remove( fPath.length() - 1, 1 ); + while(!fPath.isEmpty() && (fPath[fPath.length() - 1] == '\\' || fPath[fPath.length() - 1] == '/')) + fPath.remove(fPath.length() - 1, 1); - if ( withExt ) - return QFileInfo( fPath ).fileName(); + if (withExt) + return QFileInfo(fPath).fileName(); else - return QFileInfo( fPath ).completeBaseName(); + return QFileInfo(fPath).completeBaseName(); } //****************************************************************** -QString extension( const QString& path, bool full ) +QString extension(const QString& path, bool full) { - return full ? QFileInfo( path ).completeSuffix() : QFileInfo( path ).suffix(); + return full ? QFileInfo(path).completeSuffix() : QFileInfo(path).suffix(); } //****************************************************************** -QString addSlash( const QString& path ) +QString addSlash(const QString& path) { QString res = path; - if ( !res.isEmpty() && res.at( res.length() - 1 ) != QChar( '/' ) && - res.at( res.length() - 1 ) != QChar( '\\' ) ) - res += QDir::separator(); + if (!res.isEmpty() && res.at(res.length() - 1) != QChar('/') + && res.at(res.length() - 1) != QChar('\\')) + res += QDir::separator(); 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 ) ); +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)); } diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index f45575eea..e60684c75 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -1,4 +1,3 @@ - #ifndef XGUI_Tools_H #define XGUI_Tools_H @@ -6,66 +5,63 @@ #include /*! - \brief Convert the given parameter to the platform-specific library name. + \brief Convert the given parameter to the platform-specific library name. - The function appends platform-specific prefix (lib) and suffix (.dll/.so) - to the library file name. - For example, if \a str = "mylib", "libmylib.so" is returned for Linux and - mylib.dll for Windows. + The function appends platform-specific prefix (lib) and suffix (.dll/.so) + to the library file name. + For example, if \a str = "mylib", "libmylib.so" is returned for Linux and + mylib.dll for Windows. - \param str short library name - \return full library name -*/ -QString library( const QString& str ); + \param str short library name + \return full library name + */ +QString library(const QString& str); /*! - \brief Return directory part of the file path. - - If the file path does not include directory part (the file is in the - current directory), null string is returned. + \brief Return directory part of the file path. - \param path file path - \param abs if true (default) \a path parameter is treated as absolute file path - \return directory part of the file path -*/ -QString dir( const QString& path, bool isAbs = true); + If the file path does not include directory part (the file is in the + current directory), null string is returned. + \param path file path + \param abs if true (default) \a path parameter is treated as absolute file path + \return directory part of the file path + */ +QString dir(const QString& path, bool isAbs = true); /*! - \brief Return file name part of the file path. + \brief Return file name part of the file path. - \param path file path - \param withExt if true (default) complete file name (with all - extension except the last) is returned, otherwise only base name - is returned - \return file name part of the file path -*/ -QString file( const QString& path, bool withExt = true ); + \param path file path + \param withExt if true (default) complete file name (with all + extension except the last) is returned, otherwise only base name + is returned + \return file name part of the file path + */ +QString 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 extension( const QString& path, bool full = false ); + \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 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. - \param path directory path - \return modified path (with slash added to the end) -*/ -QString addSlash( const QString& path ); + \brief Add a slash (platform-specific) to the end of \a path + if it is not already there. + \param path directory path + \return modified path (with slash added to the end) + */ +QString addSlash(const QString& path); /*! - Creates a rect with TopLeft = ( min(x1,x2), min(y1,y2) ) - and BottomRight = ( TopLeft + (x2-x1)(y2-y1) ) -*/ -QRect makeRect( const int x1, const int y1, const int x2, const int y2 ); - + Creates a rect with TopLeft = ( min(x1,x2), min(y1,y2) ) + and BottomRight = ( TopLeft + (x2-x1)(y2-y1) ) + */ +QRect makeRect(const int x1, const int y1, const int x2, const int y2); -#endif \ No newline at end of file +#endif diff --git a/src/XGUI/XGUI_ViewBackground.cpp b/src/XGUI/XGUI_ViewBackground.cpp index 0c9d50543..580f4cff0 100644 --- a/src/XGUI/XGUI_ViewBackground.cpp +++ b/src/XGUI/XGUI_ViewBackground.cpp @@ -1,214 +1,201 @@ #include "XGUI_ViewBackground.h" - /*! - \brief Default constructor. - Creates invalid background data. -*/ + \brief Default constructor. + Creates invalid background data. + */ XGUI_ViewBackground::XGUI_ViewBackground() - : myTextureMode( XGUI::CenterTexture ), - myGradientType( XGUI::NoGradient ), - myTextureShown( false ) + : myTextureMode(XGUI::CenterTexture), myGradientType(XGUI::NoGradient), myTextureShown(false) { - setMode( XGUI::NoBackground ); + 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 ) + \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 ); + 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 ) + \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 ); + 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 ) + \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 ); + setGradient(grad); } /*! - \brief Destructor. -*/ + \brief Destructor. + */ XGUI_ViewBackground::~XGUI_ViewBackground() { } /*! - \brief Compares two background data objects -*/ -bool XGUI_ViewBackground::operator==( const XGUI_ViewBackground& other ) const + \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 ); + 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() -*/ + \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 + \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. + \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. + \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 ) + \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() -*/ + \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 ) + \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() -*/ + \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 ) + \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 ); + 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 + \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() ); + 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 ) + \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 ); + 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() -*/ + \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 ) + \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 ); + setMode(XGUI::CustomGradientBackground); } diff --git a/src/XGUI/XGUI_ViewBackground.h b/src/XGUI/XGUI_ViewBackground.h index 1906001da..749f21b38 100644 --- a/src/XGUI/XGUI_ViewBackground.h +++ b/src/XGUI/XGUI_ViewBackground.h @@ -1,4 +1,3 @@ - #ifndef XGUI_ViewBackground_H #define XGUI_ViewBackground_H @@ -12,90 +11,98 @@ typedef QList 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_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_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& ); - + 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; + XGUI::BackgroundMode myMode; + XGUI::TextureMode myTextureMode; + QString myFileName; + QColorList myColors; + XGUI::GradientType myGradientType; + QGradient myGradient; + bool myTextureShown; }; -#endif \ No newline at end of file +#endif diff --git a/src/XGUI/XGUI_ViewPort.cpp b/src/XGUI/XGUI_ViewPort.cpp index b8ec91582..997845808 100644 --- a/src/XGUI/XGUI_ViewPort.cpp +++ b/src/XGUI/XGUI_ViewPort.cpp @@ -31,23 +31,20 @@ #include - 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 ) + 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; + Aspect_Handle aWindowHandle = (Aspect_Handle) winId; #ifdef WIN32 - Handle(WNT_Window) viewWindow = new WNT_Window( aWindowHandle ); + 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 ); @@ -55,15 +52,13 @@ Handle(Aspect_Window) CreateCasWindow( const Handle(V3d_View)& view, WId winId ) return viewWindow; } - - class OpenGLUtils_FrameBuffer { public: OpenGLUtils_FrameBuffer(); ~OpenGLUtils_FrameBuffer(); - bool init( const GLsizei&, const GLsizei& ); + bool init(const GLsizei&, const GLsizei&); void release(); void bind(); @@ -75,7 +70,6 @@ private: GLuint rboId; }; - #ifndef APIENTRY #define APIENTRY #endif @@ -103,16 +97,21 @@ private: #define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 #endif -typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint *framebuffers); -typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer); -typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target); -typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint *framebuffers); -typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers); -typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC)(GLsizei n, GLuint *framebuffers); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC)(GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)(GLenum target, GLenum attachment, + GLenum textarget, GLuint texture, + GLint level); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)(GLenum target); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC)(GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC)(GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC)(GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC)(GLenum target, GLenum internalformat, + GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)(GLenum target, GLenum attachment, + GLenum renderbuffertarget, + GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC)(GLsizei n, const GLuint *renderbuffers); static PFNGLGENFRAMEBUFFERSEXTPROC vglGenFramebuffersEXT = NULL; static PFNGLBINDFRAMEBUFFEREXTPROC vglBindFramebufferEXT = NULL; @@ -133,21 +132,29 @@ static PFNGLDELETERENDERBUFFERSEXTPROC vglDeleteRenderbuffersEXT = NULL; bool InitializeEXT() { - vglGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)GL_GetProcAddress( "glGenFramebuffersEXT" ); - vglBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)GL_GetProcAddress( "glBindFramebufferEXT" ); - vglFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)GL_GetProcAddress( "glFramebufferTexture2DEXT" ); - vglCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)GL_GetProcAddress( "glCheckFramebufferStatusEXT" ); - vglDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)GL_GetProcAddress( "glDeleteFramebuffersEXT" ); - vglGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC)GL_GetProcAddress( "glGenRenderbuffersEXT" ); - vglBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC)GL_GetProcAddress( "glBindRenderbufferEXT" ); - vglRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC)GL_GetProcAddress( "glRenderbufferStorageEXT" ); - vglFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)GL_GetProcAddress( "glFramebufferRenderbufferEXT" ); - vglDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC)GL_GetProcAddress( "glDeleteRenderbuffersEXT" ); - - bool ok = vglGenFramebuffersEXT && vglBindFramebufferEXT && vglFramebufferTexture2DEXT && - vglCheckFramebufferStatusEXT && vglDeleteFramebuffersEXT && vglGenRenderbuffersEXT && - vglBindRenderbufferEXT && vglRenderbufferStorageEXT && vglFramebufferRenderbufferEXT && - vglDeleteRenderbuffersEXT; + vglGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC) GL_GetProcAddress("glGenFramebuffersEXT"); + vglBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC) GL_GetProcAddress("glBindFramebufferEXT"); + vglFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) GL_GetProcAddress( + "glFramebufferTexture2DEXT"); + vglCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) GL_GetProcAddress( + "glCheckFramebufferStatusEXT"); + vglDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC) GL_GetProcAddress( + "glDeleteFramebuffersEXT"); + vglGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC) GL_GetProcAddress( + "glGenRenderbuffersEXT"); + vglBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC) GL_GetProcAddress( + "glBindRenderbufferEXT"); + vglRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC) GL_GetProcAddress( + "glRenderbufferStorageEXT"); + vglFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) GL_GetProcAddress( + "glFramebufferRenderbufferEXT"); + vglDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC) GL_GetProcAddress( + "glDeleteRenderbuffersEXT"); + + bool ok = vglGenFramebuffersEXT && vglBindFramebufferEXT && vglFramebufferTexture2DEXT + && vglCheckFramebufferStatusEXT && vglDeleteFramebuffersEXT && vglGenRenderbuffersEXT + && vglBindRenderbufferEXT && vglRenderbufferStorageEXT && vglFramebufferRenderbufferEXT + && vglDeleteRenderbuffersEXT; return ok; } @@ -155,9 +162,7 @@ bool InitializeEXT() static bool IsEXTInitialized = InitializeEXT(); OpenGLUtils_FrameBuffer::OpenGLUtils_FrameBuffer() - : textureId( 0 ), - fboId( 0 ), - rboId( 0 ) + : textureId(0), fboId(0), rboId(0) { } @@ -166,111 +171,107 @@ OpenGLUtils_FrameBuffer::~OpenGLUtils_FrameBuffer() release(); } -bool OpenGLUtils_FrameBuffer::init( const GLsizei& xSize, const GLsizei& ySize ) +bool OpenGLUtils_FrameBuffer::init(const GLsizei& xSize, const GLsizei& ySize) { - char* ext = (char*)glGetString( GL_EXTENSIONS ); - if( !IsEXTInitialized || - strstr( ext, "GL_EXT_framebuffer_object" ) == NULL ) - { - qDebug( "Initializing OpenGL FrameBuffer extension failed" ); + char* ext = (char*) glGetString(GL_EXTENSIONS); + if (!IsEXTInitialized || strstr(ext, "GL_EXT_framebuffer_object") == NULL) { + qDebug( "Initializing OpenGL FrameBuffer extension failed"); return false; } // create a texture object - glEnable( GL_TEXTURE_2D ); - glGenTextures( 1, &textureId ); - glBindTexture( GL_TEXTURE_2D, textureId ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, xSize, ySize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); - glBindTexture( GL_TEXTURE_2D, 0 ); + glEnable (GL_TEXTURE_2D); + glGenTextures(1, &textureId); + glBindTexture(GL_TEXTURE_2D, textureId); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, xSize, ySize, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, 0); // create a renderbuffer object to store depth info - vglGenRenderbuffersEXT( 1, &rboId ); - vglBindRenderbufferEXT( GL_RENDERBUFFER_EXT, rboId ); - vglRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, xSize, ySize ); - vglBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0 ); + vglGenRenderbuffersEXT(1, &rboId); + vglBindRenderbufferEXT( GL_RENDERBUFFER_EXT, rboId); + vglRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, xSize, ySize); + vglBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0); // create a framebuffer object - vglGenFramebuffersEXT( 1, &fboId ); - vglBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fboId ); + vglGenFramebuffersEXT(1, &fboId); + vglBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fboId); // attach the texture to FBO color attachment point - vglFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0 ); + vglFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, + textureId, 0); // attach the renderbuffer to depth attachment point - vglFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboId ); + vglFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, + GL_RENDERBUFFER_EXT, + rboId); // check FBO status - GLenum status = vglCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT ); + GLenum status = vglCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT); // Unbind FBO - vglBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); + vglBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0); return status == GL_FRAMEBUFFER_COMPLETE_EXT; } void OpenGLUtils_FrameBuffer::release() { - if( !IsEXTInitialized ) + if (!IsEXTInitialized) return; - glDeleteTextures( 1, &textureId ); + glDeleteTextures(1, &textureId); textureId = 0; - vglDeleteFramebuffersEXT( 1, &fboId ); + vglDeleteFramebuffersEXT(1, &fboId); fboId = 0; - vglDeleteRenderbuffersEXT( 1, &rboId ); + vglDeleteRenderbuffersEXT(1, &rboId); rboId = 0; } void OpenGLUtils_FrameBuffer::bind() { - if( !IsEXTInitialized ) + if (!IsEXTInitialized) return; - vglBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fboId ); + vglBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fboId); } void OpenGLUtils_FrameBuffer::unbind() { - if( !IsEXTInitialized ) + if (!IsEXTInitialized) return; - vglBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); + vglBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0); } - - //************************************************************************ //************************************************************************ //************************************************************************ -XGUI_ViewPort::XGUI_ViewPort(XGUI_ViewWindow* theParent, - const Handle(V3d_Viewer)& theViewer, - V3d_TypeOfView theType) : -QWidget(theParent), - myPaintersRedrawing(false), - myScale( 1.0 ), - myIsAdvancedZoomingEnabled( false ) +XGUI_ViewPort::XGUI_ViewPort(XGUI_ViewWindow* theParent, const Handle(V3d_Viewer)& theViewer, + V3d_TypeOfView theType) + : QWidget(theParent), myPaintersRedrawing(false), myScale(1.0), myIsAdvancedZoomingEnabled( + false) { - setMouseTracking( true ); - setBackgroundRole( QPalette::NoRole ); - - // set focus policy to threat QContextMenuEvent from keyboard - setFocusPolicy( Qt::StrongFocus ); - setAttribute( Qt::WA_PaintOnScreen ); - setAttribute( Qt::WA_NoSystemBackground ); - - 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); + setMouseTracking(true); + setBackgroundRole(QPalette::NoRole); + + // set focus policy to threat QContextMenuEvent from keyboard + setFocusPolicy(Qt::StrongFocus); + setAttribute(Qt::WA_PaintOnScreen); + setAttribute(Qt::WA_NoSystemBackground); + + 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); //setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background } @@ -281,315 +282,328 @@ XGUI_ViewPort::~XGUI_ViewPort() } //*********************************************** -bool XGUI_ViewPort::mapView( const Handle(V3d_View)& theView) +bool XGUI_ViewPort::mapView(const Handle(V3d_View)& theView) { - if ( !setWindow( theView ) ) - return false; + if (!setWindow(theView)) + return false; - if ( !mapped( theView ) ) { - theView->SetWindow( myWindow ); - if ( theView != activeView() ) - theView->View()->Deactivate(); - } + if (!mapped(theView)) { + theView->SetWindow(myWindow); + if (theView != activeView()) + theView->View()->Deactivate(); + } - /* create static trihedron (16551: EDF PAL 501) */ - //OCCViewer_ViewWindow* aVW = dynamic_cast( parentWidget()->parentWidget()->parentWidget() ); - //if ( aVW ) { - // OCCViewer_Viewer* aViewModel = dynamic_cast( aVW->getViewManager()->getViewModel() ); - // if ( aViewModel && aViewModel->isStaticTrihedronDisplayed() ){ - //theView->ZBufferTriedronSetup(); - theView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER ); - // } - //} + /* create static trihedron (16551: EDF PAL 501) */ + //OCCViewer_ViewWindow* aVW = dynamic_cast( parentWidget()->parentWidget()->parentWidget() ); + //if ( aVW ) { + // OCCViewer_Viewer* aViewModel = dynamic_cast( aVW->getViewManager()->getViewModel() ); + // if ( aViewModel && aViewModel->isStaticTrihedronDisplayed() ){ + //theView->ZBufferTriedronSetup(); + theView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER); + // } + //} - emit( vpMapped() ); + emit(vpMapped()); - return true; + return true; } //*********************************************** -bool XGUI_ViewPort::setWindow( const Handle(V3d_View)& theView) +bool XGUI_ViewPort::setWindow(const Handle(V3d_View)& theView) { - if ( !myWindow.IsNull() ) - return true; + if (!myWindow.IsNull()) + return true; - if ( theView.IsNull() ) - return false; + if (theView.IsNull()) + return false; - attachWindow( theView, CreateCasWindow( theView, winId() ) ); + attachWindow(theView, CreateCasWindow(theView, winId())); myWindow = theView->Window(); return !myWindow.IsNull(); } //*********************************************** -bool XGUI_ViewPort::mapped( const Handle(V3d_View)& theView) const +bool XGUI_ViewPort::mapped(const Handle(V3d_View)& theView) const { - return ( !theView.IsNull() && theView->View()->IsDefined() ); + 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 XGUI::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 XGUI::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 XGUI::CustomGradientBackground: - // NOT IMPLEMENTED YET + 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 XGUI::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 XGUI::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; - default: + 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; + } } - // 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(); - } + break; + } + case XGUI::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) +void XGUI_ViewPort::attachWindow(const Handle(V3d_View)& theView, + const Handle(Aspect_Window)& theWnd) { - if (!theView.IsNull()) { - theView->SetWindow( theWnd ); - updateBackground(); - } + if (!theView.IsNull()) { + theView->SetWindow(theWnd); + updateBackground(); + } } //*********************************************** -void XGUI_ViewPort::paintEvent( QPaintEvent* theEvent) +void XGUI_ViewPort::paintEvent(QPaintEvent* theEvent) { #ifndef WIN32 - /* X11 : map before show doesn't work */ - if ( !mapped( activeView() ) ) - mapView( activeView() ); + /* X11 : map before show doesn't work */ + if ( !mapped( activeView() ) ) + mapView( activeView() ); #endif - if ( !myWindow.IsNull() ) { - //QGuiApplication::sync(); - 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; + if (!myWindow.IsNull()) { + //QGuiApplication::sync(); + 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* ) +void XGUI_ViewPort::resizeEvent(QResizeEvent*) { #ifdef WIN32 - /* Win32 : map before first show to avoid flicker */ - if ( !mapped( activeView() ) ) - mapView( activeView() ); + /* Win32 : map before first show to avoid flicker */ + if (!mapped(activeView())) + mapView(activeView()); #endif - //QGuiApplication::sync(); - if ( !activeView().IsNull() ) - activeView()->MustBeResized(); + //QGuiApplication::sync(); + if (!activeView().IsNull()) + activeView()->MustBeResized(); } //*********************************************** QImage XGUI_ViewPort::dumpView(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(); - - OpenGLUtils_FrameBuffer aFrameBuffer; - if( aFrameBuffer.init( aWidth, aHeight ) ) - { - QImage anImage( aWidth, aHeight, QImage::Format_RGB32 ); - - glPushAttrib( GL_VIEWPORT_BIT ); - glViewport( 0, 0, aWidth, aHeight ); - aFrameBuffer.bind(); - - // draw scene - if (toUpdate) { - if (theRect.isNull()) - view->Redraw(); - else - view->Redraw(theRect.x(), theRect.y(), theRect.width(), theRect.height()); - } - aFrameBuffer.unbind(); - glPopAttrib(); - - aFrameBuffer.bind(); - if (theRect.isNull()) - glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() ); - else - glReadPixels( theRect.x(), theRect.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() ); - aFrameBuffer.unbind(); - - anImage = anImage.rgbSwapped(); - anImage = anImage.mirrored(); - return anImage; - } - // if frame buffers are unsupported, use old functionality - unsigned char* data = 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(); + 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(); + + OpenGLUtils_FrameBuffer aFrameBuffer; + if (aFrameBuffer.init(aWidth, aHeight)) { + QImage anImage(aWidth, aHeight, QImage::Format_RGB32); + + glPushAttrib (GL_VIEWPORT_BIT); + glViewport(0, 0, aWidth, aHeight); + aFrameBuffer.bind(); + + // draw scene + if (toUpdate) { + if (theRect.isNull()) + view->Redraw(); + else + view->Redraw(theRect.x(), theRect.y(), theRect.width(), theRect.height()); } - glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, data); + aFrameBuffer.unbind(); + glPopAttrib(); + + aFrameBuffer.bind(); + if (theRect.isNull()) + glReadPixels(0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits()); + else + glReadPixels(theRect.x(), theRect.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, + anImage.bits()); + aFrameBuffer.unbind(); - QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 ); - anImage = anImage.mirrored(); anImage = anImage.rgbSwapped(); + anImage = anImage.mirrored(); return anImage; -} + } + // if frame buffers are unsupported, use old functionality + unsigned char* data = 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, data); + QImage anImage(data, 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 ) + Inits 'rotation' transformation. + */ +void XGUI_ViewPort::startRotation(int x, int y, int theRotationPointType, + const gp_Pnt& theSelectedPoint) { - if ( !activeView().IsNull() ) { - switch ( theRotationPointType ) { + if (!activeView().IsNull()) { + switch(theRotationPointType) { case XGUI::GRAVITY: - activeView()->StartRotation( x, y, 0.45 ); + activeView()->StartRotation(x, y, 0.45); break; case XGUI::SELECTED: - sx = x; sy = y; + sx = x; + sy = y; - double X,Y; - activeView()->Size(X,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 ); + 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; + 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: @@ -600,119 +614,116 @@ void XGUI_ViewPort::startRotation( int x, int y, } /*! - Rotates the viewport. -*/ -void XGUI_ViewPort::rotate( int x, int y, - int theRotationPointType, - const gp_Pnt& theSelectedPoint ) + Rotates the viewport. + */ +void XGUI_ViewPort::rotate(int x, int y, int theRotationPointType, const gp_Pnt& theSelectedPoint) { - if ( !activeView().IsNull() ) { - switch ( theRotationPointType ) { + if (!activeView().IsNull()) { + switch(theRotationPointType) { case XGUI::GRAVITY: - activeView()->Rotation( x, y ); + 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); + 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; + } 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 ); + activeView()->Rotate(dx, dy, dz, theSelectedPoint.X(), theSelectedPoint.Y(), + theSelectedPoint.Z(), + Standard_False); break; default: break; } - emit vpTransformed( ); + emit vpTransformed(); } // setZSize( getZSize() ); } /*! - Resets the viewport after 'rotation'. -*/ + Resets the viewport after 'rotation'. + */ void XGUI_ViewPort::endRotation() { - if ( !activeView().IsNull() ) { + if (!activeView().IsNull()) { activeView()->ZFitAll(1.); activeView()->SetZSize(0.); activeView()->Update(); - emit vpTransformed( ); + emit vpTransformed(); } } /*! - Inits 'zoom' transformation. -*/ -void XGUI_ViewPort::startZoomAtPoint( int x, int y ) + Inits 'zoom' transformation. + */ +void XGUI_ViewPort::startZoomAtPoint(int x, int y) { - if ( !activeView().IsNull()/* && isAdvancedZoomingEnabled() */) - activeView()->StartZoomAtPoint( x, y ); + if (!activeView().IsNull()/* && isAdvancedZoomingEnabled() */) + activeView()->StartZoomAtPoint(x, y); } /*! - Centers the viewport. -*/ -void XGUI_ViewPort::setCenter( int x, int y ) + Centers the viewport. + */ +void XGUI_ViewPort::setCenter(int x, int y) { - if ( !activeView().IsNull() ) { - activeView()->Place( x, y, myScale ); - emit vpTransformed( ); + if (!activeView().IsNull()) { + activeView()->Place(x, y, myScale); + emit vpTransformed(); } } /*! - Called at 'pan' transformation. + Called at 'pan' transformation. */ -void XGUI_ViewPort::pan( int dx, int dy ) +void XGUI_ViewPort::pan(int dx, int dy) { - if ( !activeView().IsNull() ) { - activeView()->Pan( dx, dy, 1.0 ); - emit vpTransformed( ); + if (!activeView().IsNull()) { + activeView()->Pan(dx, dy, 1.0); + emit vpTransformed(); } } /*! - Called at 'window fit' transformation. -*/ -void XGUI_ViewPort::fitRect( const QRect& rect ) + 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( ); + 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 ) + 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 ); + if (!activeView().IsNull()) { + if (isAdvancedZoomingEnabled()) + activeView()->ZoomAtPoint(x0, y0, x, y); else - activeView()->Zoom( x0 + y0, 0, x + y, 0 ); - emit vpTransformed( ); + activeView()->Zoom(x0 + y0, 0, x + y, 0); + emit vpTransformed(); } } /*! - Sets the background data -*/ -void XGUI_ViewPort::setBackground( const XGUI_ViewBackground& bgData ) + Sets the background data + */ +void XGUI_ViewPort::setBackground(const XGUI_ViewBackground& bgData) { - if ( bgData.isValid() ) { - myBackground = bgData; - updateBackground(); - emit vpChangeBackground( myBackground ); - } + if (bgData.isValid()) { + myBackground = bgData; + updateBackground(); + emit vpChangeBackground(myBackground); + } } diff --git a/src/XGUI/XGUI_ViewPort.h b/src/XGUI/XGUI_ViewPort.h index cd79d564e..e03dad5d0 100644 --- a/src/XGUI/XGUI_ViewPort.h +++ b/src/XGUI/XGUI_ViewPort.h @@ -1,4 +1,3 @@ - #ifndef XGUI_ViewPort_H #define XGUI_ViewPort_H @@ -11,75 +10,87 @@ class XGUI_ViewWindow; -class XGUI_ViewPort : public QWidget +class XGUI_ViewPort: public QWidget { - Q_OBJECT +Q_OBJECT public: - XGUI_ViewPort(XGUI_ViewWindow* theParent, - const Handle(V3d_Viewer)& theViewer, - V3d_TypeOfView theType = V3d_ORTHOGRAPHIC); - ~XGUI_ViewPort(); - - virtual QPaintEngine* paintEngine() const { return 0; } - - QImage dumpView(QRect theRect = QRect(), bool toUpdate = true); + XGUI_ViewPort(XGUI_ViewWindow* theParent, const Handle(V3d_Viewer)& theViewer, + V3d_TypeOfView theType = V3d_ORTHOGRAPHIC); + ~XGUI_ViewPort(); + + virtual QPaintEngine* paintEngine() const + { + return 0; + } + + QImage dumpView(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 setAdvancedZoomingEnabled(const bool theState) + { + myIsAdvancedZoomingEnabled = theState; + } + bool isAdvancedZoomingEnabled() const + { + return myIsAdvancedZoomingEnabled; + } + + XGUI_ViewBackground background() const + { + return myBackground; + } + void setBackground(const XGUI_ViewBackground& bgData); - Handle(V3d_View) getView() const { return activeView(); } +signals: + void vpChangeBackground(const XGUI_ViewBackground&); + void vpClosed(); + void vpMapped(); + void vpTransformed(); + void vpUpdated(); - void startRotation( int x, int y, int theRotationPointType, const gp_Pnt& theSelectedPoint ); - void rotate( int, int, int, const gp_Pnt& ); - void endRotation(); +protected: + virtual void paintEvent(QPaintEvent*); + virtual void resizeEvent(QResizeEvent*); - // 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 ); +private: + Handle(V3d_View) activeView() const + { + return myActiveView; + } - void setAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; } - bool isAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; } + 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); - XGUI_ViewBackground background() const { return myBackground; } - void setBackground( const XGUI_ViewBackground& bgData ); + Handle(V3d_View) myOrthoView;Handle(V3d_View) myPerspView;Handle(V3d_View) myActiveView; -signals: - void vpChangeBackground( const XGUI_ViewBackground& ); - void vpClosed(); - void vpMapped(); - void vpTransformed( ); - void vpUpdated(); + Handle(Aspect_Window) myWindow; -protected: - virtual void paintEvent( QPaintEvent* ); - virtual void resizeEvent( QResizeEvent* ); + bool myPaintersRedrawing; + bool myIsAdvancedZoomingEnabled; + double myScale; -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; - - XGUI_ViewBackground myBackground; - int myBgImgHeight; - int myBgImgWidth; + XGUI_ViewBackground myBackground; + int myBgImgHeight; + int myBgImgWidth; }; - -#endif \ No newline at end of file +#endif diff --git a/src/XGUI/XGUI_ViewWindow.cpp b/src/XGUI/XGUI_ViewWindow.cpp index eb851c800..7d410b874 100644 --- a/src/XGUI/XGUI_ViewWindow.cpp +++ b/src/XGUI/XGUI_ViewWindow.cpp @@ -21,244 +21,175 @@ #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...............", - "................................", - "................................", - "................................", - "................................", - "................................", - "................................", - "................................"}; - +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...............", "................................", + "................................", "................................", + "................................", "................................", + "................................", "................................" }; //************************************************************************** -void ViewerToolbar::paintEvent( QPaintEvent* theEvent) +void ViewerToolbar::paintEvent(QPaintEvent* theEvent) { - //QTime aTime; - //aTime.start(); - 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())); - QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false)); - //QString aMsg = QString("### Painted in %1").arg(aTime.elapsed()); - //qDebug(qPrintable(aMsg)); + //QTime aTime; + //aTime.start(); + 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())); + QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false)); + //QString aMsg = QString("### Painted in %1").arg(aTime.elapsed()); + //qDebug(qPrintable(aMsg)); } //************************************************************************** -void ViewerLabel::paintEvent( QPaintEvent* theEvent) +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())); - QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false)); - QLabel::paintEvent(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())); + QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false)); + QLabel::paintEvent(theEvent); } //************************************************************************** //************************************************************************** //************************************************************************** -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) +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) { - 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); - aLay->addWidget(myViewPort); - - myPicture = new QLabel(); - myPicture->setFrameStyle(QFrame::Sunken); - myPicture->setFrameShape(QFrame::Panel); - myPicture->setMouseTracking(true); - myPicture->installEventFilter(this); - myPicture->hide(); - - QStringList aPictures; - aPictures<<":pictures/occ_view_camera_dump.png"<<":pictures/occ_view_style_switch.png"; - aPictures<<":pictures/occ_view_triedre.png"<<":pictures/occ_view_fitall.png"; - aPictures<<":pictures/occ_view_fitarea.png"<<":pictures/occ_view_zoom.png"; - aPictures<<":pictures/occ_view_pan.png"<<":pictures/occ_view_glpan.png"; - aPictures<<":pictures/occ_view_rotate.png"<<":pictures/occ_view_front.png"; - aPictures<<":pictures/occ_view_back.png"<<":pictures/occ_view_left.png"; - aPictures<<":pictures/occ_view_right.png"<<":pictures/occ_view_top.png"; - aPictures<<":pictures/occ_view_bottom.png"<<":pictures/occ_view_clone.png"; - - QStringList aTitles; - aTitles << "Dump view" << "Mouse style switch" << "Show trihedron" << "Fit all"; - aTitles << "Fit area" << "Zoom" << "Panning" << "Global panning" << "Rotate"; - aTitles << "Front" << "Back" << "Left" << "Right" << "Top" << "Bottom" << "Clone view"; - - myGripWgt = new ViewerLabel(this, myViewPort); - myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png")); - myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 2, 19, 32); - myGripWgt->setMouseTracking(true); - myGripWgt->installEventFilter(this); - connect(myViewPort, SIGNAL(vpTransformed()), myGripWgt, SLOT(update())); - connect(myViewPort, SIGNAL(vpUpdated()), myGripWgt, SLOT(update())); - - myViewBar = new ViewerToolbar(this, myViewPort); - - QAction* aBtn; - for (int i = 0; i < aTitles.length(); i++) { - aBtn = new QAction(QIcon(aPictures.at(i)), aTitles.at(i), myViewBar); - myViewBar->addAction(aBtn); - } - connect(myViewPort, SIGNAL(vpTransformed()), myViewBar, SLOT(update())); - connect(myViewPort, SIGNAL(vpUpdated()), myViewBar, SLOT(update())); - - myWindowBar = new ViewerToolbar(this, myViewPort); - connect(myViewPort, SIGNAL(vpTransformed()), myWindowBar, SLOT(update())); - connect(myViewPort, SIGNAL(vpUpdated()), myWindowBar, SLOT(update())); - - 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())); - - myViewBar->hide(); - myWindowBar->hide(); - myGripWgt->hide(); + 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); + aLay->addWidget(myViewPort); + + myPicture = new QLabel(); + myPicture->setFrameStyle(QFrame::Sunken); + myPicture->setFrameShape(QFrame::Panel); + myPicture->setMouseTracking(true); + myPicture->installEventFilter(this); + myPicture->hide(); + + QStringList aPictures; + aPictures << ":pictures/occ_view_camera_dump.png" << ":pictures/occ_view_style_switch.png"; + aPictures << ":pictures/occ_view_triedre.png" << ":pictures/occ_view_fitall.png"; + aPictures << ":pictures/occ_view_fitarea.png" << ":pictures/occ_view_zoom.png"; + aPictures << ":pictures/occ_view_pan.png" << ":pictures/occ_view_glpan.png"; + aPictures << ":pictures/occ_view_rotate.png" << ":pictures/occ_view_front.png"; + aPictures << ":pictures/occ_view_back.png" << ":pictures/occ_view_left.png"; + aPictures << ":pictures/occ_view_right.png" << ":pictures/occ_view_top.png"; + aPictures << ":pictures/occ_view_bottom.png" << ":pictures/occ_view_clone.png"; + + QStringList aTitles; + aTitles << "Dump view" << "Mouse style switch" << "Show trihedron" << "Fit all"; + aTitles << "Fit area" << "Zoom" << "Panning" << "Global panning" << "Rotate"; + aTitles << "Front" << "Back" << "Left" << "Right" << "Top" << "Bottom" << "Clone view"; + + myGripWgt = new ViewerLabel(this, myViewPort); + myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png")); + myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 2, 19, 32); + myGripWgt->setMouseTracking(true); + myGripWgt->installEventFilter(this); + connect(myViewPort, SIGNAL(vpTransformed()), myGripWgt, SLOT(update())); + connect(myViewPort, SIGNAL(vpUpdated()), myGripWgt, SLOT(update())); + + myViewBar = new ViewerToolbar(this, myViewPort); + + QAction* aBtn; + for(int i = 0; i < aTitles.length(); i++) { + aBtn = new QAction(QIcon(aPictures.at(i)), aTitles.at(i), myViewBar); + myViewBar->addAction(aBtn); + } + connect(myViewPort, SIGNAL(vpTransformed()), myViewBar, SLOT(update())); + connect(myViewPort, SIGNAL(vpUpdated()), myViewBar, SLOT(update())); + + myWindowBar = new ViewerToolbar(this, myViewPort); + connect(myViewPort, SIGNAL(vpTransformed()), myWindowBar, SLOT(update())); + connect(myViewPort, SIGNAL(vpUpdated()), myWindowBar, SLOT(update())); + + 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())); + + myViewBar->hide(); + myWindowBar->hide(); + myGripWgt->hide(); } //**************************************************************** @@ -269,203 +200,201 @@ XGUI_ViewWindow::~XGUI_ViewWindow() //**************************************************************** void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent) { - QSize aSize = theEvent->size(); - QSize aWndBarSize = myWindowBar->sizeHint(); - QSize myViewBarSize = myViewBar->sizeHint(); - - myWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE - 4, BORDER_SIZE + 2); - int aViewBarWidth = aSize.width() - aWndBarSize.width() - myGripWgt->width() - 8; - if (aViewBarWidth > myViewBarSize.width()) - aViewBarWidth = myViewBarSize.width(); - myViewBar->setGeometry(BORDER_SIZE + 18, BORDER_SIZE + 2, aViewBarWidth, myViewBarSize.height()); + QSize aSize = theEvent->size(); + QSize aWndBarSize = myWindowBar->sizeHint(); + QSize myViewBarSize = myViewBar->sizeHint(); + + myWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE - 4, + BORDER_SIZE + 2); + int aViewBarWidth = aSize.width() - aWndBarSize.width() - myGripWgt->width() - 8; + if (aViewBarWidth > myViewBarSize.width()) + aViewBarWidth = myViewBarSize.width(); + myViewBar->setGeometry(BORDER_SIZE + 18, BORDER_SIZE + 2, aViewBarWidth, myViewBarSize.height()); } //**************************************************************** void XGUI_ViewWindow::changeEvent(QEvent* theEvent) { - if (theEvent->type() == QEvent::WindowStateChange) { - if (isMinimized()) { - if (!myPicture->parentWidget()) { - QMdiSubWindow* aParent = static_cast(parentWidget()); - QMdiArea* aMDIArea = aParent->mdiArea(); - myPicture->setParent(aMDIArea); - } - myPicture->move(parentWidget()->x(), parentWidget()->y()); - myPicture->show(); - } else { - myPicture->hide(); - if (isMaximized()) { - myMinimizeBtn->setIcon(MinimizeIco); - myMaximizeBtn->setIcon(RestoreIco); - } - } - } else - QWidget::changeEvent(theEvent); + if (theEvent->type() == QEvent::WindowStateChange) { + if (isMinimized()) { + if (!myPicture->parentWidget()) { + QMdiSubWindow* aParent = static_cast(parentWidget()); + QMdiArea* aMDIArea = aParent->mdiArea(); + myPicture->setParent(aMDIArea); + } + myPicture->move(parentWidget()->x(), parentWidget()->y()); + myPicture->show(); + } else { + myPicture->hide(); + if (isMaximized()) { + myMinimizeBtn->setIcon(MinimizeIco); + myMaximizeBtn->setIcon(RestoreIco); + } + } + } else + QWidget::changeEvent(theEvent); } //**************************************************************** void XGUI_ViewWindow::onClose() { - if (parentWidget()) - parentWidget()->close(); + if (parentWidget()) + parentWidget()->close(); } //**************************************************************** void XGUI_ViewWindow::enterEvent(QEvent* theEvent) { - if (!isMinimized()) { - myViewBar->show(); - if (!isMaximized()) - myGripWgt->show(); - } - myWindowBar->show(); + if (!isMinimized()) { + myViewBar->show(); + if (!isMaximized()) + myGripWgt->show(); + } + myWindowBar->show(); } //**************************************************************** void XGUI_ViewWindow::leaveEvent(QEvent* theEvent) { - myViewBar->hide(); - myGripWgt->hide(); - myWindowBar->hide(); + myViewBar->hide(); + myGripWgt->hide(); + myWindowBar->hide(); } //**************************************************************** void XGUI_ViewWindow::onMinimize() { - QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView()); - int aW = width(); - int aH = height(); - double aR = aW / 100.; - myPicture->setPixmap(aPMap.scaled(100, int(aH / aR))); - - myLastState = isMaximized()? MaximizedState : NormalState; - showMinimized(); + QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView()); + int aW = width(); + int aH = height(); + double aR = aW / 100.; + myPicture->setPixmap(aPMap.scaled(100, int(aH / aR))); + + myLastState = isMaximized() ? MaximizedState : NormalState; + showMinimized(); } //**************************************************************** void XGUI_ViewWindow::onMaximize() { - if (isMaximized()) { - myMaximizeBtn->setIcon(MaximizeIco); - myGripWgt->show(); - showNormal(); - } else { - myMaximizeBtn->setIcon(RestoreIco); - myGripWgt->hide(); - showMaximized(); - } - myMinimizeBtn->setIcon(MinimizeIco); + if (isMaximized()) { + myMaximizeBtn->setIcon(MaximizeIco); + myGripWgt->show(); + showNormal(); + } else { + myMaximizeBtn->setIcon(RestoreIco); + myGripWgt->hide(); + showMaximized(); + } + myMinimizeBtn->setIcon(MinimizeIco); } //**************************************************************** bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent) { - QWidget* aWgt = (theObj == myPicture)? myPicture : static_cast(parentWidget()); - switch (theEvent->type()) { - case QEvent::MouseButtonPress: - { - QMouseEvent* aEvent = static_cast(theEvent); - if ((aEvent->button() == Qt::LeftButton) && (!myMoving)){ - myMoving = true; - myMousePnt = aEvent->globalPos(); - return true; - } - } - break; - case QEvent::MouseButtonRelease: - { - QMouseEvent* aEvent = static_cast(theEvent); - if ((aEvent->button() == Qt::LeftButton) && myMoving) { - myMoving = false; - return true; - } - } - break; - case QEvent::MouseMove: - { - QMouseEvent* aEvent = static_cast(theEvent); - if (myMoving) { - QMdiSubWindow* aParent = static_cast(parentWidget()); - QMdiArea* aMDIArea = aParent->mdiArea(); - - QPoint aPnt = aEvent->globalPos(); - QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt); - if (aMDIArea->rect().contains(aMDIPnt)) { - int aX = aWgt->x() + (aPnt.x() - myMousePnt.x()); - int aY = aWgt->y() + (aPnt.y() - myMousePnt.y()); - aWgt->move(aX, aY); - myMousePnt = aPnt; - } - return true; - } - } - break; - case QEvent::MouseButtonDblClick: - if (theObj == myPicture) { - myMoving = false; - if (myLastState == MaximizedState) - showMaximized(); - else - showNormal(); - return true; - } + QWidget* aWgt = (theObj == myPicture) ? myPicture : static_cast(parentWidget()); + switch(theEvent->type()) { + case QEvent::MouseButtonPress: { + QMouseEvent* aEvent = static_cast(theEvent); + if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) { + myMoving = true; + myMousePnt = aEvent->globalPos(); + return true; + } + } + break; + case QEvent::MouseButtonRelease: { + QMouseEvent* aEvent = static_cast(theEvent); + if ((aEvent->button() == Qt::LeftButton) && myMoving) { + myMoving = false; + return true; } - return false; + } + break; + case QEvent::MouseMove: { + QMouseEvent* aEvent = static_cast(theEvent); + if (myMoving) { + QMdiSubWindow* aParent = static_cast(parentWidget()); + QMdiArea* aMDIArea = aParent->mdiArea(); + + QPoint aPnt = aEvent->globalPos(); + QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt); + if (aMDIArea->rect().contains(aMDIPnt)) { + int aX = aWgt->x() + (aPnt.x() - myMousePnt.x()); + int aY = aWgt->y() + (aPnt.y() - myMousePnt.y()); + aWgt->move(aX, aY); + myMousePnt = aPnt; + } + return true; + } + } + break; + case QEvent::MouseButtonDblClick: + if (theObj == myPicture) { + myMoving = false; + if (myLastState == MaximizedState) + showMaximized(); + else + showNormal(); + 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; - } - return false; + 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; + } + 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; - } - return QFrame::eventFilter(theObj, theEvent); + if ((theObj == myGripWgt) || (theObj == myPicture)) { + if (processWindowControls(theObj, theEvent)) + return true; + } else if (theObj == myViewPort) { + if (processViewPort(theEvent)) + return true; + } + return QFrame::eventFilter(theObj, theEvent); } //**************************************************************** -XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(QMouseEvent* theEvent, - XGUI::InteractionStyle theInteractionStyle) +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]) ) + 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]) ) + 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)) + 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; @@ -474,429 +403,428 @@ XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(QMouseEvent* theE //**************************************************************** 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; + 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); } - - switch ( myOperation ) { - case WINDOWFIT: - if ( theEvent->button() == Qt::LeftButton ) - emit vpTransformationStarted ( WINDOWFIT ); - break; - - case PANGLOBAL: - if ( theEvent->button() == Qt::LeftButton ) - emit vpTransformationStarted ( PANGLOBAL ); - break; - + 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: - if ( theEvent->button() == Qt::LeftButton ) { - myViewPort->startZoomAtPoint( myStartX, myStartY ); - emit vpTransformationStarted ( ZOOMVIEW ); - } - break; - + myViewPort->startZoomAtPoint(myStartX, myStartY); + activateZoom(); + break; case PANVIEW: - if ( aSwitchToZoom ) { - myViewPort->startZoomAtPoint( myStartX, myStartY ); - activateZoom(); - } else if ( theEvent->button() == Qt::LeftButton ) - emit vpTransformationStarted ( PANVIEW ); - break; - + activatePanning(); + 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; - + activateRotation(); + myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint); + 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; + 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; } - /* notify that we start a transformation */ - if ( transformRequested() ) - emit vpTransformationStarted ( myOperation ); + } else + emit mousePressed(this, theEvent); + break; } - if ( transformRequested() ) - setTransformInProcess( true ); - - /* we may need it for sketching... */ -/* if ( l_mbPressEvent ) - delete l_mbPressEvent; - l_mbPressEvent = new QMouseEvent( *theEvent );*/ + /* 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::vpMouseReleaseEvent(QMouseEvent* theEvent) { - switch ( myOperation ) { - case NOTHING: - { - int prevState = myCurSketch; -/* if(theEvent->button() == Qt::RightButton) { - QList::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); - if (theEvent->button() == Qt::RightButton && prevState == -1) { - QContextMenuEvent aEvent( QContextMenuEvent::Mouse, - theEvent->pos(), theEvent->globalPos() ); - emit contextMenuRequested( &aEvent ); - } - } - 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 = makeRect(myStartX, myStartY, myCurrX, myCurrY); - if ( !rect.isEmpty() ) myViewPort->fitRect(rect); - endDrawRect(); - resetState(); - } - break; + switch(myOperation) { + case NOTHING: { + int prevState = myCurSketch; + /* if(theEvent->button() == Qt::RightButton) { + QList::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); + if (theEvent->button() == Qt::RightButton && prevState == -1) { + QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos()); + emit contextMenuRequested(&aEvent); } - - // 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(); + } + 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(); } -/* if ( l_mbPressEvent ) { - delete l_mbPressEvent; - l_mbPressEvent = 0; - }*/ + break; + + case WINDOWFIT: + if (theEvent->button() == Qt::LeftButton) { + myCurrX = theEvent->x(); + myCurrY = theEvent->y(); + drawRect(); + QRect rect = 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; - + if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) { + myIsKeyFree = false; + switch(getButtonState(theEvent, interactionStyle())) { case ZOOMVIEW: - myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY); - myStartX = myCurrX; - myStartY = myCurrY; - break; - + myViewPort->startZoomAtPoint(myStartX, myStartY); + activateZoom(); + break; case PANVIEW: - myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY); - myStartX = myCurrX; - myStartY = myCurrY; - break; - - case PANGLOBAL: - break; - + activatePanning(); + break; + case ROTATE: + activateRotation(); + myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint); + 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::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 ); + 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::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. -*/ + \brief Draw rubber band rectangle. + */ void XGUI_ViewWindow::drawRect() { - if ( !myRectBand ) { - myRectBand = new XGUI_RectRubberBand( myViewPort ); - } + if (!myRectBand) { + myRectBand = new XGUI_RectRubberBand(myViewPort); + } - myRectBand->setUpdatesEnabled ( false ); - QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY); - myRectBand->initGeometry( aRect ); + myRectBand->setUpdatesEnabled(false); + QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY); + myRectBand->initGeometry(aRect); - if ( !myRectBand->isVisible() ) - myRectBand->show(); + if (!myRectBand->isVisible()) + myRectBand->show(); - myRectBand->setUpdatesEnabled ( true ); + myRectBand->setUpdatesEnabled(true); } /*! - \brief Clear rubber band rectangle on the end on the dragging operation. -*/ + \brief Clear rubber band rectangle on the end on the dragging operation. + */ void XGUI_ViewWindow::endDrawRect() { - if ( myRectBand ) { - myRectBand->clearGeometry(); - myRectBand->hide(); - } + 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 ); - } + 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 ); + return (myOperation != NOTHING); } /*! - \brief Start delayed viewer operation. -*/ -bool XGUI_ViewWindow::setTransformRequested( OperationType op ) + \brief Start delayed viewer operation. + */ +bool XGUI_ViewWindow::setTransformRequested(OperationType op) { - bool ok = transformEnabled( op ); + bool ok = transformEnabled(op); myOperation = ok ? op : NOTHING; - myViewPort->setMouseTracking( myOperation == 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 ) + 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 ); + if (id != NOTHING) + myStatus.insert(id, on); } /*! - \return enabled state of transformation (rotate, zoom, etc) -*/ -bool XGUI_ViewWindow::transformEnabled( const OperationType id ) const + \return enabled state of transformation (rotate, zoom, etc) + */ +bool XGUI_ViewWindow::transformEnabled(const OperationType id) const { - return myStatus.contains( id ) ? myStatus[ id ] : true; + return myStatus.contains(id) ? myStatus[id] : true; } - /*! - \brief Start panning operation. + \brief Start panning operation. - Sets the corresponding cursor for the widget. -*/ + 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 ); - } + if (!transformRequested() && !myCursorIsHand) + myCursor = cursor(); // save old cursor + + if (myOperation != PANVIEW) { + QCursor panCursor(Qt::SizeAllCursor); + if (setTransformRequested(PANVIEW)) + myViewPort->setCursor(panCursor); + } } /*! - \brief Start rotation operation + \brief Start rotation operation - Sets the corresponding cursor for the widget. -*/ + 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 ); - } + 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. ) -*/ + \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 ); + 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); } XGUI_ViewBackground XGUI_ViewWindow::background() const { return myViewPort ? myViewPort->background() : XGUI_ViewBackground(); } - -void XGUI_ViewWindow::setBackground( const XGUI_ViewBackground& theBackground ) + +void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground) { - if ( myViewPort ) myViewPort->setBackground( theBackground ); + if (myViewPort) + myViewPort->setBackground(theBackground); } diff --git a/src/XGUI/XGUI_ViewWindow.h b/src/XGUI/XGUI_ViewWindow.h index 1d794e94d..e77a4ee60 100644 --- a/src/XGUI/XGUI_ViewWindow.h +++ b/src/XGUI/XGUI_ViewWindow.h @@ -19,179 +19,209 @@ class ViewerToolbar; class ViewerLabel; class XGUI_RectRubberBand; -class XGUI_ViewWindow : public QFrame +class XGUI_ViewWindow: public QFrame { - Q_OBJECT +Q_OBJECT public: - enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE, - PANGLOBAL, WINDOWFIT, FITALLVIEW, RESETVIEW, - FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW, - CLOCKWISEVIEW, ANTICLOCKWISEVIEW }; + 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(); + + XGUI_ViewPort* viewPort() const + { + return myViewPort; + } + + XGUI::InteractionStyle interactionStyle() const + { + return myInteractionStyle; + } + + void setTransformEnabled(const OperationType, const bool); + bool transformEnabled(const OperationType) const; + + XGUI_ViewBackground background() const; + void setBackground(const XGUI_ViewBackground& theBackground); - XGUI_ViewWindow(XGUI_Viewer* theViewer, - V3d_TypeOfView theType); +signals: + void vpTransformationStarted(XGUI_ViewWindow::OperationType type); + void vpTransformationFinished(XGUI_ViewWindow::OperationType type); + //void viewCloned( XGUI_ViewWindow* ); + + void Show(QShowEvent *); + void Hide(QHideEvent *); + void maximized(XGUI_ViewWindow*, bool); + void returnedTo3d(); + + void tryClosing(XGUI_ViewWindow*); + void closing(XGUI_ViewWindow*); + void mousePressed(XGUI_ViewWindow*, QMouseEvent*); + void mouseReleased(XGUI_ViewWindow*, QMouseEvent*); + void mouseDoubleClicked(XGUI_ViewWindow*, QMouseEvent*); + void mouseMoving(XGUI_ViewWindow*, QMouseEvent*); + void wheeling(XGUI_ViewWindow*, QWheelEvent*); + void keyPressed(XGUI_ViewWindow*, QKeyEvent*); + void keyReleased(XGUI_ViewWindow*, QKeyEvent*); + void contextMenuRequested(QContextMenuEvent *e); + void viewModified(XGUI_ViewWindow*); - virtual ~XGUI_ViewWindow(); +public slots: + void activateZoom(); + void activateRotation(); + void activatePanning(); - XGUI_ViewPort* viewPort() const { return myViewPort; } +protected: + virtual void resizeEvent(QResizeEvent* theEvent); + virtual void changeEvent(QEvent* theEvent); - XGUI::InteractionStyle interactionStyle() const { return myInteractionStyle; } + virtual void enterEvent(QEvent* theEvent); + virtual void leaveEvent(QEvent* theEvent); - void setTransformEnabled( const OperationType, const bool ); - bool transformEnabled( const OperationType ) const; + virtual bool eventFilter(QObject *theObj, QEvent *theEvent); - XGUI_ViewBackground background() const; - void setBackground( const XGUI_ViewBackground& theBackground ); +private slots: + void onClose(); + void onMinimize(); + void onMaximize(); -signals: - void vpTransformationStarted(XGUI_ViewWindow::OperationType type); - void vpTransformationFinished(XGUI_ViewWindow::OperationType type); - //void viewCloned( XGUI_ViewWindow* ); - - void Show( QShowEvent * ); - void Hide( QHideEvent * ); - void maximized( XGUI_ViewWindow*, bool ); - void returnedTo3d( ); - - - void tryClosing( XGUI_ViewWindow* ); - void closing( XGUI_ViewWindow* ); - void mousePressed( XGUI_ViewWindow*, QMouseEvent* ); - void mouseReleased( XGUI_ViewWindow*, QMouseEvent* ); - void mouseDoubleClicked( XGUI_ViewWindow*, QMouseEvent* ); - void mouseMoving( XGUI_ViewWindow*, QMouseEvent* ); - void wheeling( XGUI_ViewWindow*, QWheelEvent* ); - void keyPressed( XGUI_ViewWindow*, QKeyEvent* ); - void keyReleased( XGUI_ViewWindow*, QKeyEvent* ); - void contextMenuRequested( QContextMenuEvent *e ); - void viewModified( XGUI_ViewWindow* ); +private: + enum WindowState + { + MinimizedState, MaximizedState, NormalState + }; -public slots: - void activateZoom(); - void activateRotation(); - void activatePanning(); + bool processWindowControls(QObject *theObj, QEvent *theEvent); + bool processViewPort(QEvent *theEvent); -protected: - virtual void resizeEvent(QResizeEvent* theEvent); + void vpMousePressEvent(QMouseEvent* theEvent); + void vpMouseReleaseEvent(QMouseEvent* theEvent); + void vpMouseMoveEvent(QMouseEvent* theEvent); - virtual void changeEvent(QEvent* theEvent); + OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle); - virtual void enterEvent(QEvent* theEvent); - virtual void leaveEvent(QEvent* theEvent); + void resetState(); + void drawRect(); + void endDrawRect(); - virtual bool eventFilter(QObject *theObj, QEvent *theEvent); + bool transformRequested() const; + bool setTransformRequested(OperationType); -private slots: - void onClose(); - void onMinimize(); - void onMaximize(); + // Transformation is selected and already started + bool transformInProcess() const + { + return myEventStarted; + } + void setTransformInProcess(bool bOn) + { + myEventStarted = bOn; + } private: - enum WindowState { MinimizedState, MaximizedState, NormalState }; + XGUI_Viewer* myViewer; - bool processWindowControls(QObject *theObj, QEvent *theEvent); - bool processViewPort(QEvent *theEvent); + QLabel* myPicture; + ViewerLabel* myGripWgt; + XGUI_ViewPort* myViewPort; + ViewerToolbar* myViewBar; + ViewerToolbar* myWindowBar; + QAction* myMinimizeBtn; + QAction* myMaximizeBtn; - void vpMousePressEvent(QMouseEvent* theEvent); - void vpMouseReleaseEvent(QMouseEvent* theEvent); - void vpMouseMoveEvent(QMouseEvent* theEvent); + QIcon MinimizeIco; + QIcon MaximizeIco; + QIcon CloseIco; + QIcon RestoreIco; - OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle); - - void resetState(); - void drawRect(); - void endDrawRect(); + bool myMoving; + QPoint myMousePnt; - bool transformRequested() const; - bool setTransformRequested ( OperationType ); + WindowState myLastState; - // Transformation is selected and already started - bool transformInProcess() const { return myEventStarted; } - void setTransformInProcess( bool bOn ) { myEventStarted = bOn; } + int myStartX; + int myStartY; + int myCurrX; + int myCurrY; -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 - - QCursor myCursor; - - XGUI::RotationPointType myCurrPointType; - XGUI::RotationPointType myPrevPointType; - - gp_Pnt mySelectedPoint; - - XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band - - typedef QMap MapOfTransformStatus; - MapOfTransformStatus myStatus; - - double myCurScale; -}; + 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 + + QCursor myCursor; + + XGUI::RotationPointType myCurrPointType; + XGUI::RotationPointType myPrevPointType; + gp_Pnt mySelectedPoint; + + XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band + + typedef QMap MapOfTransformStatus; + MapOfTransformStatus myStatus; + + double myCurScale; +}; //****************************************************** -class ViewerToolbar : public QToolBar +class ViewerToolbar: public QToolBar { - Q_OBJECT +Q_OBJECT public: - ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort) : - QToolBar(theParent), myVPort(thePort) {} + ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort) + : QToolBar(theParent), myVPort(thePort) + { + } protected: - virtual void paintEvent( QPaintEvent* theEvent); + virtual void paintEvent(QPaintEvent* theEvent); private: - XGUI_ViewPort* myVPort; + XGUI_ViewPort* myVPort; }; //****************************************************** -class ViewerLabel : public QLabel +class ViewerLabel: public QLabel { - Q_OBJECT +Q_OBJECT public: - ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort) : - QLabel(theParent), myVPort(thePort) {} + ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort) + : QLabel(theParent), myVPort(thePort) + { + } protected: - virtual void paintEvent( QPaintEvent* theEvent); + virtual void paintEvent(QPaintEvent* theEvent); private: - XGUI_ViewPort* myVPort; + XGUI_ViewPort* myVPort; }; -#endif \ No newline at end of file +#endif diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index 77b61acca..8053c9712 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -28,161 +28,146 @@ 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 ) + 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()) - { + if (aGraphicDriver.IsNull()) { Handle(Aspect_DisplayConnection) aDisplayConnection; #ifndef WIN32 aDisplayConnection = new Aspect_DisplayConnection( displayName ); #else aDisplayConnection = new Aspect_DisplayConnection(); #endif - aGraphicDriver = Graphic3d::InitGraphicDriver( aDisplayConnection ); + 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 ); + 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 ) + 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("GT_HORIZONTALGRADIENT") << tr("GT_VERTICALGRADIENT") << - tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") << - tr("GT_FIRSTCORNERGRADIENT") << tr("GT_SECONDCORNERGRADIENT") << - tr("GT_THIRDCORNERGRADIENT") << tr("GT_FORTHCORNERGRADIENT"); - idList << XGUI::HorizontalGradient << XGUI::VerticalGradient << - XGUI::Diagonal1Gradient << XGUI::Diagonal2Gradient << - XGUI::Corner1Gradient << XGUI::Corner2Gradient << - XGUI::Corner3Gradient << XGUI::Corner4Gradient; + gradList << tr("GT_HORIZONTALGRADIENT") << tr("GT_VERTICALGRADIENT") + << tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") + << tr("GT_FIRSTCORNERGRADIENT") << tr("GT_SECONDCORNERGRADIENT") + << tr("GT_THIRDCORNERGRADIENT") << tr("GT_FORTHCORNERGRADIENT"); + 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; + txtList << XGUI::CenterTexture << XGUI::TileTexture << XGUI::StretchTexture; #endif return tr("BG_IMAGE_FILES"); } - - -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) +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) { - if ( !isInitialized ) { - isInitialized = true; + 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; + // 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::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::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; + 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; + // "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::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::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 - } + 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)); - } + // 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; + } + // set zooming style to standard + //myZoomingStyle = 0; } - XGUI_Viewer::~XGUI_Viewer(void) { - myAISContext.Nullify(); - myV3dViewer.Nullify(); + 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())); - - view->setBackground(XGUI_ViewBackground(XGUI::VerticalGradient, Qt::green, Qt::blue)); - - QMdiArea* aMDI = myMainWindow->mdiArea(); - QMdiSubWindow* aWnd = aMDI->addSubWindow(view, Qt::FramelessWindowHint); - aWnd->setGeometry(0,0, aMDI->width() / 2, aMDI->height() / 2); - aWnd->show(); - return aWnd; + // 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())); + + view->setBackground(XGUI_ViewBackground(XGUI::VerticalGradient, Qt::green, Qt::blue)); + + QMdiArea* aMDI = myMainWindow->mdiArea(); + QMdiSubWindow* aWnd = aMDI->addSubWindow(view, Qt::FramelessWindowHint); + aWnd->setGeometry(0, 0, aMDI->width() / 2, aMDI->height() / 2); + aWnd->show(); + return aWnd; } /*! Sets hot button @@ -190,106 +175,108 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType) *\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 ) +void XGUI_Viewer::setHotButton(XGUI::InteractionStyle theInteractionStyle, + XGUI::HotOperation theOper, Qt::KeyboardModifiers theState, + Qt::MouseButtons theButton) { - myStateMap[theInteractionStyle][theOper] = theState; - myButtonMap[theInteractionStyle][theOper] = 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 ) + */ +void XGUI_Viewer::getHotButton(XGUI::InteractionStyle theInteractionStyle, + XGUI::HotOperation theOper, Qt::KeyboardModifiers& theState, + Qt::MouseButtons& theButton) { - theState = myStateMap[theInteractionStyle][theOper]; - theButton = myButtonMap[theInteractionStyle][theOper]; + theState = myStateMap[theInteractionStyle][theOper]; + theButton = myButtonMap[theInteractionStyle][theOper]; } /*! - Changes visibility of trihedron to opposite -*/ + Changes visibility of trihedron to opposite + */ void XGUI_Viewer::toggleTrihedron() { - setTrihedronShown( !isTrihedronVisible() ); + setTrihedronShown(!isTrihedronVisible()); } /*! - \return true if trihedron is visible -*/ + \return true if trihedron is visible + */ bool XGUI_Viewer::isTrihedronVisible() const { - return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron ); + return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed(myTrihedron); } /*! - Sets visibility state of trihedron - \param on - new state -*/ + Sets visibility state of trihedron + \param on - new state + */ -void XGUI_Viewer::setTrihedronShown( const bool on ) +void XGUI_Viewer::setTrihedronShown(const bool on) { - if ( myTrihedron.IsNull() ) - return; - - if ( on ) { - myAISContext->Display( myTrihedron ); - myAISContext->Deactivate(myTrihedron); - } else { - myAISContext->Erase( myTrihedron ); - } + if (myTrihedron.IsNull()) + return; + + if (on) { + myAISContext->Display(myTrihedron); + myAISContext->Deactivate(myTrihedron); + } else { + myAISContext->Erase(myTrihedron); + } } /*! - \return trihedron size -*/ + \return trihedron size + */ double XGUI_Viewer::trihedronSize() const { - double sz = 0; - if ( !myTrihedron.IsNull() ) - sz = myTrihedron->Size(); - return sz; + 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 ) + 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(); - } + if (myTrihedronSize != sz || isRelative != myIsRelative) { + myTrihedronSize = sz; + myIsRelative = isRelative; + updateTrihedron(); + } } /*! * Update the size of the trihedron */ -void XGUI_Viewer::updateTrihedron() +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); - } + 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 ) + Get new and current trihedron size corresponding to the current model size + */ +bool XGUI_Viewer::computeTrihedronSize(double& theNewSize, double& theSize) { theNewSize = 100; theSize = 100; @@ -297,48 +284,50 @@ bool XGUI_Viewer::computeTrihedronSize( double& theNewSize, double& theSize ) //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization Handle(V3d_Viewer) viewer = v3dViewer(); viewer->InitActiveViews(); - if(!viewer->MoreActiveViews()) return false; + if (!viewer->MoreActiveViews()) + return false; Handle(V3d_View) view3d = viewer->ActiveView(); //SRN: END of fix - if ( view3d.IsNull() ) + 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 ); + view3d->View()->MinMaxValues(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); - if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() || - Xmax == RealLast() || Ymax == RealLast() || Zmax == RealLast() ) + 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; + 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() ) + if (aMaxSide < Precision::Confusion()) return false; static float EPS = 5.0E-3; theSize = trihedron()->Size(); //theNewSize = aMaxSide*aSizeInPercents / 100.0; - return fabs( theNewSize - theSize ) > theSize * EPS || - fabs( theNewSize - theSize) > theNewSize * EPS; + return fabs(theNewSize - theSize) > theSize * EPS || fabs(theNewSize - theSize) > theNewSize * EPS; } - void XGUI_Viewer::onViewClosed() { Standard_Integer aViewsNb = 0; - for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews()) + for(myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); + myV3dViewer->NextActiveViews()) ++aViewsNb; - if ( aViewsNb < 2 ) { + if (aViewsNb < 2) { //clean up presentations before last view is closed myAISContext->RemoveAll(Standard_False); } @@ -346,6 +335,6 @@ void XGUI_Viewer::onViewClosed() void XGUI_Viewer::onViewMapped() { - setTrihedronShown( true ); + setTrihedronShown(true); } diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index 78cfe55a5..a5b43311f 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -1,4 +1,3 @@ - #ifndef XGUI_Viewer_H #define XGUI_Viewer_H @@ -14,69 +13,80 @@ class XGUI_MainWindow; class QMdiSubWindow; -class XGUI_Viewer : public QObject +class XGUI_Viewer: public QObject { - Q_OBJECT +Q_OBJECT public: - static QString backgroundData( QStringList&, QIntList&, QIntList& ); - - XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true); - ~XGUI_Viewer(); - - QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC); - - XGUI_MainWindow* mainWindow() const { return myMainWindow; } - - Handle(V3d_Viewer) v3dViewer() const { return myV3dViewer; } - - Handle(AIS_InteractiveContext) AISContext() const { return myAISContext; } - - Handle(AIS_Trihedron) trihedron() const { return myTrihedron; } - - void toggleTrihedron(); - bool isTrihedronVisible() const; - void setTrihedronShown( const bool on ); - double trihedronSize() const; - void setTrihedronSize( const double sz, bool isRelative ); - bool trihedronRelative() const { return myIsRelative; } - void updateTrihedron(); - bool computeTrihedronSize( double& theNewSize, double& theSize ); + static QString backgroundData(QStringList&, QIntList&, QIntList&); + + XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true); + ~XGUI_Viewer(); + + QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC); + + XGUI_MainWindow* mainWindow() const + { + return myMainWindow; + } + + Handle(V3d_Viewer) v3dViewer() const + { + return myV3dViewer; + } + + Handle(AIS_InteractiveContext) AISContext() const + { + return myAISContext; + } + + Handle(AIS_Trihedron) trihedron() const + { + return myTrihedron; + } + + void toggleTrihedron(); + bool isTrihedronVisible() const; + void setTrihedronShown(const bool on); + double trihedronSize() const; + void setTrihedronSize(const double sz, bool isRelative); + bool trihedronRelative() const + { + return myIsRelative; + } + void updateTrihedron(); + bool computeTrihedronSize(double& theNewSize, double& theSize); + + 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 StatesMap; + typedef QMap ButtonsMap; + + typedef QMap InteractionStyle2StatesMap; + typedef QMap InteractionStyle2ButtonsMap; + + static InteractionStyle2StatesMap myStateMap; + static InteractionStyle2ButtonsMap myButtonMap; +private slots: + void onViewClosed(); + void onViewMapped(); +private: + XGUI_MainWindow* myMainWindow; - 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 StatesMap; - typedef QMap ButtonsMap; - - typedef QMap InteractionStyle2StatesMap; - typedef QMap InteractionStyle2ButtonsMap; + Handle(V3d_Viewer) myV3dViewer;Handle(AIS_Trihedron) myTrihedron;Handle(AIS_InteractiveContext) myAISContext; - static InteractionStyle2StatesMap myStateMap; - static InteractionStyle2ButtonsMap myButtonMap; + XGUI::InteractionStyle myInteractionStyle; -private slots: - void onViewClosed(); - void onViewMapped(); + bool myPreselectionEnabled; + bool mySelectionEnabled; + bool myMultiSelectionEnabled; + bool myIsRelative; -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; + double myTrihedronSize; }; -#endif \ No newline at end of file +#endif diff --git a/src/XGUI/XGUI_Workbench.cpp b/src/XGUI/XGUI_Workbench.cpp index 61da43fa2..b3a1aee2b 100644 --- a/src/XGUI/XGUI_Workbench.cpp +++ b/src/XGUI/XGUI_Workbench.cpp @@ -5,67 +5,68 @@ #include #include - #define SCROLL_STEP 20 //************************************************** -class CommandsArea : public QScrollArea +class CommandsArea: public QScrollArea { public: - CommandsArea(QWidget* theParent) : QScrollArea(theParent) {} + CommandsArea(QWidget* theParent) + : QScrollArea(theParent) + { + } protected: - virtual void resizeEvent(QResizeEvent * theEvent); + 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); + 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) +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); - - 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); + 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); + + 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); } @@ -74,18 +75,18 @@ XGUI_Workbench::XGUI_Workbench(QWidget *theParent) : */ 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); - addSeparator(); - myLayout->addStretch(); - myGroups.append(aGroup); - return aGroup; + 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); + addSeparator(); + myLayout->addStretch(); + myGroups.append(aGroup); + return aGroup; } /* @@ -94,71 +95,67 @@ XGUI_MenuGroupPanel* XGUI_Workbench::addGroup(const QString& theId) XGUI_MenuGroupPanel* XGUI_Workbench::findGroup(const QString& theId) { XGUI_MenuGroupPanel* aPanel; - foreach(aPanel, myGroups) { - if(aPanel->objectName() == theId) { + 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); + 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()); + 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()); + 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()); + 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); + 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); + QPoint aPos = myChildWidget->pos(); + int aVPWidth = myCommandsArea->viewport()->rect().width(); + int aWgtWidth = myChildWidget->childrenRect().width(); + return ((aVPWidth - aPos.x()) < aWgtWidth); } diff --git a/src/XGUI/XGUI_Workbench.h b/src/XGUI/XGUI_Workbench.h index 2564f21ce..cc362db2b 100644 --- a/src/XGUI/XGUI_Workbench.h +++ b/src/XGUI/XGUI_Workbench.h @@ -1,4 +1,3 @@ - #ifndef XGUI_Workbench_H #define XGUI_Workbench_H @@ -13,37 +12,34 @@ class CommandsArea; class QHBoxLayout; class QPushButton; - - -class XGUI_Workbench : public QWidget +class XGUI_Workbench: public QWidget { - Q_OBJECT +Q_OBJECT public: - XGUI_Workbench(QWidget* theParent); + XGUI_Workbench(QWidget* theParent); - XGUI_MenuGroupPanel* addGroup(const QString& theId); - XGUI_MenuGroupPanel* findGroup(const QString& theName); + XGUI_MenuGroupPanel* addGroup(const QString& theId); + XGUI_MenuGroupPanel* findGroup(const QString& theName); private slots: - void onLeftScroll(); - void onRightScroll(); + void onLeftScroll(); + void onRightScroll(); protected: - virtual void resizeEvent(QResizeEvent * theEvent); + virtual void resizeEvent(QResizeEvent * theEvent); private: - void addSeparator(); - bool isExceedsLeft(); - bool isExceedsRight(); - + void addSeparator(); + bool isExceedsLeft(); + bool isExceedsRight(); - QWidget* myChildWidget; - QHBoxLayout* myLayout; - QList myGroups; + QWidget* myChildWidget; + QHBoxLayout* myLayout; + QList myGroups; - CommandsArea* myCommandsArea; - QPushButton* myRightButton; - QPushButton* myLeftButton; + CommandsArea* myCommandsArea; + QPushButton* myRightButton; + QPushButton* myLeftButton; }; #endif; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 48bc0c087..be82600eb 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -16,7 +16,6 @@ #include #include - #ifdef _DEBUG #include #endif @@ -27,12 +26,11 @@ #include #endif - -XGUI_Workshop::XGUI_Workshop() : - QObject() +XGUI_Workshop::XGUI_Workshop() + : QObject() { - myMainWindow = new XGUI_MainWindow(); - myPartSetModule = NULL; + myMainWindow = new XGUI_MainWindow(); + myPartSetModule = NULL; } //****************************************************** @@ -43,83 +41,81 @@ XGUI_Workshop::~XGUI_Workshop(void) //****************************************************** void XGUI_Workshop::startApplication() { - initMenu(); - //Initialize event listening - Event_Loop* aLoop = Event_Loop::Loop(); - Event_ID aFeatureId = aLoop->EventByName("menu_item"); - aLoop->RegisterListener(this, aFeatureId); - Event_ID aPartSetId = aLoop->EventByName("partset_module"); - aLoop->RegisterListener(this, aPartSetId); - activateModule(); - myMainWindow->show(); - QMdiSubWindow* aWnd = myMainWindow->viewer()->createView(); - aWnd->showMaximized(); + initMenu(); + //Initialize event listening + Event_Loop* aLoop = Event_Loop::Loop(); + Event_ID aFeatureId = aLoop->EventByName("menu_item"); + aLoop->RegisterListener(this, aFeatureId); + Event_ID aPartSetId = aLoop->EventByName("partset_module"); + aLoop->RegisterListener(this, aPartSetId); + activateModule(); + myMainWindow->show(); + QMdiSubWindow* aWnd = myMainWindow->viewer()->createView(); + aWnd->showMaximized(); } //****************************************************** void XGUI_Workshop::initMenu() { - XGUI_Workbench* aPage = addWorkbench(tr("GEN_MENU_TITLE")); + XGUI_Workbench* aPage = addWorkbench(tr("GEN_MENU_TITLE")); - // File commands group - XGUI_MenuGroupPanel* aGroup = aPage->addGroup("Default"); + // File commands group + XGUI_MenuGroupPanel* aGroup = aPage->addGroup("Default"); - XGUI_Command* aCommand; + XGUI_Command* aCommand; - aCommand = aGroup->addFeature("SAVE_CMD", tr("SAVE_MENU"), tr("SAVE_MENU_TIP"), - QIcon(":pictures/save.png"), QKeySequence::Save); - aCommand->connectTo(this, SLOT(onSave())); - //aCommand->disable(); + aCommand = aGroup->addFeature("SAVE_CMD", tr("SAVE_MENU"), tr("SAVE_MENU_TIP"), + QIcon(":pictures/save.png"), QKeySequence::Save); + aCommand->connectTo(this, SLOT(onSave())); + //aCommand->disable(); - aCommand = aGroup->addFeature("UNDO_CMD", tr("UNDO_MENU"), tr("UNDO_MENU_TIP"), - QIcon(":pictures/undo.png"), QKeySequence::Undo); + aCommand = aGroup->addFeature("UNDO_CMD", tr("UNDO_MENU"), tr("UNDO_MENU_TIP"), + QIcon(":pictures/undo.png"), QKeySequence::Undo); - aCommand = aGroup->addFeature("REDO_CMD", tr("REDO_MENU"), tr("REDO_MENU_TIP"), - QIcon(":pictures/redo.png"), QKeySequence::Redo); + aCommand = aGroup->addFeature("REDO_CMD", tr("REDO_MENU"), tr("REDO_MENU_TIP"), + QIcon(":pictures/redo.png"), QKeySequence::Redo); - aCommand = aGroup->addFeature("REBUILD_CMD", tr("REBUILD_MENU"), tr("REBUILD_MENU_TIP"), - QIcon(":pictures/rebuild.png")); + aCommand = aGroup->addFeature("REBUILD_CMD", tr("REBUILD_MENU"), tr("REBUILD_MENU_TIP"), + QIcon(":pictures/rebuild.png")); - aCommand = aGroup->addFeature("SAVEAS_CMD", tr("SAVEAS_MENU"), tr("SAVEAS_MENU_TIP"), - QIcon(":pictures/save.png")); - aCommand->connectTo(this, SLOT(onSaveAs())); - //aCommand->disable(); + aCommand = aGroup->addFeature("SAVEAS_CMD", tr("SAVEAS_MENU"), tr("SAVEAS_MENU_TIP"), + QIcon(":pictures/save.png")); + aCommand->connectTo(this, SLOT(onSaveAs())); + //aCommand->disable(); - aCommand = aGroup->addFeature("OPEN_CMD", tr("OPEN_MENU"), tr("OPEN_MENU_TIP"), - QIcon(":pictures/open.png"), QKeySequence::Open); - aCommand->connectTo(this, SLOT(onOpen())); + aCommand = aGroup->addFeature("OPEN_CMD", tr("OPEN_MENU"), tr("OPEN_MENU_TIP"), + QIcon(":pictures/open.png"), QKeySequence::Open); + aCommand->connectTo(this, SLOT(onOpen())); + aCommand = aGroup->addFeature("NEW_CMD", tr("NEW_MENU"), tr("NEW_MENU_TIP"), + QIcon(":pictures/new.png"), QKeySequence::New); + aCommand->connectTo(this, SLOT(onNew())); - aCommand = aGroup->addFeature("NEW_CMD", tr("NEW_MENU"), tr("NEW_MENU_TIP"), - QIcon(":pictures/new.png"), QKeySequence::New); - aCommand->connectTo(this, SLOT(onNew())); - - aCommand = aGroup->addFeature("EXIT_CMD", tr("EXIT_MENU"), tr("EXIT_MENU_TIP"), - QIcon(":pictures/close.png"), QKeySequence::Close); - aCommand->connectTo(this, SLOT(onExit())); + aCommand = aGroup->addFeature("EXIT_CMD", tr("EXIT_MENU"), tr("EXIT_MENU_TIP"), + QIcon(":pictures/close.png"), QKeySequence::Close); + aCommand->connectTo(this, SLOT(onExit())); } //****************************************************** XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName) { - XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); - return aMenuBar->addWorkbench(theName); + XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); + return aMenuBar->addWorkbench(theName); } //****************************************************** void XGUI_Workshop::ProcessEvent(const Event_Message* theMessage) { - const Config_FeatureMessage* aFeatureMsg = - dynamic_cast( theMessage ); - if(aFeatureMsg) { + const Config_FeatureMessage* aFeatureMsg = dynamic_cast(theMessage); + if (aFeatureMsg) { addFeature(aFeatureMsg); return; } - #ifdef _DEBUG +#ifdef _DEBUG qDebug() << "XGUI_Workshop::ProcessEvent: " - << "Catch message, but it can not be processed."; - #endif + << "Catch message, but it can not be processed."; +#endif } @@ -128,53 +124,52 @@ void XGUI_Workshop::ProcessEvent(const Event_Message* theMessage) */ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) { - if(!theMessage) { - #ifdef _DEBUG + if (!theMessage) { +#ifdef _DEBUG qDebug() << "XGUI_Workshop::addFeature: NULL message."; - #endif +#endif return; } //Find or create Workbench XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); QString aWchName = QString::fromStdString(theMessage->workbenchId()); XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName); - if(!aPage) { + if (!aPage) { aPage = addWorkbench(aWchName); } //Find or create Group QString aGroupName = QString::fromStdString(theMessage->groupId()); XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName); - if(!aGroup) { + if (!aGroup) { aGroup = aPage->addGroup(aGroupName); } //Create feature... QString aFeatureId = QString::fromStdString(theMessage->id()); - XGUI_Command* aCommand = aGroup->addFeature( - QString::fromStdString(theMessage->id()), - QString::fromStdString(theMessage->text()), - QString::fromStdString(theMessage->tooltip()), - QIcon(theMessage->icon().c_str()) - //TODO(sbh): QKeySequence - ); + XGUI_Command* aCommand = aGroup->addFeature(QString::fromStdString(theMessage->id()), + QString::fromStdString(theMessage->text()), + QString::fromStdString(theMessage->tooltip()), + QIcon(theMessage->icon().c_str()) + //TODO(sbh): QKeySequence + ); myPartSetModule->featureCreated(aCommand); } //****************************************************** void XGUI_Workshop::onExit() { - qApp->exit(); + qApp->exit(); } //****************************************************** void XGUI_Workshop::onNew() { - myMainWindow->showObjectBrowser(); + myMainWindow->showObjectBrowser(); } //****************************************************** void XGUI_Workshop::onOpen() { - QString aFileName = QFileDialog::getOpenFileName(mainWindow()); + QString aFileName = QFileDialog::getOpenFileName(mainWindow()); } //****************************************************** @@ -185,16 +180,16 @@ void XGUI_Workshop::onSave() //****************************************************** void XGUI_Workshop::onSaveAs() { - QString aFileName = QFileDialog::getSaveFileName(mainWindow()); + QString aFileName = QFileDialog::getSaveFileName(mainWindow()); } //****************************************************** XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule) { - QString libName = library( theModule ); - if ( libName.isEmpty() ) - { - qWarning( qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ) ); + QString libName = library(theModule); + if (libName.isEmpty()) { + qWarning( + qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) )); return 0; } @@ -203,48 +198,47 @@ XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule) #ifdef WIN32 - HINSTANCE modLib = ::LoadLibrary( (LPTSTR) qPrintable(libName) ); - if ( !modLib ) - { + HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName)); + if (!modLib) { LPVOID lpMsgBuf; - ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, 0, ::GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, 0 ); - QString aMsg((char*)&lpMsgBuf); - err = QString( "Failed to load %1. %2" ).arg( libName ).arg( aMsg ); - ::LocalFree( lpMsgBuf ); - } - else - { - crtInst = (CREATE_FUNC)::GetProcAddress( modLib, CREATE_MODULE ); - if ( !crtInst ) - { + ::FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0); + QString aMsg((char*) &lpMsgBuf); + err = QString("Failed to load %1. %2").arg(libName).arg(aMsg); + ::LocalFree(lpMsgBuf); + } else { + crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE); + if (!crtInst) { LPVOID lpMsgBuf; - ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, 0, ::GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, 0 ); - QString aMsg((char*)&lpMsgBuf); - err = QString( "Failed to find %1 function. %2" ).arg( CREATE_MODULE ).arg(aMsg ); - ::LocalFree( lpMsgBuf ); + ::FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_IGNORE_INSERTS, + 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0); + QString aMsg((char*) &lpMsgBuf); + err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg); + ::LocalFree(lpMsgBuf); } } #else void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY ); if ( !modLib ) - err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() ); + err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() ); else { crtInst = (CREATE_FUNC)dlsym( modLib, GET_MODULE_NAME ); if ( !crtInst ) - err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() ); + err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() ); } #endif XGUI_Module* aModule = crtInst ? crtInst(this) : 0; - if ( !err.isEmpty() ) { - if ( mainWindow() && mainWindow()->isVisible() ) - QMessageBox::warning( mainWindow(), tr( "Error" ), err ); + if (!err.isEmpty()) { + if (mainWindow() && mainWindow()->isVisible()) + QMessageBox::warning(mainWindow(), tr("Error"), err); else - qWarning( qPrintable( err ) ); + qWarning( qPrintable( err )); } return aModule; } diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index c84925f6c..f25f355fb 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -1,4 +1,3 @@ - #ifndef XGUI_WORKSHOP_H #define XGUI_WORKSHOP_H @@ -19,39 +18,42 @@ class Config_FeatureMessage; class XGUI_Workshop: public QObject, public Event_Listener { - Q_OBJECT +Q_OBJECT public: - XGUI_Workshop(); - virtual ~XGUI_Workshop(); + XGUI_Workshop(); + virtual ~XGUI_Workshop(); - void startApplication(); + void startApplication(); - XGUI_MainWindow* mainWindow() const { return myMainWindow; } + XGUI_MainWindow* mainWindow() const + { + return myMainWindow; + } - XGUI_Workbench* addWorkbench(const QString& theName); + XGUI_Workbench* addWorkbench(const QString& theName); - virtual void ProcessEvent(const Event_Message* theMessage); + virtual void ProcessEvent(const Event_Message* theMessage); public slots: - void onNew(); - void onOpen(); - void onSave(); - void onSaveAs(); - void onExit(); + void onNew(); + void onOpen(); + void onSave(); + void onSaveAs(); + void onExit(); protected: - //Event-loop processing methods: - void addFeature(const Config_FeatureMessage*); + //Event-loop processing methods: + void addFeature(const Config_FeatureMessage*); private: - void initMenu(); + void initMenu(); - XGUI_Module* loadModule(const QString& theModule); - bool activateModule(); + XGUI_Module* loadModule(const QString& theModule); + bool activateModule(); - XGUI_MainWindow* myMainWindow; - XGUI_Module* myPartSetModule; + XGUI_MainWindow* myMainWindow; + XGUI_Module* myPartSetModule; }; #endif -- 2.39.2