]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implimentation of the Config XML Reader
authorSergey Belash <sergey.belash@opencascade.com>
Thu, 20 Mar 2014 08:44:02 +0000 (12:44 +0400)
committerSergey Belash <sergey.belash@opencascade.com>
Thu, 20 Mar 2014 08:44:02 +0000 (12:44 +0400)
28 files changed:
CMakeCommon/Common.cmake
CMakeCommon/XMLProcessing.cmake
CMakeLists.txt
env.bat
src/Config/CMakeLists.txt [new file with mode: 0644]
src/Config/Config.h [new file with mode: 0644]
src/Config/Config_Message.cpp [new file with mode: 0644]
src/Config/Config_Message.h [new file with mode: 0644]
src/Config/Config_XMLReader.cpp [new file with mode: 0644]
src/Config/Config_XMLReader.h [new file with mode: 0644]
src/Config/plugin-PartSet.xml
src/Event/CMakeLists.txt
src/Event/Event_Listener.hxx
src/Event/Event_Loop.cxx
src/Event/Event_Loop.hxx
src/Event/Event_Message.cxx
src/Event/Event_Message.hxx
src/GeomModule/CMakeLists.txt
src/GeomModule/GeomModule.cpp
src/GeomModule/GeomModule.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_Interfaces.h
src/XGUI/XGUI_MainMenu.cpp
src/XGUI/XGUI_MainMenu.h
src/XGUI/XGUI_Workbench.cpp
src/XGUI/XGUI_Workbench.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 29f6e2241aa301f052916a50918b3b3c69dc7b90..b1e5384def66614edf0f35d4a4d4cf42762e697a 100644 (file)
@@ -6,3 +6,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
 
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+IF(WIN32)
+  ADD_DEFINITIONS(-DWIN32 -D_WINDOWS)
+ENDIF(WIN32)
index 114371138f060b19515195ecc7dffd646614f995..da2bbf47cab72ea3f012b20a0c61548a4c7a6d21 100644 (file)
@@ -1,13 +1,25 @@
 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})
index d67d35f11e9488913dd8d57f1ea8b0fd0203561c..248e6f91af64cc77e471c1623916b75906759bb5 100644 (file)
@@ -8,7 +8,8 @@ INCLUDE(Common)
 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)
diff --git a/env.bat b/env.bat
index 55814d96ef7e33ddf0dd98bc287236b0d0484f42..ac6d75d7cf6966ff15147adb12b015327bdc3da7 100644 (file)
--- a/env.bat
+++ b/env.bat
@@ -99,13 +99,20 @@ if "%QTDIR%" == "" (
 @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 -------------------------
@@ -113,6 +120,8 @@ if "%QTDIR%" == "" (
 @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%" == "" (
diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt
new file mode 100644 (file)
index 0000000..95bcd8f
--- /dev/null
@@ -0,0 +1,34 @@
+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)
diff --git a/src/Config/Config.h b/src/Config/Config.h
new file mode 100644 (file)
index 0000000..587ac53
--- /dev/null
@@ -0,0 +1,18 @@
+#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
diff --git a/src/Config/Config_Message.cpp b/src/Config/Config_Message.cpp
new file mode 100644 (file)
index 0000000..ea701ff
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ *
+ */
+
+#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 = "";
+}
+
diff --git a/src/Config/Config_Message.h b/src/Config/Config_Message.h
new file mode 100644 (file)
index 0000000..2e3d567
--- /dev/null
@@ -0,0 +1,27 @@
+#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
diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp
new file mode 100644 (file)
index 0000000..658d624
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * 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;
+}
diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h
new file mode 100644 (file)
index 0000000..25637fd
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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_ */
index feca64bfc5e08cc7a8c56a2907c47a18fd379fb2..d3d7d4cb22a1ffd8dcb041293f54e84166387b62 100644 (file)
@@ -1,9 +1,7 @@
 <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>
