]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Provide error messages if AIEngine cannot be found. Disable Suggest Constraints featu...
authorjfa <jfa@opencascade.com>
Tue, 24 Jan 2023 11:53:47 +0000 (14:53 +0300)
committerjfa <jfa@opencascade.com>
Tue, 24 Jan 2023 11:53:47 +0000 (14:53 +0300)
src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py
src/SketchPlugin/SketchPlugin_Plugin.cpp

index b055441ee0ef58b67c45444a7773099805bf63d6..f8f7ce09a1586ec4024f8eb6a255dcaf878fba8b 100644 (file)
@@ -43,20 +43,19 @@ import importlib.util
 def getPathToSketchConstraintsFinder():
     ai_engine_path = os.environ.get('SHAPER_SKETCH_CONSTRAINT_SUGGESTION_AI')
     if not ai_engine_path:
-        print('SHAPER_SKETCH_CONSTRAINT_SUGGESTION_AI variable is not set')
+        EventsAPI.Events_InfoMessage('Error', 'Error: SHAPER_SKETCH_CONSTRAINT_SUGGESTION_AI variable is not set').send()
         return None
 
-    print(ai_engine_path)
     if not os.path.isfile(ai_engine_path):
-        print('{} is not a file'.format(ai_engine_path))
+        EventsAPI.Events_InfoMessage('Error', 'Error: {} is not a file'.format(ai_engine_path)).send()
         return None
 
     file_extension = pathlib.Path(ai_engine_path).suffix
     if file_extension == '.py' or file_extension == '.pyc':
         return ai_engine_path
     else:
-        print('{} is not a python file'.format(ai_engine_path))
-        pass
+        EventsAPI.Events_InfoMessage('Error', 'Error: {} is not a python file'.format(ai_engine_path)).send()
+        return None
 
     return None
 
@@ -65,7 +64,7 @@ def getPathToSketchConstraintsFinder():
 def getSketchConstraintsFinder():
     ai_engine_path = getPathToSketchConstraintsFinder()
     if not ai_engine_path:
-        return
+        return None
 
     p = pathlib.Path(ai_engine_path)
     ai_engine_name = p.stem
@@ -74,10 +73,16 @@ def getSketchConstraintsFinder():
     ai_spec.loader.exec_module(ai_engine)
 
     if not hasattr(ai_engine, 'AIEngine'):
-        print('There is no AIEngine in {}'.format(ai_engine_path))
-        return
+        EventsAPI.Events_InfoMessage('Error', 'Error: There is no AIEngine class in {}'.format(ai_engine_path)).send()
+        return None
 
     ai_class_inst = getattr(ai_engine, 'AIEngine')()
+
+    predict_op = getattr(ai_class_inst, "Predict", None)
+    if not callable(predict_op):
+        EventsAPI.Events_InfoMessage('Error', 'Error: There is no Predict method in AIEngine in {}'.format(ai_engine_path)).send()
+        return None
+
     return ai_class_inst
 
 ## Method to create error message
index 22f4e92014470372a5888806d7d733d49abc1ba2..7b684d46354db6ca31f711c0e3c72e270f4b63b2 100644 (file)
@@ -368,8 +368,10 @@ std::shared_ptr<ModelAPI_FeatureStateMessage> SketchPlugin_Plugin
       aMsg->setState(SketchPlugin_Offset::ID(), aHasSketchPlane);
       // SketchRectangle is a python feature, so its ID is passed just as a string
       aMsg->setState("SketchRectangle", aHasSketchPlane);
+
       // SuggestConstraints is a python feature, so its ID is passed just as a string
-      aMsg->setState("SuggestConstraints", aHasSketchPlane);
+      char* aConstraintsFinder = getenv("SHAPER_SKETCH_CONSTRAINT_SUGGESTION_AI");
+      aMsg->setState("SuggestConstraints", aHasSketchPlane && aConstraintsFinder && *aConstraintsFinder);
     }
   }
   return aMsg;