set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+IF(WIN32)
+ ADD_DEFINITIONS(-DWIN32 -D_WINDOWS)
+ENDIF(WIN32)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
-FILE(TO_CMAKE_PATH $ENV{LIBXML2_INCLUDE_DIR} LIBXML2_INCLUDE_DIR)
+SET(LIBXMLDIR $ENV{LIBXML2_DIR})
+INCLUDE_DIRECTORIES(${LIBXMLDIR}/include/libxml2)
+LINK_DIRECTORIES (${LIBXMLDIR}/lib)
+
+SET(LIBXML2_LIBRARIES ${LIBXMLDIR}/lib/libxml2.lib)
+#set(PROJECT_LIBRARIES ${PROJECT_LIBRARIES} ${LIBXMLDIR}/lib/libxml2.lib)
+
+#FILE(TO_CMAKE_PATH $ENV{PC_LIBXML_INCLUDEDIR} PC_LIBXML_INCLUDEDIR)
+#FILE(TO_CMAKE_PATH $ENV{PC_LIBXML_INCLUDEDIR} PC_LIBXML_INCLUDEDIR)
+#FILE(TO_CMAKE_PATH $ENV{PC_LIBXML_LIBDIR} PC_LIBXML_LIBDIR)
+#message(STATUS "PC_LIBXML_INCLUDEDIR " ${PC_LIBXML_INCLUDEDIR})
+#message(STATUS "PC_LIBXML_LIBDIR " ${PC_LIBXML_LIBDIR})
+
-FIND_PACKAGE(LibXml2 REQUIRED)
-if(LIBXML2_FOUND)
- message(STATUS "Found libxml2 ver. " ${LIBXML2_VERSION_STRING})
- message(STATUS "LIBXML2_LIBRARIES " ${LIBXML2_LIBRARIES})
- message(STATUS "LIBXML2_INCLUDE_DIR " ${LIBXML2_INCLUDE_DIR})
-endif(LIBXML2_FOUND)
-
-INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
-ADD_DEFINITIONS(${LIBXML2_DEFINITIONS})
+#FIND_PACKAGE(LibXml2 REQUIRED)
+#if(LIBXML2_FOUND)
+# message(STATUS "Found libxml2 ver. " ${LIBXML2_VERSION_STRING})
+# message(STATUS "LIBXML2_LIBRARIES " ${LIBXML2_LIBRARIES})
+# message(STATUS "LIBXML2_INCLUDE_DIR " ${LIBXML2_INCLUDE_DIR})
+#endif(LIBXML2_FOUND)
+
+#INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
+#ADD_DEFINITIONS(${LIBXML2_DEFINITIONS})
INCLUDE(FindQt5)
ADD_SUBDIRECTORY (src/Event)
+ADD_SUBDIRECTORY (src/Config)
#ADD_SUBDIRECTORY (src/ModelAPI)
-ADD_SUBDIRECTORY (src/Model)
-ADD_SUBDIRECTORY (src/XGUI)
+#ADD_SUBDIRECTORY (src/Model)
ADD_SUBDIRECTORY (src/GeomModule)
+ADD_SUBDIRECTORY (src/XGUI)
@SET PYTHON_VERSION=2.7
@REM -------------------------
+@REM -------------------------
+@REM ZLIB (for LIBXML2)
+@SET PATH=%PDIR%\zlib-1.2.5\dll;%PATH%
+@REM -------------------------
+
@REM -------------------------
@REM LIBXML2
@SET LIBXML2_DIR=%PDIR%\libxml2-2.9.0
+@REM DO NOT rename following 3 variables,
+@REM they are required by CMake "find(Libxml2)" procedure
@SET LIBXML2_INCLUDE_DIR=%LIBXML2_DIR%\include\libxml2
@SET LIBXML2_LIB_DIR=%LIBXML2_DIR%\lib
@SET LIBXML2_BIN_DIR=%LIBXML2_DIR%\bin
-@SET PATH=LIBXML2_BIN_DIR;LIBXML2_LIB_DIR;%PATH%
+@SET PATH=%LIBXML2_BIN_DIR%;%LIBXML2_LIB_DIR%;%PATH%
@REM -------------------------
@REM -------------------------
@SET PATH=%PDIR%\swig-2.0.9\bin;%PATH%
@REM -------------------------
+@SET PATH=D:\NewGEOM\build-eclipse\bin;%PATH%
+
rem -------- Visual Studio --------------------
rem Detect Visual Studio (either commercial or Express edition)
if "%VS100COMNTOOLS%" == "" (
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
+
+INCLUDE(Common)
+INCLUDE(XMLProcessing)
+
+INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Event)
+
+SET(PROJECT_HEADERS
+ Config.h
+ Config_XMLReader.h
+ Config_Message.h
+ )
+
+SET(PROJECT_SOURCES
+ Config_XMLReader.cpp
+ Config_Message.cpp
+)
+
+SET(XML_RESOURCES
+ plugin-PartSet.xml
+ plugins.xml
+)
+
+SET(PROJECT_LIBRARIES
+ Event
+ ${LIBXML2_LIBRARIES}
+)
+
+ADD_DEFINITIONS(-DCONFIG_EXPORTS)
+ADD_LIBRARY(Config SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+
+TARGET_LINK_LIBRARIES(Config ${PROJECT_LIBRARIES})
+
+INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
--- /dev/null
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#if defined CONFIG_EXPORTS
+#if defined WIN32
+#define CONFIG_EXPORT __declspec( dllexport )
+#else
+#define CONFIG_EXPORT
+#endif
+#else
+#if defined WIN32
+#define CONFIG_EXPORT __declspec( dllimport )
+#else
+#define CONFIG_EXPORT
+#endif
+#endif
+
+#endif //CONFIG_H
--- /dev/null
+/*
+ *
+ */
+
+#include "Config_Message.h"
+
+Config_FeatureMessage::Config_FeatureMessage(const Event_ID theId, const void* theParent) :
+ Event_Message(theId, theParent)
+{
+ m_group = "";
+ m_id = "";
+ m_text = "";
+ m_tooltip = "";
+ m_icon = "";
+ m_keysequence = "";
+}
+
--- /dev/null
+#ifndef CONFIG_MESSAGE_H
+#define CONFIG_MESSAGE_H
+
+#include "Config.h"
+
+#include <Event_Message.hxx>
+#include <string>
+
+class CONFIG_EXPORT Config_FeatureMessage : public Event_Message
+{
+public:
+ std::string m_id;
+ std::string m_text;
+ std::string m_tooltip;
+ std::string m_icon;
+ std::string m_keysequence;
+
+ std::string m_group;
+
+public:
+ //const Event_ID theID, const void* theSender = 0
+ Config_FeatureMessage(const Event_ID theId, const void* theParent = 0);
+
+};
+
+
+#endif // CONFIG_MESSAGE_H
--- /dev/null
+/*
+ * Config_XMLReader.cpp
+ *
+ * Created on: Mar 14, 2014
+ * Author: sbh
+ */
+
+#include <Config_XMLReader.h>
+
+#include <Event_Loop.hxx>
+
+#include <libxml\parser.h>
+#include <libxml\tree.h>
+#ifdef WIN32
+//For GetModuleFileNameW
+#include <windows.h>
+#endif
+
+#ifdef _DEBUG
+#include <iostream>
+#endif
+
+static bool IsNode(xmlNodePtr theNode, const char* theNodeName)
+{
+ return theNode->type == XML_ELEMENT_NODE
+ && !xmlStrcmp(theNode->name, (const xmlChar *) theNodeName);
+}
+
+const static char* FEATURE_ID = "id";
+const static char* FEATURE_TEXT = "text";
+const static char* FEATURE_TOOLTIP = "tooltip";
+const static char* FEATURE_ICON = "icon";
+const static char* FEATURE_KEYSEQUENCE = "keysequence";
+const static char* FEATURE_GROUP_NAME = "name";
+
+Config_XMLReader::Config_XMLReader(const std::string& theXmlFile)
+{
+ setDocumentPath(theXmlFile);
+}
+
+Config_XMLReader::~Config_XMLReader()
+{
+}
+
+std::string Config_XMLReader::documentPath() const
+{
+ return m_DocumentPath;
+}
+
+void Config_XMLReader::setDocumentPath(std::string documentPath)
+{
+ std::string prefix;
+#ifdef WIN32
+ HMODULE hModule = GetModuleHandleW(NULL);
+ WCHAR wchar_path[MAX_PATH];
+ GetModuleFileNameW(hModule, wchar_path, MAX_PATH);
+ char char_path[MAX_PATH];
+ char DefChar = ' ';
+ WideCharToMultiByte(CP_ACP, 0, wchar_path, -1, char_path, MAX_PATH, &DefChar, NULL);
+ prefix = std::string(char_path);
+ //chop "bin\XGUI.exe"
+ unsigned found = prefix.rfind("bin");
+ if(found != std::string::npos)
+ prefix.replace(found, prefix.length(), "plugins\\");
+#else
+ //TODO(sbh): Find full path to binary on linux
+ prefix = "../plugins/";
+#endif
+ m_DocumentPath = prefix + documentPath;
+}
+
+void Config_XMLReader::readAll()
+{
+ import();
+}
+
+/*
+ * TODO: make virtual as beforeImport
+ */
+bool Config_XMLReader::import()
+{
+ bool result = false;
+ xmlDocPtr aDoc;
+ aDoc = xmlParseFile(m_DocumentPath.c_str());
+ if(aDoc == NULL) {
+ #ifdef _DEBUG
+ std::cout << "Config_XMLReader::import: " << "Document " << m_DocumentPath
+ << " is not parsed successfully." << std::endl;
+ #endif
+ return result;
+ }
+ xmlNodePtr aRoot = xmlDocGetRootElement(aDoc);
+ if(aRoot == NULL) {
+ #ifdef _DEBUG
+ std::cout << "Config_XMLReader::import: " << "Error: empty document";
+ #endif
+ return result;
+ }
+ xmlNodePtr aWbSec;
+ for(aWbSec = aRoot->xmlChildrenNode; aWbSec; aWbSec = aWbSec->next) { // searching for higher level element "workbench"
+ if(IsNode(aWbSec, "workbench")) {
+ result = importWorkbench(aWbSec);
+ } else {
+ #ifdef _DEBUG
+ std::cout << "Config_XMLReader::import: "
+ << "Found strange section, should be workbench" << std::endl;
+ #endif
+ continue;
+ }
+ }
+ return result;
+}
+
+/*
+ * TODO(sbh): make virtual as doImport
+ */
+bool Config_XMLReader::importWorkbench(void* theRoot)
+{
+ xmlNodePtr aGroupNode = (static_cast<xmlNodePtr>(theRoot))->xmlChildrenNode;
+ Event_Loop* aEvLoop = Event_Loop::Loop();
+ if(!aEvLoop) {
+ #ifdef _DEBUG
+ std::cout << "Config_XMLReader::importWorkbench: "
+ << "No event loop registered" << std::endl;
+ #endif
+ return false;
+ }
+ for(; aGroupNode; aGroupNode = aGroupNode->next) { // searching for record
+ if(!IsNode(aGroupNode, "group"))
+ continue;
+ std::string aGroupName = getProperty(aGroupNode, FEATURE_GROUP_NAME);
+ if(aGroupName.empty())
+ continue;
+ xmlNodePtr aFtNode = aGroupNode->xmlChildrenNode;
+ for(; aFtNode; aFtNode = aFtNode->next) {
+ if(!IsNode(aFtNode, "feature"))
+ continue;
+ //Create feature...
+ Config_FeatureMessage aMessage(aEvLoop->EventByName("Feature"), this);
+ fillFeature(aFtNode, aMessage);
+ aMessage.m_group = aGroupName;
+ aEvLoop->Send(aMessage);
+ }
+ }
+ return true;
+}
+
+void Config_XMLReader::fillFeature(void *theRoot,
+ Config_FeatureMessage& outFeatureMessage)
+{
+ outFeatureMessage.m_id = getProperty(theRoot, FEATURE_ID);
+ outFeatureMessage.m_text = getProperty(theRoot, FEATURE_TEXT);
+ outFeatureMessage.m_tooltip = getProperty(theRoot, FEATURE_TOOLTIP);
+ outFeatureMessage.m_icon = getProperty(theRoot, FEATURE_ICON);
+ outFeatureMessage.m_keysequence = getProperty(theRoot, FEATURE_KEYSEQUENCE);
+}
+
+std::string Config_XMLReader::getProperty(void *theRoot, const char* name)
+{
+ std::string result = "";
+ xmlNodePtr aNode = (static_cast<xmlNodePtr>(theRoot));
+ char* aPropChars = (char*) xmlGetProp(aNode, BAD_CAST name);
+ if(!aPropChars || aPropChars[0] == 0)
+ return result;
+ result = std::string(aPropChars);
+ return result;
+}
--- /dev/null
+/*
+ * Config_XMLReader.h
+ *
+ * Created on: Mar 14, 2014
+ * Author: sbh
+ */
+
+#ifndef CONFIG_XMLREADER_H_
+#define CONFIG_XMLREADER_H_
+
+#include "Config.h"
+#include "Config_Message.h"
+
+#include <string>
+#include <map>
+
+class CONFIG_EXPORT Config_XMLReader {
+public:
+ Config_XMLReader(const std::string& theXmlFile);
+ virtual ~Config_XMLReader();
+
+ std::string documentPath() const;
+ void setDocumentPath(std::string documentName);
+
+ void readAll();
+
+protected:
+ //! Performs the real import of the given xml file, return false if file is not found
+ //! or generates an algo error if file content is bad
+ //! \param theFile name of the imported XML file
+ //! \returns true if file exists and not corrupted
+ bool import();
+ bool importWorkbench(void*);
+ void fillFeature(void *theRoot, Config_FeatureMessage& outFeatureMessage);
+ std::string getProperty(void *theRoot, const char* name);
+
+private:
+ std::string m_DocumentPath;
+};
+
+#endif /* CONFIG_XMLREADER_H_ */
<plugin name="PartSet">
<workbench>
<group name="Part">
- <feature id="new_part" text="Part" tooltip="Creates a new part" icon=":pictures/part_ico.png">
- <label text="No feature..."/>
- </feature>
+ <feature id="new_part" text="Part" tooltip="Creates a new part" icon=":pictures/part_ico.png"/>
<feature id="duplicate" text="Duplicate" tooltip="Duplicate selected object" icon=":icons/duplicate.png"/>
<feature id="remove" text="Remove" tooltip="Remove selected object" icon=":icons/remove.png"/>
</group>
ADD_DEFINITIONS(-DEVENT_EXPORTS)
ADD_LIBRARY(Event SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+
TARGET_LINK_LIBRARIES(Event ${PROJECT_LIBRARIES})
-INCLUDE_DIRECTORIES(
-)
+INSTALL(TARGETS Event DESTINATION bin)
* If some object wants to listen some events it must inherit
* this class and register in the Loop.
*/
-EVENT_EXPORT class Event_Listener {
+class EVENT_EXPORT Event_Listener {
public:
//! This method is called by loop when the event is started to process.
return Event_ID(aResult);
}
-void Event_Loop::Send(Event_Message theMessage)
+void Event_Loop::Send(Event_Message& theMessage)
{
// TO DO: make it in thread and wit husage of semaphores
EVENT_EXPORT static Event_ID EventByName(const char* theName);
//! Allows to send an event
- EVENT_EXPORT void Send(Event_Message theMessage);
+ EVENT_EXPORT void Send(Event_Message& theMessage);
//! Registers (or adds if such listener is already registered) a listener
//! that will be called on the event and from the defined sender
// Author: Mikhail PONIKAROV
#include <Event_Message.hxx>
+
+Event_Message::Event_Message(const Event_ID theID, const void* theSender) :
+myID(theID), mySender((void*)theSender)
+{
+}
* used as an identifier (this is usefull for debugging of the events
* with log files and in debugger).
*/
-EVENT_EXPORT class 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;}
* \brief Message for communication between sender and listener of event.
* Normally it is inherited by the higher-level
*/
-EVENT_EXPORT class Event_Message {
+class EVENT_EXPORT Event_Message {
Event_ID myID; ///< identifier of the event
void* mySender; ///< the sender object
//! Creates the message
Event_Message(const Event_ID theID, const void* theSender = 0);
+ virtual ~Event_Message() {}
//! Returns identifier of the message
const Event_ID& ID() const {return myID;}
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
+INCLUDE(Common)
SET(PROJECT_HEADERS
GeomModule_Defs.h
GeomModule_msg_en.ts
)
+SET(PROJECT_LIBRARIES
+ Config
+ ${Qt5Widgets_LIBRARIES}
+)
+
QT5_ADD_RESOURCES(PROJECT_COMPILED_RESOURCES ${PROJECT_RESOURCES})
QT5_ADD_TRANSLATION(QM_RESOURCES ${TEXT_RESOURCES})
SOURCE_GROUP ("Generated Files" FILES ${PROJECT_COMPILED_RESOURCES} ${QM_RESOURCES})
SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES} ${PROJECT_RESOURCES})
-ADD_DEFINITIONS(-DWIN32 -D_WINDOWS)
-
ADD_LIBRARY(GeomModule SHARED
${PROJECT_SOURCES}
${PROJECT_HEADERS}
ADD_DEPENDENCIES(GeomModule XGUI)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/Config)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/Event)
# The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore
-TARGET_LINK_LIBRARIES(GeomModule ${Qt5Widgets_LIBRARIES})
+TARGET_LINK_LIBRARIES(GeomModule ${PROJECT_LIBRARIES})
INSTALL(TARGETS GeomModule DESTINATION bin)
-#INSTALL(FILES ${XML_RESOURCES} DESTINATION bin)
#include "GeomModule.h"
+#include <Config_XMLReader.h>
+
#include <QFile>
#include <QDir>
#include <QApplication>
void GeomModule::createFeatures()
{
- IWorkbench* aPage = myWorkshop->addWorkbench("Home");
- IMenuGroup* aGroup = aPage->addGroup();
-
- IFeatureMenu* aCommand = aGroup->addFeature("new_part", "Part", "Creates a new part", QIcon(":pictures/part_ico.png"));
- aCommand = aGroup->addFeature("new_point", "Point", "Create a new point", QIcon(":icons/point.png"));
- aCommand = aGroup->addFeature("new_axis", "Axis", "Create a new axis", QIcon(":icons/axis.png"), QKeySequence());
- aCommand = aGroup->addFeature("new_plane", "Plane", "Create a new plane", QIcon(":icons/plane.png"), QKeySequence());
-
- //aGroup = aPage->addGroup();
- aCommand = aGroup->addFeature("duplicate", "Duplicate", "Duplicate selected object", QIcon(":icons/duplicate.png"));
- aCommand = aGroup->addFeature("remove", "Remove", "Remove selected object", QIcon(":icons/remove.png"));
-
- aPage = myWorkshop->addWorkbench("Features");
- aGroup = aPage->addGroup();
-
- aCommand = aGroup->addFeature("extrusion", "Extrusion", "Make extrusion", QIcon(":icons/extrusion.png"));
- aCommand = aGroup->addFeature("revolution", "Revolution", "Make revolution", QIcon(":icons/revol.png"));
- aCommand = aGroup->addFeature("cut", "Cut", "Make cut", QIcon(":icons/cut.png"));
- aCommand = aGroup->addFeature("fusion", "Fusion", "Make fusion", QIcon(":icons/fusion.png"));
- aCommand = aGroup->addFeature("common", "Common", "Make common", QIcon(":icons/common.png"));
-
- //aGroup = aPage->addGroup();
- aCommand = aGroup->addFeature("import", "Import", "Make import", QIcon(":icons/import.png"));
-
- aPage = myWorkshop->addWorkbench("Sketch");
- aPage = myWorkshop->addWorkbench("Properties");
-}
\ No newline at end of file
+ Config_XMLReader* aReader =
+ new Config_XMLReader("plugin-PartSet.xml");
+ aReader->readAll();
+}
#include <XGUI_Interfaces.h>
+class Config_XMLReader;
+
class GM_EXPORT GeomModule : public IModule
{
public:
IWorkshop* myWorkshop;
};
-#endif
\ No newline at end of file
+#endif
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
+INCLUDE(Common)
SET(CMAKE_AUTOMOC ON)
SET(PROJECT_HEADERS
XGUI_Command.h
- XGUI_Interfaces.h
XGUI_MainMenu.h
XGUI_MainWindow.h
XGUI_MenuGroupPanel.h
XGUI_msg_en.ts
)
+SET(PROJECT_LIBRARIES
+ Event
+ Config
+ ${Qt5Widgets_LIBRARIES}
+)
+
QT5_ADD_RESOURCES(PROJECT_COMPILED_RESOURCES ${PROJECT_RESOURCES})
QT5_ADD_TRANSLATION(QM_RESOURCES ${TEXT_RESOURCES})
SOURCE_GROUP ("Generated Files" FILES ${PROJECT_AUTOMOC} ${PROJECT_COMPILED_RESOURCES} ${QM_RESOURCES})
SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES} ${PROJECT_RESOURCES})
-ADD_DEFINITIONS(-DWIN32 -D_WINDOWS)
+INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Event)
+INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Config)
ADD_EXECUTABLE(XGUI WIN32
${PROJECT_SOURCES}
)
# The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore
-TARGET_LINK_LIBRARIES(XGUI ${Qt5Widgets_LIBRARIES})
+TARGET_LINK_LIBRARIES(XGUI ${PROJECT_LIBRARIES})
INSTALL(TARGETS XGUI DESTINATION bin)
INSTALL(FILES ${QM_RESOURCES} DESTINATION bin)
class IWorkbench
{
public:
- virtual IMenuGroup* addGroup() = 0;
+ virtual IMenuGroup* addGroup(const QString& theName = "") = 0;
+ virtual IMenuGroup* findGroup(const QString& theName) = 0;
};
#define CREATE_MODULE "createModule"
-#endif
\ No newline at end of file
+#endif
{
}
-IWorkbench* XGUI_MainMenu::addWorkbench(QString theTitle)
+IWorkbench* XGUI_MainMenu::addWorkbench(const QString& theTitle)
{
QDockWidget* aDoc = new QDockWidget(myDesktop);
+ QString workbenchObjName = theTitle + "_Workbench";
+ aDoc->setObjectName(workbenchObjName);
aDoc->setFeatures(QDockWidget::DockWidgetVerticalTitleBar);
aDoc->setAllowedAreas(Qt::TopDockWidgetArea);
aDoc->setWindowTitle(theTitle);
myDesktop->tabifyDockWidget(myMenuTabs.last(), aDoc);
}
-
myMenuTabs.append(aDoc);
return aPage;
}
+/*
+ * Searches for already created workbench with given name.
+ */
+IWorkbench* XGUI_MainMenu::findWorkbench(const QString& theObjName)
+{
+ QDockWidget* aDoc = myDesktop->findChild<QDockWidget*>(theObjName);
+ if(aDoc) {
+ return dynamic_cast<IWorkbench*>(aDoc->widget());
+ }
+ return NULL;
+}
+
IMenuGroup* XGUI_MainMenu::addGroup(int thePageId)
{
XGUI_MainMenu(XGUI_MainWindow *parent);
virtual ~XGUI_MainMenu();
- IWorkbench* addWorkbench(QString theTitle);
+ IWorkbench* addWorkbench(const QString& theTitle);
+ IWorkbench* findWorkbench(const QString& theObjName);
IMenuGroup* addGroup(int thePageId);
}
-IMenuGroup* XGUI_Workbench::addGroup()
+/*
+ * Creates a new group in the workbench with given name.
+ * If no name provided it would be defined as {workbench_name}_Group_N.
+ */
+IMenuGroup* XGUI_Workbench::addGroup(const QString& theName)
{
+ QString aGroupName = theName;
+ //Generate a group name.
+ if(theName.isEmpty()){
+ QString aGroupName = objectName();
+ aGroupName = aGroupName.replace("_Workbench", "_Group_%1");
+ aGroupName = aGroupName.arg(myGroups.count());
+ }
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(aGroupName);
myLayout->addWidget(aGroup);
addSeparator();
myLayout->addStretch();
return aGroup;
}
+/*
+ * Searches for already created group with given name.
+ */
+IMenuGroup* XGUI_Workbench::findGroup(const QString& theName)
+{
+ QString aGroupName = theName;
+ XGUI_MenuGroupPanel* aPanel;
+ foreach(aPanel, myGroups) {
+ if(aPanel->objectName() == theName) {
+ return aPanel;
+ }
+ }
+ return NULL;
+}
+
+
void XGUI_Workbench::addSeparator()
{
QFrame* aLine = new QFrame(myChildWidget);
myLayout->addWidget(aLine);
}
+
void XGUI_Workbench::resizeEvent(QResizeEvent* theEvent)
{
QWidget::resizeEvent(theEvent);
public:
XGUI_Workbench(QWidget* theParent);
- virtual IMenuGroup* addGroup();
+ virtual IMenuGroup* addGroup(const QString& theName = "");
+ virtual IMenuGroup* findGroup(const QString& theName);
private slots:
void onLeftScroll();
QPushButton* myLeftButton;
};
-#endif;
\ No newline at end of file
+#endif;
#include "XGUI_Command.h"
#include "XGUI_Tools.h"
+#include <Config_Message.h>
+#include <Event_Loop.hxx>
+
#include <QApplication>
#include <QFileDialog>
#include <QMessageBox>
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+
+#include <cstdio>
#ifdef WIN32
#include <windows.h>
void XGUI_Workshop::startApplication()
{
initMenu();
+ //Initialize event listening
+ Event_Loop* aLoop = Event_Loop::Loop();
+ Event_ID aFeatureId = aLoop->EventByName("Feature");
+ aLoop->RegisterListener(this, aFeatureId);
activateModule();
myMainWindow->show();
}
return aMenuBar->addWorkbench(theName);
}
+//******************************************************
+void XGUI_Workshop::ProcessEvent(const Event_Message* theMessage)
+{
+ const Config_FeatureMessage* aMsg =
+ dynamic_cast<const Config_FeatureMessage*>( theMessage );
+ if(aMsg) {
+ addFeature(aMsg);
+ return;
+ }
+ #ifdef _DEBUG
+ qDebug() << "XGUI_Workshop::ProcessEvent: "
+ << "Got message, but it's not a Config_FeatureMessage";
+ #endif
+
+}
+
+void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
+{
+ XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
+ IWorkbench* aPage = aMenuBar->findWorkbench(tr( "GEN_MENU_TITLE" ) + "_Workbench");
+ if(!aPage) {
+ #ifdef _DEBUG
+ qDebug() << "XGUI_Workshop::ProcessEvent: "
+ << "Creating a workbench " << tr( "GEN_MENU_TITLE" );
+ #endif
+ aPage = addWorkbench(tr( "GEN_MENU_TITLE" ));
+ }
+ QString aGroupName = QString::fromStdString(theMessage->m_group);
+ IMenuGroup* aGroup = aPage->findGroup(aGroupName);
+ if(!aGroup) {
+ aGroup = aPage->addGroup(aGroupName);
+ }
+ IFeatureMenu* aCommand;
+ aCommand = aGroup->addFeature(
+ QString::fromStdString(theMessage->m_id),
+ QString::fromStdString(theMessage->m_text),
+ QString::fromStdString(theMessage->m_tooltip),
+ QIcon(theMessage->m_icon.c_str())
+ //TODO(sbh): QKeySequence
+ );
+}
+
//******************************************************
void XGUI_Workshop::onExit()
{
#include "XGUI_Interfaces.h"
+#include <Event_Message.hxx>
+#include <Event_Listener.hxx>
+
#include <QObject>
#include <QMap>
#include <QIcon>
class XGUI_Command;
class XGUI_Module;
-class XGUI_Workshop: public QObject, public IWorkshop
+class Config_FeatureMessage;
+
+class XGUI_Workshop: public QObject, public Event_Listener, public IWorkshop
{
Q_OBJECT
public:
virtual IWorkbench* addWorkbench(const QString& theName);
+ virtual void ProcessEvent(const Event_Message* theMessage);
+
public slots:
void onNew();
void onOpen();
void onSaveAs();
void onExit();
+protected:
+ //Event-loop processing methods:
+ void addFeature(const Config_FeatureMessage*);
+
private:
void initMenu();
XGUI_MainWindow* myMainWindow;
};
-#endif
\ No newline at end of file
+#endif