index 7a8af5bc4c09100090018ec26ffe9a1cf604334c..70b6b3a6dd6d522a2dd8c1f4c72604e5c0369554 100644 (file)
@@ -17,7 +17,7 @@ SET(PROJECT_SOURCES
 
 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)
index f5d70ba65aa19466581e8909e68b05f1fc833a2e..8a17122d9f9e579a1e2f1cdf7e9b434fab614eb9 100644 (file)
@@ -15,7 +15,7 @@ class Event_Message;
  * 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.
index b1f22b50f6f6c712d032f72ead81e511912ababe..e997c8b8fb3a8bacad7049081a981c75307c4c40 100644 (file)
@@ -30,7 +30,7 @@ Event_ID Event_Loop::EventByName(const char* theName)
   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
 
index 7b6da954942278a2888ae15b70c4d3d571dc8944..3d57ec45cb6c37d1a226f0827823ef91f99bfe62 100644 (file)
@@ -35,7 +35,7 @@ public:
   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
index 02a018ef32dab5df43126db89f694598e392396f..e9dc311b32fdb1060d05895fc48e19234b41fc0c 100644 (file)
@@ -3,3 +3,8 @@
 // Author:     Mikhail PONIKAROV
 
 #include <Event_Message.hxx>
+
+Event_Message::Event_Message(const Event_ID theID, const void* theSender) :
+myID(theID), mySender((void*)theSender)
+{
+}
index b9abe11ce2cf0bfbf90a58acc867b4ecc15198d3..4e5337c8362ceb1fb8fdaa7bad5eb494850197e3 100644 (file)
@@ -17,7 +17,7 @@
  * 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;}
@@ -35,7 +35,7 @@ public:
  * \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
 
@@ -43,6 +43,7 @@ public:
 
   //! 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;}
index a27056b6f8cfcec4fc3cb86c5fd8c5267de63ddb..540798c8dbe478dcf27085625381712aaa4f9683 100644 (file)
@@ -1,5 +1,6 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
 
+INCLUDE(Common)
 
 SET(PROJECT_HEADERS
        GeomModule_Defs.h
@@ -18,14 +19,17 @@ SET(TEXT_RESOURCES
        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} 
@@ -37,9 +41,10 @@ ADD_LIBRARY(GeomModule SHARED
 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)
index 6bddce9b101628566db1ce41374d26b906d85d34..f3bc0fd16e94ac784ffc4896f3177ec1c4419d93 100644 (file)
@@ -1,5 +1,7 @@
 #include "GeomModule.h"
 
+#include <Config_XMLReader.h>
+
 #include <QFile>
 #include <QDir>
 #include <QApplication>
@@ -25,30 +27,7 @@ GeomModule::~GeomModule()
 
 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();
+}
index 80c8ae5015f1874120294e4bd0f2ed18dd274abb..e190a2305f138ec3a9438665ee07d181b96befd5 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <XGUI_Interfaces.h>
 
+class Config_XMLReader;
+
 class GM_EXPORT GeomModule : public IModule
 {
 public:
@@ -20,4 +22,4 @@ private:
     IWorkshop* myWorkshop;
 };
 
-#endif
\ No newline at end of file
+#endif
index e4521a14864a2890f02424e1a2502b9ef029857d..56aadf14099bf5e2cbbcbf56b36f7c9bcbfb769e 100644 (file)
@@ -1,10 +1,10 @@
 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
@@ -38,13 +38,20 @@ SET(TEXT_RESOURCES
        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} 
@@ -55,7 +62,7 @@ ADD_EXECUTABLE(XGUI WIN32
 )
 
 # 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)
index d54bba43bbe3879d18797962c711f111048193fa..24b53dcd5591a025c899de125949cedcdc9d7866 100644 (file)
@@ -32,7 +32,8 @@ public:
 class IWorkbench
 {
 public:
-    virtual IMenuGroup* addGroup() = 0;
+    virtual IMenuGroup* addGroup(const QString& theName = "") = 0;
+    virtual IMenuGroup* findGroup(const QString& theName) = 0;
 };
 
 
