From: jfa Date: Tue, 24 Jan 2023 11:53:47 +0000 (+0300) Subject: Provide error messages if AIEngine cannot be found. Disable Suggest Constraints featu... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=88975292088f84e1a23d435f7c367ced7da653e1;p=modules%2Fshaper.git Provide error messages if AIEngine cannot be found. Disable Suggest Constraints feature if variable SHAPER_SKETCH_CONSTRAINT_SUGGESTION_AI is not defined or set to empty string. --- diff --git a/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py b/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py index b055441ee..f8f7ce09a 100644 --- a/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py +++ b/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py @@ -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 diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 22f4e9201..7b684d463 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -368,8 +368,10 @@ std::shared_ptr 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;