Salome HOME
de5c61a12743bc3b492ab796665b79048a5d2109
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Tools.cpp
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ModelHighAPI_Tools.h"
21 #include <ModelHighAPI_FeatureStore.h>
22 //--------------------------------------------------------------------------------------
23 #include <GeomAPI_Dir.h>
24 #include <GeomAPI_Pnt.h>
25 #include <GeomAPI_Pnt2d.h>
26 //--------------------------------------------------------------------------------------
27 #include <GeomDataAPI_Dir.h>
28 #include <GeomDataAPI_Point.h>
29 #include <GeomDataAPI_Point2D.h>
30 #include <GeomDataAPI_Point2DArray.h>
31 //--------------------------------------------------------------------------------------
32 #include <GeomAlgoAPI_Tools.h>
33 //--------------------------------------------------------------------------------------
34 #include <Locale_Convert.h>
35 //--------------------------------------------------------------------------------------
36 #include <ModelAPI_AttributeBoolean.h>
37 #include <ModelAPI_AttributeDocRef.h>
38 #include <ModelAPI_AttributeDouble.h>
39 #include <ModelAPI_AttributeDoubleArray.h>
40 #include <ModelAPI_AttributeIntArray.h>
41 #include <ModelAPI_AttributeInteger.h>
42 #include <ModelAPI_AttributeRefAttr.h>
43 #include <ModelAPI_AttributeRefAttrList.h>
44 #include <ModelAPI_AttributeReference.h>
45 #include <ModelAPI_AttributeRefList.h>
46 #include <ModelAPI_AttributeSelection.h>
47 #include <ModelAPI_AttributeSelectionList.h>
48 #include <ModelAPI_AttributeString.h>
49 #include <ModelAPI_AttributeStringArray.h>
50 #include <ModelAPI_AttributeDoubleArray.h>
51 #include <ModelAPI_Session.h>
52 #include <ModelAPI_Tools.h>
53 #include <ModelAPI_ResultPart.h>
54 #include <ModelAPI_Events.h>
55 //--------------------------------------------------------------------------------------
56 #include <Config_ModuleReader.h>
57 //--------------------------------------------------------------------------------------
58 #include "ModelHighAPI_Double.h"
59 #include "ModelHighAPI_Integer.h"
60 #include "ModelHighAPI_RefAttr.h"
61 #include "ModelHighAPI_Reference.h"
62 #include "ModelHighAPI_Selection.h"
63
64 #include <Events_InfoMessage.h>
65
66 // Have to be included before std headers
67 #include <Python.h>
68
69 #include <algorithm>
70 #include <iostream>
71
72 //--------------------------------------------------------------------------------------
73 void fillAttribute(const std::shared_ptr<GeomAPI_Pnt2d> & theValue,
74                    const std::shared_ptr<GeomDataAPI_Point2D> & theAttribute)
75 {
76   theAttribute->setValue(theValue);
77 }
78
79 void fillAttribute(const std::shared_ptr<GeomDataAPI_Point2D> & theAttribute,
80                    double theX, double theY)
81 {
82   theAttribute->setValue(theX, theY);
83 }
84
85 //--------------------------------------------------------------------------------------
86 void fillAttribute(const std::shared_ptr<GeomAPI_Dir> & theValue,
87                    const std::shared_ptr<GeomDataAPI_Dir> & theAttribute)
88 {
89   theAttribute->setValue(theValue);
90 }
91
92 //--------------------------------------------------------------------------------------
93 void fillAttribute(const std::shared_ptr<GeomAPI_Pnt> & theValue,
94                    const std::shared_ptr<GeomDataAPI_Point> & theAttribute)
95 {
96   theAttribute->setValue(theValue);
97 }
98
99 //--------------------------------------------------------------------------------------
100 void fillAttribute(bool theValue,
101                    const std::shared_ptr<ModelAPI_AttributeBoolean> & theAttribute)
102 {
103   theAttribute->setValue(theValue);
104 }
105
106 //--------------------------------------------------------------------------------------
107 void fillAttribute(const ModelHighAPI_Double & theValue,
108                    const std::shared_ptr<ModelAPI_AttributeDouble> & theAttribute)
109 {
110   theValue.fillAttribute(theAttribute);
111 }
112 void fillAttribute(double theValue,
113                    const std::shared_ptr<ModelAPI_AttributeDouble> & theAttribute)
114 {
115   theAttribute->setValue(theValue);
116 }
117
118 //--------------------------------------------------------------------------------------
119 void fillAttribute(const ModelHighAPI_Integer & theValue,
120                    const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute)
121 {
122   theValue.fillAttribute(theAttribute);
123 }
124 void fillAttribute(int theValue,
125                    const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute)
126 {
127   theAttribute->setValue(theValue);
128 }
129
130 //--------------------------------------------------------------------------------------
131 void fillAttribute(const ModelHighAPI_RefAttr & theValue,
132                    const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
133 {
134   theValue.fillAttribute(theAttribute);
135 }
136
137 //--------------------------------------------------------------------------------------
138 void fillAttribute(const std::list<ModelHighAPI_RefAttr> & theValue,
139                    const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute)
140 {
141   theAttribute->clear();
142   for (auto it = theValue.begin(); it != theValue.end(); ++it)
143     it->appendToList(theAttribute);
144 }
145
146 //--------------------------------------------------------------------------------------
147 void fillAttribute(const ModelHighAPI_Reference & theValue,
148                    const std::shared_ptr<ModelAPI_AttributeReference> & theAttribute)
149 {
150   theValue.fillAttribute(theAttribute);
151 }
152
153 //--------------------------------------------------------------------------------------
154 void fillAttribute(const std::list<ModelHighAPI_Reference> & theValue,
155                    const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
156 {
157   theAttribute->clear();
158   for (auto it = theValue.begin(); it != theValue.end(); ++it)
159     it->appendToList(theAttribute);
160 }
161
162 //--------------------------------------------------------------------------------------
163 void fillAttribute(const std::shared_ptr<ModelAPI_Object> & theValue,
164                    const std::shared_ptr<ModelAPI_AttributeReference> & theAttribute)
165 {
166   theAttribute->setValue(theValue);
167 }
168
169 //--------------------------------------------------------------------------------------
170 void fillAttribute(const std::list<std::shared_ptr<ModelAPI_Object> > & theValue,
171                    const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
172 {
173   int aSize = theAttribute->size();
174   // keep objects at the beginning of the list if they the same
175   auto it = theValue.begin();
176   for (int anIndex = 0; it != theValue.end() && anIndex < aSize; ++it, ++anIndex)
177     if (theAttribute->object(anIndex) != *it) {
178       // remove the tail of the list
179       while (++anIndex <= aSize)
180         theAttribute->removeLast();
181       break;
182     }
183   // append the rest of elements
184   for (; it != theValue.end(); ++it)
185     theAttribute->append(*it);
186 }
187
188 MODELHIGHAPI_EXPORT
189 void fillAttribute(const std::list<ModelHighAPI_Selection> & theValue,
190                    const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
191 {
192   theAttribute->clear();
193   for (auto it = theValue.begin(); it != theValue.end(); ++it) {
194     if (it->resultSubShapePair().first)
195       theAttribute->append(it->resultSubShapePair().first); // use only context
196   }
197 }
198
199 //--------------------------------------------------------------------------------------
200 void fillAttribute(const ModelHighAPI_Selection & theValue,
201                    const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
202 {
203   theValue.fillAttribute(theAttribute);
204 }
205
206 //--------------------------------------------------------------------------------------
207 void fillAttribute(const std::list<ModelHighAPI_Selection> & theValue,
208                    const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute)
209 {
210   theAttribute->clear();
211
212   if(!theValue.empty() && theAttribute->selectionType().empty()) {
213     const ModelHighAPI_Selection& aSelection = theValue.front();
214     GeomAPI_Shape::ShapeType aSelectionType = getShapeType(aSelection);
215     theAttribute->setSelectionType(strByShapeType(aSelectionType));
216   }
217
218   for (auto it = theValue.begin(); it != theValue.end(); ++it)
219     it->appendToList(theAttribute);
220 }
221
222 //--------------------------------------------------------------------------------------
223 void fillAttribute(const std::string & theValue,
224                    const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
225 {
226   theAttribute->setValue(theValue);
227 }
228
229 //--------------------------------------------------------------------------------------
230 void fillAttribute(const std::wstring & theValue,
231   const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
232 {
233   theAttribute->setValue(theValue);
234 }
235
236 //--------------------------------------------------------------------------------------
237 void fillAttribute(const char * theValue,
238                    const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
239 {
240   theAttribute->setValue(theValue);
241 }
242
243 //--------------------------------------------------------------------------------------
244 void fillAttribute(const std::list<std::string> & theValue,
245                    const std::shared_ptr<ModelAPI_AttributeStringArray> & theAttribute)
246 {
247   theAttribute->setSize(int(theValue.size()));
248
249   int anIndex = 0;
250   for (auto it = theValue.begin(); it != theValue.end(); ++it, ++anIndex)
251     theAttribute->setValue(anIndex, *it);
252 }
253
254 //--------------------------------------------------------------------------------------
255 void fillAttribute(const std::list<ModelHighAPI_Integer> & theValue,
256                    const std::shared_ptr<ModelAPI_AttributeIntArray> & theAttribute)
257 {
258   theAttribute->setSize(int(theValue.size()));
259
260   int anIndex = 0;
261   for (auto it = theValue.begin(); it != theValue.end(); ++it, ++anIndex)
262     theAttribute->setValue(anIndex, it->intValue()); // use only values, no text support in array
263 }
264
265 //--------------------------------------------------------------------------------------
266 void fillAttribute(const std::list<ModelHighAPI_Double> & theValue,
267                    const std::shared_ptr<ModelAPI_AttributeDoubleArray> & theAttribute)
268 {
269   theAttribute->setSize(int(theValue.size()));
270
271   int anIndex = 0;
272   for (auto it = theValue.begin(); it != theValue.end(); ++it, ++anIndex)
273     theAttribute->setValue(anIndex, it->value()); // use only values, no text support in array
274 }
275
276 //--------------------------------------------------------------------------------------
277 void fillAttribute(const std::list<std::shared_ptr<GeomAPI_Pnt2d> > & theValue,
278                    const std::shared_ptr<GeomDataAPI_Point2DArray> & theAttribute)
279 {
280   theAttribute->setSize(int(theValue.size()));
281
282   int anIndex = 0;
283   for (auto it = theValue.begin(); it != theValue.end(); ++it, ++anIndex)
284     theAttribute->setPnt(anIndex, *it);
285 }
286
287 //--------------------------------------------------------------------------------------
288 void fillAttribute(const ModelHighAPI_Double & theX,
289                    const ModelHighAPI_Double & theY,
290                    const ModelHighAPI_Double & theZ,
291                    const std::shared_ptr<GeomDataAPI_Point> & theAttribute)
292 {
293   theX.fillAttribute(theAttribute, theX, theY, theZ);
294 }
295
296 //==================================================================================================
297 GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr)
298 {
299   GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
300
301   std::transform(theShapeTypeStr.begin(), theShapeTypeStr.end(), theShapeTypeStr.begin(),
302                  [](char c) { return static_cast<char>(::tolower(c)); });
303
304   if(theShapeTypeStr == "compound") {
305     aShapeType = GeomAPI_Shape::COMPOUND;
306   } else if(theShapeTypeStr == "compsolid") {
307     aShapeType = GeomAPI_Shape::COMPSOLID;
308   } else if(theShapeTypeStr == "solid") {
309     aShapeType = GeomAPI_Shape::SOLID;
310   } else if(theShapeTypeStr == "shell") {
311     aShapeType = GeomAPI_Shape::SHELL;
312   } else if(theShapeTypeStr == "face") {
313     aShapeType = GeomAPI_Shape::FACE;
314   } else if(theShapeTypeStr == "wire") {
315     aShapeType = GeomAPI_Shape::WIRE;
316   } else if(theShapeTypeStr == "edge") {
317     aShapeType = GeomAPI_Shape::EDGE;
318   } else if(theShapeTypeStr == "vertex") {
319     aShapeType = GeomAPI_Shape::VERTEX;
320   } else if(theShapeTypeStr == "shape") {
321     aShapeType = GeomAPI_Shape::SHAPE;
322   }
323
324   return aShapeType;
325 }
326
327 std::string strByShapeType(GeomAPI_Shape::ShapeType theShapeType)
328 {
329   std::string aShapeTypeStr;
330   switch (theShapeType) {
331   case GeomAPI_Shape::COMPOUND:
332     aShapeTypeStr = "COMPOUND";
333     break;
334   case GeomAPI_Shape::COMPSOLID:
335     aShapeTypeStr = "COMPSOLID";
336     break;
337   case GeomAPI_Shape::SOLID:
338     aShapeTypeStr = "SOLID";
339     break;
340   case GeomAPI_Shape::SHELL:
341     aShapeTypeStr = "SHELL";
342     break;
343   case GeomAPI_Shape::FACE:
344     aShapeTypeStr = "FACE";
345     break;
346   case GeomAPI_Shape::WIRE:
347     aShapeTypeStr = "WIRE";
348     break;
349   case GeomAPI_Shape::EDGE:
350     aShapeTypeStr = "EDGE";
351     break;
352   case GeomAPI_Shape::VERTEX:
353     aShapeTypeStr = "VERTEX";
354     break;
355   default:
356     aShapeTypeStr = "SHAPE";
357     break;
358   }
359   return aShapeTypeStr;
360 }
361
362 //==================================================================================================
363 GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection)
364 {
365   GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
366
367   switch(theSelection.variantType()) {
368     case ModelHighAPI_Selection::VT_ResultSubShapePair: {
369       ResultSubShapePair aPair = theSelection.resultSubShapePair();
370       GeomShapePtr aShape = aPair.second;
371       if(!aShape.get() && aPair.first.get()) {
372         aShape = aPair.first->shape();
373       }
374       if(!aShape.get()) {
375         return aShapeType;
376       }
377       aShapeType = aShape->shapeType();
378       break;
379     }
380     case ModelHighAPI_Selection::VT_TypeSubShapeNamePair: {
381       TypeSubShapeNamePair aPair = theSelection.typeSubShapeNamePair();
382       std::string aType = aPair.first;
383       aShapeType = shapeTypeByStr(aType);
384       break;
385     }
386     case ModelHighAPI_Selection::VT_TypeInnerPointPair: {
387       TypeInnerPointPair aPair = theSelection.typeInnerPointPair();
388       std::string aType = aPair.first;
389       aType = aType.substr(0, aType.find_first_of('_'));
390       aShapeType = shapeTypeByStr(aType);
391       break;
392     }
393     case ModelHighAPI_Selection::VT_WeakNamingPair: {
394       TypeWeakNamingPair aPair = theSelection.typeWeakNamingPair();
395       std::string aType = aPair.first;
396       aShapeType = shapeTypeByStr(aType);
397       break;
398     }
399     default:
400       break; // do nothing [to avoid compilation warning]
401   }
402
403   return aShapeType;
404 }
405
406 //--------------------------------------------------------------------------------------
407 ModelAPI_AttributeTables::ValueType valueTypeByStr(const std::string& theValueTypeStr)
408 {
409   std::string aType = theValueTypeStr;
410   std::transform(aType.begin(), aType.end(), aType.begin(),
411                  [](char c) { return static_cast<char>(::tolower(c)); });
412   if (aType == "boolean")
413     return ModelAPI_AttributeTables::BOOLEAN;
414   else if (aType == "integer")
415     return ModelAPI_AttributeTables::INTEGER;
416   else if (aType == "string")
417     return ModelAPI_AttributeTables::STRING;
418   return ModelAPI_AttributeTables::DOUBLE; // default
419 }
420
421 //--------------------------------------------------------------------------------------
422 std::string strByValueType(const ModelAPI_AttributeTables::ValueType theType)
423 {
424   switch(theType) {
425   case ModelAPI_AttributeTables::BOOLEAN: return "BOOLEAN";
426   case ModelAPI_AttributeTables::INTEGER: return "INTEGER";
427   case ModelAPI_AttributeTables::DOUBLE: return "DOUBLE";
428   case ModelAPI_AttributeTables::STRING: return "STRING";
429   }
430   return ""; // bad case
431 }
432
433 /// stores the features information, recursively stores sub-documents features
434 std::string storeFeatures(const std::wstring& theDocName, DocumentPtr theDoc,
435   std::map<std::wstring, std::map<std::wstring, ModelHighAPI_FeatureStore> >& theStore,
436   const bool theCompare) // if false => store
437 {
438   std::map<std::wstring, std::map<std::wstring, ModelHighAPI_FeatureStore> >::iterator aDocFind;
439   if (theCompare) {
440      aDocFind = theStore.find(theDocName);
441      if (aDocFind == theStore.end()) {
442        return "Document '" + Locale::Convert::toString(theDocName) + "' not found";
443      }
444   }
445   // store the model features information: iterate all features
446   size_t anObjectsCount = 0; // stores the number of compared features for this document to compare
447   std::set<std::wstring> aProcessed; // processed features names (that are in the current document)
448
449   // process all objects (features and folders)
450   std::list<ObjectPtr> allObjects = theDoc->allObjects();
451   std::list<ObjectPtr>::iterator allIter = allObjects.begin();
452   for(; allIter != allObjects.end(); allIter++) {
453     ObjectPtr anObject = *allIter;
454     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
455     //if (aFeature && aFeature->getKind() == "SketchConstraintCoincidenceInternal")
456
457     if (aFeature) {
458       std::string aStr = aFeature->getKind().substr(0, 16);
459       if (aStr == "SketchConstraint")
460         continue; // no need to dump and check constraints
461     }
462     if (theCompare) {
463       std::map<std::wstring, ModelHighAPI_FeatureStore>::iterator
464         anObjFind = aDocFind->second.find(anObject->data()->name());
465       if (anObjFind == aDocFind->second.end()) {
466         return "Document '" + Locale::Convert::toString(theDocName)
467           + "' feature '" + Locale::Convert::toString(anObject->data()->name()) + "' not found";
468       }
469       std::string anError = anObjFind->second.compare(anObject);
470       if (!anError.empty()) {
471         anError = "Document " + Locale::Convert::toString(theDocName) + " " + anError;
472         return anError;
473       }
474       anObjectsCount++;
475       aProcessed.insert(anObject->data()->name());
476     } else {
477       theStore[theDocName][anObject->data()->name()] = ModelHighAPI_FeatureStore(anObject);
478     }
479
480     if (aFeature) {
481       // iterate all results of this feature
482       std::list<ResultPtr> allResults;
483       ModelAPI_Tools::allResults(aFeature, allResults);
484       std::list<ResultPtr>::iterator aRes = allResults.begin();
485       for(; aRes != allResults.end(); aRes++) {
486         // recursively store features of sub-documents
487         if ((*aRes)->groupName() == ModelAPI_ResultPart::group()) {
488           DocumentPtr aDoc = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes)->partDoc();
489           if (aDoc.get()) {
490             std::string anError =
491                 storeFeatures((*aRes)->data()->name(), aDoc, theStore, theCompare);
492             if (!anError.empty())
493               return anError;
494           }
495         }
496       }
497     }
498   }
499   // checks the number of compared features
500   if (theCompare) {
501     if (aDocFind->second.size() != anObjectsCount) {
502       // search for disappeared feature
503       std::wstring aLostName;
504       std::map<std::wstring, ModelHighAPI_FeatureStore>::iterator aLostIter;
505       for(aLostIter = aDocFind->second.begin(); aLostIter != aDocFind->second.end(); aLostIter++) {
506         if (aProcessed.find(aLostIter->first) == aProcessed.end()) {
507           aLostName = aLostIter->first;
508         }
509       }
510       return "For document '" + Locale::Convert::toString(theDocName) +
511         "' the number of features is decreased, there is no feature '" +
512         Locale::Convert::toString(aLostName) + "'";
513     }
514   }
515   return ""; // ok
516 }
517
518 //==================================================================================================
519 typedef std::map<std::wstring, std::map<std::wstring, ModelHighAPI_FeatureStore> > Storage;
520
521 static bool dumpToPython(SessionPtr theSession,
522                          const std::string& theFilename,
523                          const checkDumpType theSelectionType,
524                          const std::string& theErrorMsgContext)
525 {
526   // 2431: set PartSet as a current document
527   theSession->setActiveDocument(theSession->moduleDocument(), true);
528   // dump all to the python file
529   theSession->startOperation("Check python dump");
530   FeaturePtr aDump = theSession->moduleDocument()->addFeature("Dump");
531   if (aDump.get()) {
532     aDump->string("file_path")->setValue(theFilename);
533     aDump->string("file_format")->setValue("py");
534     std::string aTrek = GeomAlgoAPI_Tools::File_Tools::path(theFilename);
535     aDump->string("dump_dir")->setValue(aTrek);
536     aDump->boolean("topological_naming")->setValue((theSelectionType & CHECK_NAMING) != 0);
537     aDump->boolean("geometric_selection")->setValue((theSelectionType & CHECK_GEOMETRICAL) != 0);
538     aDump->boolean("weak_naming")->setValue((theSelectionType & CHECK_WEAK) != 0);
539   }
540   bool isProblem = !aDump.get() || !aDump->error().empty(); // after "finish" dump will be removed
541   if (isProblem && aDump.get()) {
542     std::cout << "Dump feature error " << aDump->error() << std::endl;
543     Events_InfoMessage anErrorMsg(theErrorMsgContext, aDump->error());
544     anErrorMsg.send();
545   }
546   theSession->finishOperation();
547   return !isProblem;
548 }
549
550 static bool checkDump(SessionPtr theSession,
551                       const char* theFilename,
552                       Storage& theStorage,
553                       const std::string& theErrorMsgContext)
554 {
555
556   // close all before importation of the script
557   theSession->closeAll();
558
559   // execute the dumped
560   PyGILState_STATE gstate = PyGILState_Ensure(); /* acquire python thread */
561   static char aReadMode[] = "r";
562   FILE* PyFileObject = fopen(theFilename, aReadMode);
563   PyRun_SimpleFileEx(PyFileObject, theFilename, 1);
564   PyGILState_Release(gstate); /* release python thread */
565
566   // compare with the stored data
567   std::string anError =
568     storeFeatures(Locale::Convert::toWString(theSession->moduleDocument()->kind()),
569     theSession->moduleDocument(), theStorage, true);
570   if (!anError.empty()) {
571     std::cout << anError << std::endl;
572     Events_InfoMessage anErrorMsg(theErrorMsgContext, anError);
573     anErrorMsg.send();
574     return false;
575   }
576
577   return true;
578 }
579
580 bool checkPyDump(
581 #ifdef _DEBUG
582   const std::string&, const std::string&, const std::string&,
583 #else
584   const std::string& theFilenameNaming,
585   const std::string& theFilenameGeo,
586   const std::string& theFilenameWeak,
587 #endif
588   const checkDumpType theCheckType)
589 {
590   static const std::string anErrorByNaming("checkPythonDump by naming");
591   static const std::string anErrorByGeometry("checkPythonDump by geometry");
592   static const std::string anErrorByWeak("checkPythonDump by weak naming");
593
594 #ifdef _DEBUG
595   std::string aFileForNamingDump("./check_dump.py");
596   std::string aFileForGeometryDump("./check_dump_geo.py");
597   std::string aFileForWeakDump("./check_dump_weak.py");
598 #else
599   std::string aFileForNamingDump = theFilenameNaming;
600   std::string aFileForGeometryDump = theFilenameGeo;
601   std::string aFileForWeakDump = theFilenameWeak;
602 #endif
603
604   SessionPtr aSession = ModelAPI_Session::get();
605   // dump with the specified types
606   std::string aFileName = theCheckType == CHECK_GEOMETRICAL ? aFileForGeometryDump :
607                           (theCheckType == CHECK_WEAK ? aFileForWeakDump : aFileForNamingDump);
608   if (!dumpToPython(aSession, aFileName, theCheckType, anErrorByNaming))
609     return false;
610
611    // map from document name to feature name to feature data
612   std::map<std::wstring, std::map<std::wstring, ModelHighAPI_FeatureStore> > aStore;
613   std::string anError =
614     storeFeatures(Locale::Convert::toWString(aSession->moduleDocument()->kind()),
615     aSession->moduleDocument(), aStore, false);
616   if (!anError.empty()) {
617     Events_InfoMessage anErrorMsg(std::string("checkPythonDump"), anError);
618     anErrorMsg.send();
619     return false;
620   }
621
622   bool isOk = true;
623   if (theCheckType & CHECK_NAMING) {
624     // check dump with the selection by names
625     isOk = checkDump(aSession, aFileForNamingDump.c_str(), aStore, anErrorByNaming);
626   }
627   if (theCheckType & CHECK_GEOMETRICAL) {
628     // check dump with the selection by geometry
629     isOk = isOk && checkDump(aSession, aFileForGeometryDump.c_str(), aStore, anErrorByGeometry);
630   }
631   if (theCheckType & CHECK_WEAK) {
632     isOk = isOk && checkDump(aSession, aFileForWeakDump.c_str(), aStore, anErrorByWeak);
633   }
634
635   return isOk;
636 }
637
638 //--------------------------------------------------------------------------------------