Salome HOME
Copyrights update
[modules/geom.git] / src / GEOM / GEOM_Engine.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 #ifdef WNT
21 #pragma warning( disable:4786 )
22 #endif
23
24 #include "GEOM_Engine.hxx"
25
26 #include "GEOM_Solver.hxx"
27 #include "GEOM_Function.hxx"
28 #include "GEOM_ISubShape.hxx"
29 #include "GEOM_SubShapeDriver.hxx"
30 #include "GEOM_DataMapIteratorOfDataMapOfAsciiStringTransient.hxx"
31 #include "GEOM_PythonDump.hxx"
32
33 #include "utilities.h"
34
35 #include <TDF_Tool.hxx>
36 #include <TDF_Data.hxx>
37 #include <TDF_LabelSequence.hxx>
38 #include <TDataStd_Integer.hxx>
39 #include <TDataStd_ChildNodeIterator.hxx>
40 #include <TFunction_Driver.hxx>
41 #include <TFunction_DriverTable.hxx>
42
43 #include <TopExp.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
45
46 #include <TCollection_AsciiString.hxx>
47 #include <TCollection_ExtendedString.hxx>
48 #include <TColStd_SequenceOfAsciiString.hxx>
49 #include <TColStd_MapOfTransient.hxx>
50 #include <TColStd_HSequenceOfInteger.hxx>
51
52 #include <Interface_DataMapIteratorOfDataMapOfIntegerTransient.hxx>
53 #include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
54
55 #include <map>
56 #include <string>
57
58 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
59
60 static GEOM_Engine* TheEngine = NULL;
61
62 static TCollection_AsciiString BuildIDFromObject(Handle(GEOM_Object)& theObject)
63 {
64   TCollection_AsciiString anID(theObject->GetDocID()), anEntry;
65   TDF_Tool::Entry(theObject->GetEntry(), anEntry);
66   anID+=(TCollection_AsciiString("_")+anEntry);
67   return anID;
68 }
69
70 static TCollection_AsciiString BuildID(Standard_Integer theDocID, char* theEntry)
71 {
72   TCollection_AsciiString anID(theDocID);
73   anID+=(TCollection_AsciiString("_")+theEntry);
74   return anID;
75 }
76
77 static Standard_Integer ExtractDocID(TCollection_AsciiString& theID)
78 {
79   TCollection_AsciiString aDocID = theID.Token("_");
80   if(aDocID.Length() < 1) return -1;
81   return aDocID.IntegerValue();
82 }
83
84 void ProcessFunction(Handle(GEOM_Function)& theFunction, 
85                      TCollection_AsciiString& theScript,
86                      TColStd_MapOfTransient& theProcessed);
87
88 Handle(TColStd_HSequenceOfInteger) FindEntries(TCollection_AsciiString& theString);
89
90 //=============================================================================
91 /*!
92  *  GetEngine
93  */
94 //=============================================================================
95 GEOM_Engine* GEOM_Engine::GetEngine() { return TheEngine; }
96
97
98 //=============================================================================
99 /*!
100  *  SetEngine
101  */
102 //=============================================================================
103 void GEOM_Engine::SetEngine(GEOM_Engine* theEngine) { TheEngine = theEngine; }
104
105 //=============================================================================
106 /*!
107  *  Constructor
108  */
109 //=============================================================================
110 GEOM_Engine::GEOM_Engine()
111 {
112   TFunction_DriverTable::Get()->AddDriver(GEOM_Object::GetSubShapeID(), new GEOM_SubShapeDriver());
113
114   _OCAFApp = new GEOM_Application();
115   _UndoLimit = 10;
116 }
117
118 //=============================================================================
119 /*!
120  *  GetDocument
121  */
122 //=============================================================================
123 Handle(TDocStd_Document) GEOM_Engine::GetDocument(int theDocID)
124 {
125   Handle(TDocStd_Document) aDoc;
126   if(!_mapIDDocument.IsBound(theDocID)) {
127     _OCAFApp->NewDocument("SALOME_GEOM", aDoc);
128     aDoc->SetUndoLimit(_UndoLimit);
129     _mapIDDocument.Bind(theDocID, aDoc);
130     TDataStd_Integer::Set(aDoc->Main(), theDocID);
131   }
132
133   return Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID));
134 }
135
136 //=============================================================================
137 /*!
138  *  GetDocID
139  */
140 //=============================================================================
141 int GEOM_Engine::GetDocID(Handle(TDocStd_Document) theDocument)
142 {
143   if(theDocument.IsNull()) return -1;
144   for(Interface_DataMapIteratorOfDataMapOfIntegerTransient anItr(_mapIDDocument); anItr.More(); anItr.Next())
145     if(anItr.Value() == theDocument) return anItr.Key();
146
147   return -1;
148
149 }
150
151 //=============================================================================
152 /*!
153  *  GetObject
154  */
155 //=============================================================================
156 Handle(GEOM_Object) GEOM_Engine::GetObject(int theDocID, char* theEntry)
157 {
158   TCollection_AsciiString anID = BuildID(theDocID, theEntry);
159   if(_objects.IsBound(anID)) return Handle(GEOM_Object)::DownCast(_objects(anID));
160
161   TDF_Label aLabel;
162   Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
163   TDF_Tool::Label(aDoc->Main().Data(), theEntry, aLabel, Standard_True);
164   Handle(GEOM_Object) anObject = new GEOM_Object(aLabel);
165
166   _objects.Bind(anID, anObject);
167
168   return anObject;
169 }
170
171 //=============================================================================
172 /*!
173  *  AddObject
174  */
175 //=============================================================================
176 Handle(GEOM_Object) GEOM_Engine::AddObject(int theDocID, int theType)
177 {
178     Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
179     Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
180
181     TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main());
182     Handle(GEOM_Object) anObject = new GEOM_Object(aChild, theType);
183
184     //Put an object in the map of created objects
185     TCollection_AsciiString anID = BuildIDFromObject(anObject);
186     if(_objects.IsBound(anID)) _objects.UnBind(anID);
187     _objects.Bind(anID, anObject);
188
189     return anObject;
190 }
191
192 //=============================================================================
193 /*!
194  *  AddSubShape
195  */
196 //=============================================================================
197 Handle(GEOM_Object) GEOM_Engine::AddSubShape(Handle(GEOM_Object) theMainShape, 
198                                              Handle(TColStd_HArray1OfInteger) theIndices,
199                                              bool isStandaloneOperation)
200 {
201   if(theMainShape.IsNull() || theIndices.IsNull()) return NULL;
202
203   Handle(TDocStd_Document) aDoc = GetDocument(theMainShape->GetDocID());
204   Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
205
206   TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main());
207
208   Handle(GEOM_Function) aMainShape = theMainShape->GetLastFunction();
209   Handle(GEOM_Object) anObject = new GEOM_Object(aChild, 28); //28 is SUBSHAPE type
210   Handle(GEOM_Function) aFunction = anObject->AddFunction(GEOM_Object::GetSubShapeID(), 1);
211
212   GEOM_ISubShape aSSI(aFunction);
213   aSSI.SetMainShape(aMainShape);
214   aSSI.SetIndices(theIndices);
215
216   try {
217     GEOM_Solver aSolver (GEOM_Engine::GetEngine());
218     if (!aSolver.ComputeFunction(aFunction)) {
219       MESSAGE("GEOM_Engine::AddSubShape Error: Can't build a sub shape");
220       return NULL;
221     }
222   }
223   catch (Standard_Failure) {
224     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
225     MESSAGE("GEOM_Engine::AddSubShape Error: " << aFail->GetMessageString());
226     return NULL;
227   }
228
229   //Put an object in the map of created objects
230   TCollection_AsciiString anID = BuildIDFromObject(anObject);
231   if(_objects.IsBound(anID)) _objects.UnBind(anID);
232   _objects.Bind(anID, anObject);
233
234   GEOM::TPythonDump pd (aFunction);
235  
236   if (isStandaloneOperation) {
237     pd << anObject << " = geompy.GetSubShape(" << theMainShape << ", [";
238     Standard_Integer i = theIndices->Lower(), up = theIndices->Upper();
239     for (; i <= up - 1; i++) {
240       pd << theIndices->Value(i) << ", ";
241     }
242     pd << theIndices->Value(up) << "])";
243   }
244   else
245     pd << "None";
246
247   return anObject;
248 }
249
250 //=============================================================================
251 /*!
252  *  RemoveObject
253  */
254 //=============================================================================
255 bool GEOM_Engine::RemoveObject(Handle(GEOM_Object) theObject)
256 {
257   if(!theObject) return false;
258
259   //Remove an object from the map of available objects
260   TCollection_AsciiString anID = BuildIDFromObject(theObject);
261   if(_objects.IsBound(anID)) _objects.UnBind(anID);
262
263   int nb = theObject->GetNbFunctions();
264   Handle(TDataStd_TreeNode) aNode;
265   for(int i = 1; i<=nb; i++) {
266     Handle(GEOM_Function) aFunction = theObject->GetFunction(i);
267     if(aFunction->GetEntry().FindAttribute(GEOM_Function::GetFunctionTreeID(), aNode)) 
268       aNode->Remove();
269   }
270
271   TDF_Label aLabel = theObject->GetEntry();
272   aLabel.ForgetAllAttributes(Standard_True);
273
274   theObject.Nullify();
275
276   return true;
277 }
278
279 //=============================================================================
280 /*!
281  *  Undo
282  */
283 //=============================================================================
284 void GEOM_Engine::Undo(int theDocID)
285 {
286   GetDocument(theDocID)->Undo();
287 }
288
289 //=============================================================================
290 /*!
291  *  Redo
292  */
293 //=============================================================================
294 void GEOM_Engine::Redo(int theDocID)
295 {
296   GetDocument(theDocID)->Redo();
297 }
298
299 //=============================================================================
300 /*!
301  *  Save
302  */
303 //=============================================================================
304 bool GEOM_Engine::Save(int theDocID, char* theFileName)
305 {
306   if(!_mapIDDocument.IsBound(theDocID)) return false;
307   Handle(TDocStd_Document) aDoc = Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID));
308
309   _OCAFApp->SaveAs(aDoc, theFileName);
310
311   return true;
312 }
313
314 //=============================================================================
315 /*!
316  *  Load
317  */
318 //=============================================================================
319 bool GEOM_Engine::Load(int theDocID, char* theFileName)
320 {
321   Handle(TDocStd_Document) aDoc;
322   if(_OCAFApp->Open(theFileName, aDoc) != CDF_RS_OK) {
323     return false;
324   }
325
326   aDoc->SetUndoLimit(_UndoLimit);
327
328   if(_mapIDDocument.IsBound(theDocID)) _mapIDDocument.UnBind(theDocID);
329   _mapIDDocument.Bind(theDocID, aDoc);
330
331   TDataStd_Integer::Set(aDoc->Main(), theDocID);
332
333   return true;
334 }
335
336 //=============================================================================
337 /*!
338  *  Close
339  */
340 //=============================================================================
341 void GEOM_Engine::Close(int theDocID)
342 {
343   if(_mapIDDocument.IsBound(theDocID)) {
344     Handle(TDocStd_Document) aDoc = Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID));
345
346     //Remove all GEOM Objects associated to the given document
347     TColStd_SequenceOfAsciiString aSeq;
348     GEOM_DataMapIteratorOfDataMapOfAsciiStringTransient It(_objects);
349     for(; It.More(); It.Next()) {
350       TCollection_AsciiString anObjID(It.Key());
351       Standard_Integer anID = ExtractDocID(anObjID);
352       if(theDocID == anID) aSeq.Append(It.Key());
353     }
354     for(Standard_Integer i=1; i<=aSeq.Length(); i++) _objects.UnBind(aSeq.Value(i));
355
356    _mapIDDocument.UnBind(theDocID);
357     _OCAFApp->Close(aDoc);
358     aDoc.Nullify();
359   }
360 }
361
362 //=============================================================================
363 /*!
364  *  DumpPython
365  */
366 //=============================================================================
367 TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID, 
368                                                 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
369                                                 bool isPublished, 
370                                                 bool& aValidScript)
371 {
372   TCollection_AsciiString aScript;
373   Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
374   
375   if(aDoc.IsNull()) return TCollection_AsciiString("def RebuildData(theStudy): pass\n");
376  
377   aScript = "import geompy\n";
378   aScript += "import math\n\n";
379   aScript += "def RebuildData(theStudy):";
380   aScript += "\n\tgeompy.init_geom(theStudy)";
381   
382   Standard_Integer posToInertGlobalVars = aScript.Length() + 1;
383
384   Handle(TDataStd_TreeNode) aNode, aRoot;
385   Handle(GEOM_Function) aFunction;
386   TColStd_MapOfTransient aMap;
387
388   if(aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
389     TDataStd_ChildNodeIterator Itr(aRoot);
390     for(; Itr.More(); Itr.Next()) {
391       aNode = Itr.Value();
392       aFunction = GEOM_Function::GetFunction(aNode->Label());
393       if(aFunction.IsNull()) {
394         cout << "Null function !!!!" << endl;
395         continue;
396       }
397       ProcessFunction(aFunction, aScript, aMap);
398     }
399   }
400
401   Resource_DataMapOfAsciiStringAsciiString aEntry2StEntry, aStEntry2Entry;
402   Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString anEntryToNameIt;
403   // build maps entry <-> studyEntry
404   for (anEntryToNameIt.Initialize( theObjectNames );
405        anEntryToNameIt.More();
406        anEntryToNameIt.Next())
407   {
408     const TCollection_AsciiString& aEntry = anEntryToNameIt.Key();
409     // look for an object by entry
410     TDF_Label L;
411     TDF_Tool::Label( aDoc->GetData(), aEntry, L );
412     if ( L.IsNull() ) continue;
413     Handle(GEOM_Object) obj = GEOM_Object::GetObject( L );
414     // fill maps
415     if ( !obj.IsNull() ) {
416       TCollection_AsciiString aStudyEntry (obj->GetAuxData());
417       aEntry2StEntry.Bind( aEntry,  aStudyEntry);
418       aStEntry2Entry.Bind( aStudyEntry, aEntry );
419     }
420   }
421
422   Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aScript);
423   Standard_Integer aLen = aSeq->Length(), objectCounter = 0, aStart = 1, aScriptLength = aScript.Length();
424   Resource_DataMapOfAsciiStringAsciiString aNameToEntry, anEntryToBadName;
425
426   //Replace entries by the names
427   TCollection_AsciiString anUpdatedScript, anEntry, aName, aBaseName("geomObj_"),
428     allowedChars ("qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321_");
429   if(aLen == 0) anUpdatedScript = aScript;
430
431   for(Standard_Integer i = 1; i <= aLen; i+=2) {
432     anUpdatedScript += aScript.SubString(aStart, aSeq->Value(i)-1);
433     anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i+1));
434     if(theObjectNames.IsBound(anEntry)) {
435       aName = theObjectNames.Find(anEntry);
436       // check validity of aName
437       bool isValidName = true;
438       if ( aName.IsIntegerValue() ) { // aName must not start with a digit
439         aName.Insert( 1, 'a' );
440         isValidName = false;
441       }
442       int p, p2=1; // replace not allowed chars
443       while ((p = aName.FirstLocationNotInSet(allowedChars, p2, aName.Length()))) {
444         aName.SetValue(p, '_');
445         p2=p;
446         isValidName = false;
447       }
448       if ( aNameToEntry.IsBound( aName ) && anEntry != aNameToEntry( aName ))
449       {  // diff objects have same name - make a new name by appending a digit
450         TCollection_AsciiString aName2;
451         Standard_Integer i = 0;
452         do {
453           aName2 = aName + "_" + ++i;
454         } while ( aNameToEntry.IsBound( aName2 ) && anEntry != aNameToEntry( aName2 ));
455         aName = aName2;
456         isValidName = false;
457       }
458       if ( !isValidName ) {
459         if ( isPublished )
460           anEntryToBadName.Bind( anEntry, theObjectNames.Find(anEntry) );
461         theObjectNames( anEntry ) = aName;
462       }
463     }
464     else {
465       do {
466         aName = aBaseName + TCollection_AsciiString(++objectCounter);
467       } while(aNameToEntry.IsBound(aName));
468       theObjectNames.Bind(anEntry, aName);
469     }
470     aNameToEntry.Bind(aName, anEntry); // to detect same name of diff objects
471
472     anUpdatedScript += aName;
473     aStart = aSeq->Value(i+1) + 1;
474   }
475
476   //Add final part of the script
477   if(aSeq->Value(aLen) < aScriptLength)  anUpdatedScript += aScript.SubString(aSeq->Value(aLen)+1, aScriptLength);
478  
479   // Make script to publish in study
480   if ( isPublished )
481   {
482     map< int, string > anEntryToCommandMap; // sort publishing commands by object entry
483     for (anEntryToNameIt.Initialize( theObjectNames );
484          anEntryToNameIt.More();
485          anEntryToNameIt.Next())
486     {
487       const TCollection_AsciiString& aEntry = anEntryToNameIt.Key();
488       const TCollection_AsciiString& aName = anEntryToNameIt.Value();
489       if ( !aEntry2StEntry.IsBound( aEntry ))
490         continue; // was not published
491       TCollection_AsciiString aCommand("\n\tgeompy."), aFatherEntry;
492
493       // find a father entry
494       const TCollection_AsciiString& aStudyEntry = aEntry2StEntry( aEntry );
495       TCollection_AsciiString aFatherStudyEntry =
496         aStudyEntry.SubString( 1, aStudyEntry.SearchFromEnd(":") - 1 );
497       if ( aStEntry2Entry.IsBound( aFatherStudyEntry ))
498         aFatherEntry = aStEntry2Entry( aFatherStudyEntry );
499
500       // make a command
501       if ( !aFatherEntry.IsEmpty() && theObjectNames.IsBound( aFatherEntry )) {
502         aCommand += "addToStudyInFather( ";
503         aCommand += theObjectNames( aFatherEntry ) + ", ";
504       }
505       else
506         aCommand += "addToStudy( ";
507       if ( anEntryToBadName.IsBound( aEntry ))
508         aCommand += aName + ", \"" + anEntryToBadName( aEntry ) + "\" )";
509       else 
510         aCommand += aName + ", \"" + aName + "\" )";
511
512       // bind a command to the last digit of the entry
513       int tag =
514         aEntry.SubString( aEntry.SearchFromEnd(":")+1, aEntry.Length() ).IntegerValue();
515       anEntryToCommandMap.insert( make_pair( tag, aCommand.ToCString() ));
516     }
517
518     // add publishing commands to the script
519     map< int, string >::iterator anEntryToCommand = anEntryToCommandMap.begin();
520     for ( ; anEntryToCommand != anEntryToCommandMap.end(); ++anEntryToCommand ) {
521       anUpdatedScript += (char*)anEntryToCommand->second.c_str();
522     }
523   }
524
525   anUpdatedScript += "\n\tpass\n";
526   aValidScript = true;
527
528   // fill _studyEntry2NameMap and build globalVars
529   TCollection_AsciiString globalVars;
530   _studyEntry2NameMap.Clear();
531   Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString aStEntryToEntryIt;
532   for (aStEntryToEntryIt.Initialize( aStEntry2Entry );
533        aStEntryToEntryIt.More();
534        aStEntryToEntryIt.Next() )
535   {
536     const TCollection_AsciiString & name = theObjectNames( aStEntryToEntryIt.Value() );
537     _studyEntry2NameMap.Bind (aStEntryToEntryIt.Key(), name );
538     if ( !globalVars.IsEmpty() )
539       globalVars += ", ";
540     globalVars += name;
541   }
542   if ( !globalVars.IsEmpty() ) {
543     globalVars.Insert( 1, "\n\tglobal " );
544     anUpdatedScript.Insert( posToInertGlobalVars, globalVars );
545   }
546   
547   return anUpdatedScript;
548 }
549
550 //=======================================================================
551 //function : GetDumpName
552 //purpose  : 
553 //=======================================================================
554
555 const char* GEOM_Engine::GetDumpName (const char* theStudyEntry) const
556 {
557   if ( _studyEntry2NameMap.IsBound( (char*)theStudyEntry ))
558     return _studyEntry2NameMap( (char*)theStudyEntry ).ToCString();
559
560   return NULL;
561 }
562
563 //=======================================================================
564 //function : GetAllDumpNames
565 //purpose  : 
566 //=======================================================================
567
568 Handle(TColStd_HSequenceOfAsciiString) GEOM_Engine::GetAllDumpNames() const
569 {
570   Handle(TColStd_HSequenceOfAsciiString) aRetSeq = new TColStd_HSequenceOfAsciiString;
571
572   Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString it (_studyEntry2NameMap);
573   for (; it.More(); it.Next()) {
574     aRetSeq->Append(it.Value());
575   }
576
577   return aRetSeq;
578 }
579
580
581 //===========================================================================
582 //                     Internal functions
583 //===========================================================================
584 void ProcessFunction(Handle(GEOM_Function)& theFunction, 
585                      TCollection_AsciiString& theScript,
586                      TColStd_MapOfTransient& theProcessed)
587 {
588   if(theFunction.IsNull() || theProcessed.Contains(theFunction)) return;
589
590 /*
591   TDF_LabelSequence aSeq;
592   theFunction->GetDependency(aSeq);
593   Standard_Integer aLen = aSeq.Length();
594   for(Standard_Integer i = 1; i<= aLen; i++) {
595     Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(aSeq.Value(i));
596     if(aFunction.IsNull()) continue;
597     ProcessFunction(aFunction, theScript, theProcessed);
598   }
599 */
600
601   TCollection_AsciiString aDescr = theFunction->GetDescription();
602   if(aDescr.Length() == 0) {
603     //cout << "Warning: the function has no description" << endl;
604     return;
605   }
606   //Check if its internal function which doesn't requires dumping
607   if(aDescr == "None") return;
608
609   theScript += "\n\t";
610   theScript += aDescr;
611  
612   theProcessed.Add(theFunction);
613   return;
614 }
615
616 //=============================================================================
617 /*!
618  *  FindEntries: Returns a sequence of start/end positions of entries in the string
619  */
620 //=============================================================================
621 Handle(TColStd_HSequenceOfInteger) FindEntries(TCollection_AsciiString& theString)
622 {
623   Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
624   Standard_Integer aLen = theString.Length();
625   Standard_Boolean isFound = Standard_False;
626
627   char* arr = theString.ToCString();
628   Standard_Integer i = 0, j;
629
630   while(i < aLen) {
631     int c = (int)arr[i];
632     j = i+1;
633     if(c >= 48 && c <= 57) { //Is digit?
634  
635       isFound = Standard_False;
636       while((j < aLen) && ((c >= 48 && c <= 57) || c == 58) ) { //Check if it is an entry
637         c = (int)arr[j++];  
638         if(c == 58) isFound = Standard_True;
639       }
640       
641       if(isFound && arr[j-2] != 58) { // last char should be a diggit
642         aSeq->Append(i+1); // +1 because AsciiString starts from 1
643         aSeq->Append(j-1);
644       }
645     }
646      
647     i = j;
648   }
649
650   return aSeq;
651 }