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