Salome HOME
Merge branch 'master' of newgeom:newgeom
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 29 Jul 2014 08:14:09 +0000 (12:14 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 29 Jul 2014 08:14:09 +0000 (12:14 +0400)
src/Events/CMakeLists.txt
src/Events/Events_LongOp.cpp [new file with mode: 0644]
src/Events/Events_LongOp.h [new file with mode: 0644]
src/Model/Model_Update.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp

index af4155f4268119e19d78b8f3a0241823fb22e9de..b33e8516623d2ae4080d88f0472f2d9277a12ec3 100644 (file)
@@ -7,6 +7,7 @@ SET(PROJECT_HEADERS
     Events_Listener.h
     Events_Loop.h
     Events_Error.h
+    Events_LongOp.h
 )
 
 SET(PROJECT_SOURCES
@@ -14,6 +15,7 @@ SET(PROJECT_SOURCES
     Events_Listener.cpp
     Events_Loop.cpp
     Events_Error.cpp
+    Events_LongOp.cpp
 )
 
 ADD_DEFINITIONS(-DEVENTS_EXPORTS)
diff --git a/src/Events/Events_LongOp.cpp b/src/Events/Events_LongOp.cpp
new file mode 100644 (file)
index 0000000..04fc673
--- /dev/null
@@ -0,0 +1,50 @@
+// File:        Events_LongOp.cpp
+// Created:     29 Jul 2014
+// Author:      Mikhail PONIKAROV
+
+#include <Events_LongOp.h>
+#include <Events_Loop.h>
+
+/// senders of the long operation collected, ends the long operation event only
+/// if all senders are stopped
+std::map<void*, int> MY_SENDERS;
+
+Events_LongOp::Events_LongOp(void* theSender)
+ : Events_Message(Events_LongOp::errorID(), theSender)
+{
+}
+
+Events_LongOp::~Events_LongOp()
+{
+}
+
+Events_ID Events_LongOp::errorID()
+{
+  Events_Loop* aLoop = Events_Loop::loop();
+  return aLoop->eventByName("LongOperation");
+}
+
+void Events_LongOp::start(void* theSender)
+{
+  if (MY_SENDERS.empty()) {
+    Events_LongOp anError(theSender);
+    Events_Loop::loop()->send(anError);
+  }
+  if (MY_SENDERS.find(theSender) == MY_SENDERS.end())
+    MY_SENDERS[theSender] = 1;
+  else 
+    MY_SENDERS[theSender]++;
+}
+
+void Events_LongOp::end(void* theSender)
+{
+  if (MY_SENDERS.find(theSender) != MY_SENDERS.end()) {
+    int aCount = MY_SENDERS[theSender];
+    if (aCount <= 1) MY_SENDERS.erase(theSender);
+    else MY_SENDERS[theSender] = aCount - 1;
+  }
+  if (MY_SENDERS.empty()) {
+    Events_LongOp anError(theSender);
+    Events_Loop::loop()->send(anError);
+  }
+}
diff --git a/src/Events/Events_LongOp.h b/src/Events/Events_LongOp.h
new file mode 100644 (file)
index 0000000..bc698ac
--- /dev/null
@@ -0,0 +1,32 @@
+// File:        Events_LongOp.h
+// Created:     29 Jul 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef EVENTS_LONGOP_H_
+#define EVENTS_LONGOP_H_
+
+#include <Events.h>
+#include <Events_Message.h>
+
+/**
+ * Informs the application that the long operation is performed.
+ * Causes waiting coursor in GUI.
+ */
+class EVENTS_EXPORT Events_LongOp: public Events_Message
+{
+public:
+  virtual ~Events_LongOp();
+  /// Returns the identifier of this event
+  static Events_ID errorID();
+  /// Starts the long operation
+  static void start(void* theSender = 0);
+  /// Stops the long operation
+  static void end(void* theSender = 0);
+  /// Returns true if the long operation is performed
+  static bool isPerformed(); 
+
+protected:
+  Events_LongOp(void* theSender = 0);
+};
+
+#endif /* EVENTS_ERROR_H_ */
index 070e5a8c09f37f9a723ec0ba7d28c9ba222481ff..af5407cafedba7467c26761d5fc88277ca062f14 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Result.h>
 #include <Events_Loop.h>
+#include <Events_LongOp.h>
 
 using namespace std;
 
@@ -25,6 +26,7 @@ Model_Update::Model_Update()
 void Model_Update::processEvent(const Events_Message* theMessage)
 {
   if (isExecuted) return; // nothing to do: it is executed now
+  Events_LongOp::start(this);
   isExecuted = true;
   const ModelAPI_ObjectUpdatedMessage* aMsg = 
     dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
@@ -50,6 +52,7 @@ void Model_Update::processEvent(const Events_Message* theMessage)
   // flush
   static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   Events_Loop::loop()->flush(EVENT_DISP);
+  Events_LongOp::end(this);
   isExecuted = false;
 }
 
index 76e48e0760ce6f565de147baa5d92159f07c37c9..288e4e5297b308d8c5aab90a98be643ed3405bf9 100644 (file)
@@ -61,12 +61,19 @@ void SketchPlugin_Sketch::execute()
   std::list< boost::shared_ptr<GeomAPI_Shape> > aFeaturesPreview;
   for (; anIt != aLast; anIt++) {
     aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
-    boost::shared_ptr<ModelAPI_ResultConstruction> aRes = 
-      boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aFeature->firstResult());
-    if (aRes) {
-      boost::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
-      if (aShape)
-        aFeaturesPreview.push_back(aShape);
+    if (aFeature) {
+
+      const std::list<boost::shared_ptr<ModelAPI_Result> >& aRes = aFeature->results();
+      std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aResIter = aRes.cbegin();
+      for(; aResIter != aRes.cend(); aResIter++) {
+        boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = 
+          boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aResIter);
+        if (aConstr) {
+          boost::shared_ptr<GeomAPI_Shape> aShape = aConstr->shape();
+          if (aShape)
+            aFeaturesPreview.push_back(aShape);
+        }
+      }
     }
   }