]> SALOME platform Git repositories - plugins/blsurfplugin.git/commitdiff
Salome HOME
Implement Cancel Compute
authoradam <adam>
Thu, 17 Mar 2011 10:51:52 +0000 (10:51 +0000)
committeradam <adam>
Thu, 17 Mar 2011 10:51:52 +0000 (10:51 +0000)
src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx
src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx

index fd2940fcdd2a684c8d7b42d71a949e75fbb847e7..51c77bab7066426a6c92162cf224c34c7f6378b0 100644 (file)
@@ -278,6 +278,10 @@ BLSURFPlugin_BLSURF::BLSURFPlugin_BLSURF(int hypId, int studyId,
   FaceId2EnforcedVertexCoords.clear();
   EnfVertexCoords2ProjVertex.clear();
   EnfVertexCoords2EnfVertexList.clear();
+
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+  _compute_canceled = false;
+#endif
 }
 
 //=============================================================================
@@ -923,7 +927,12 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
   
   /* Set the message callback in the working context */
   context_set_message_callback(ctx, message_cb, &_comment);
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+  _compute_canceled = false;
+  context_set_interrupt_callback(ctx, interrupt_cb, this);
+#else
   context_set_interrupt_callback(ctx, interrupt_cb, NULL);
+#endif
 
   /* create the CAD object we will work on. It is associated to the context ctx. */
   cad_t *c = cad_new(ctx);
@@ -1498,6 +1507,13 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
   return true;
 }
 
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+void BLSURFPlugin_BLSURF::CancelCompute()
+{
+  _compute_canceled = true;
+}
+#endif
+
 //=============================================================================
 /*!
  *  SetNodeOnEdge
@@ -1821,13 +1837,21 @@ status_t message_cb(message_t *msg, void *user_data)
 status_t interrupt_cb(integer *interrupt_status, void *user_data)
 {
   integer you_want_to_continue = 1;
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+  BLSURFPlugin_BLSURF* tmp = (BLSURFPlugin_BLSURF*)user_data;
+  you_want_to_continue = !tmp->computeCanceled();
+#endif
 
   if(you_want_to_continue)
+  {
     *interrupt_status = INTERRUPT_CONTINUE;
+    return STATUS_OK;
+  }
   else /* you want to stop BLSurf */
+  {
     *interrupt_status = INTERRUPT_STOP;
-  
-  return STATUS_OK;
+    return STATUS_ERROR;
+  }
 }
 
 //=============================================================================
index 70ebef1bcf937aeff568fcc6d49c974a6d2fbd91..c8c34bc5ada05a579ab055f6bfbe456bb9a54248 100644 (file)
@@ -74,6 +74,11 @@ class BLSURFPlugin_BLSURF: public SMESH_2D_Algo {
 
     virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
 
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+    virtual void CancelCompute();
+    bool computeCanceled() { return _compute_canceled;};
+#endif
+
     virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
                           MapShapeNbElems& aResMap);
 
@@ -96,6 +101,10 @@ class BLSURFPlugin_BLSURF: public SMESH_2D_Algo {
       PyObject *          main_dict;
       SALOMEDS::Study_var myStudy;
       SMESH_Gen_i*        smeshGen_i;
+
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+      volatile bool _compute_canceled;
+#endif
 };
 
 #endif