@@ -59,4 +60,4 @@ extern "C"
 #define CREATE_MODULE "createModule"
 
 
-#endif
\ No newline at end of file
+#endif
index 0a4903bcea28b92a50b13f46b89b46bbf9bd604c..a19731deaf2bb9201ab6279096dd7ad6a4ae7166 100644 (file)
@@ -18,9 +18,11 @@ XGUI_MainMenu::~XGUI_MainMenu(void)
 {
 }
 
-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);
@@ -35,11 +37,22 @@ IWorkbench* XGUI_MainMenu::addWorkbench(QString 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)
 {
index ef4dc0511dcda16b15ede7435f39470f62503ff0..3addcdb6f3d202782c3bbcebb8edc4b936448ddf 100644 (file)
@@ -21,7 +21,8 @@ public:
     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);
 
index f73c693fc8ceb045c1dec92c3213e5ebc3b63ead..ac930f0766af0f12799eb2c7d892aac24c6a1aa0 100644 (file)
@@ -69,14 +69,26 @@ XGUI_Workbench::XGUI_Workbench(QWidget *theParent) :
 
 }
 
-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();
@@ -84,6 +96,22 @@ IMenuGroup* XGUI_Workbench::addGroup()
     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);
@@ -92,6 +120,7 @@ void XGUI_Workbench::addSeparator()
     myLayout->addWidget(aLine);
 }
 
+
 void XGUI_Workbench::resizeEvent(QResizeEvent* theEvent)
 {
     QWidget::resizeEvent(theEvent);
index 506845adbddbe84bf0016eafe8f98c89bb8803e3..e44b60b87d8f461eb88fcb82410595d75f091733 100644 (file)
@@ -21,7 +21,8 @@ class XGUI_Workbench : public QWidget, public IWorkbench
 public:
     XGUI_Workbench(QWidget* theParent);
 
-    virtual IMenuGroup* addGroup();
+    virtual IMenuGroup* addGroup(const QString& theName = "");
+    virtual IMenuGroup* findGroup(const QString& theName);
 
 private slots:
     void onLeftScroll();
@@ -45,4 +46,4 @@ private:
     QPushButton* myLeftButton;
 };
 
-#endif;
\ No newline at end of file
+#endif;
index b7db81cb10a0b24d529a94e91ab2f609c3eed2ce..b7cd63a16e03c65de8fcc7faa5e32e2f589e9780 100644 (file)
@@ -4,9 +4,18 @@
 #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>
@@ -30,6 +39,10 @@ XGUI_Workshop::~XGUI_Workshop(void)
 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();
 }
@@ -85,6 +98,48 @@ IWorkbench* XGUI_Workshop::addWorkbench(const QString& theName)
     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()
 {
index c941f42d010269ac594d7954a3bbc19af6ba7623..b0471732fc003889e8e4d3ebbe0ed6a8eddba9e5 100644 (file)
@@ -4,6 +4,9 @@
 
 #include "XGUI_Interfaces.h"
 
+#include <Event_Message.hxx>
+#include <Event_Listener.hxx>
+
 #include <QObject>
 #include <QMap>
 #include <QIcon>
@@ -13,7 +16,9 @@ class XGUI_MainWindow;
 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:
@@ -27,6 +32,8 @@ public:
 
     virtual IWorkbench* addWorkbench(const QString& theName);
 
+    virtual void ProcessEvent(const Event_Message* theMessage);
+
 public slots:
     void onNew();
     void onOpen();
@@ -34,6 +41,10 @@ public slots:
     void onSaveAs();
     void onExit();
 
+protected:
+    //Event-loop processing methods:
+    void addFeature(const Config_FeatureMessage*);
+
 private:
     void initMenu();
 
@@ -43,4 +54,4 @@ private:
     XGUI_MainWindow* myMainWindow;
 };
 
-#endif
\ No newline at end of file
+#endif