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