Salome HOME
ENV: Windows porting.
[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   _OCAFApp->SaveAs(aDoc, "/dn05/salome/srn/Test.sdg");
315
316   return true;
317 }
318
319 //=============================================================================
320 /*!
321  *  Close
322  */
323 //=============================================================================
324 void GEOM_Engine::Close(int theDocID)
325 {
326   if(_mapIDDocument.IsBound(theDocID)) {
327     Handle(TDocStd_Document) aDoc = Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID));
328
329     //Remove all GEOM Objects associated to the given document
330     TColStd_SequenceOfAsciiString aSeq;
331     GEOM_DataMapIteratorOfDataMapOfAsciiStringTransient It(_objects);
332     for(; It.More(); It.Next()) {
333       TCollection_AsciiString anObjID(It.Key());
334       Standard_Integer anID = ExtractDocID(anObjID);
335       if(theDocID == anID) aSeq.Append(It.Key());
336     }
337     for(Standard_Integer i=1; i<=aSeq.Length(); i++) _objects.UnBind(aSeq.Value(i));
338
339    _mapIDDocument.UnBind(theDocID);
340     _OCAFApp->Close(aDoc);
341     aDoc.Nullify();
342   }
343 }
344
345 //=============================================================================
346 /*!
347  *  DumpPython
348  */
349 //=============================================================================
350 TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID, 
351                                                 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
352                                                 bool isPublished, 
353                                                 bool& aValidScript)
354 {
355   TCollection_AsciiString aScript;
356   Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
357   
358   if(aDoc.IsNull()) return TCollection_AsciiString("def RebuildData(theStudy): pass\n");
359  
360   aScript = "import geompy\n";
361   aScript += "import math\n\n";
362   aScript += "def RebuildData(theStudy):";
363   aScript += "\n\tgeompy.init_geom(theStudy)";
364   
365   Standard_Integer posToInertGlobalVars = aScript.Length() + 1;
366
367   Handle(TDataStd_TreeNode) aNode, aRoot;
368   Handle(GEOM_Function) aFunction;
369   TColStd_MapOfTransient aMap;
370
371   if(aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
372     TDataStd_ChildNodeIterator Itr(aRoot);
373     for(; Itr.More(); Itr.Next()) {
374       aNode = Itr.Value();
375       aFunction = GEOM_Function::GetFunction(aNode->Label());
376       if(aFunction.IsNull()) {
377         cout << "Null function !!!!" << endl;
378         continue;
379       }
380       ProcessFunction(aFunction, aScript, aMap);
381     }
382   }
383
384   Resource_DataMapOfAsciiStringAsciiString aEntry2StEntry, aStEntry2Entry;
385   Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString anEntryToNameIt;
386   // build maps entry <-> studyEntry
387   for (anEntryToNameIt.Initialize( theObjectNames );
388        anEntryToNameIt.More();
389        anEntryToNameIt.Next())
390   {
391     const TCollection_AsciiString& aEntry = anEntryToNameIt.Key();
392     // look for an object by entry
393     TDF_Label L;
394     TDF_Tool::Label( aDoc->GetData(), aEntry, L );
395     if ( L.IsNull() ) continue;
396     Handle(GEOM_Object) obj = GEOM_Object::GetObject( L );
397     // fill maps
398     if ( !obj.IsNull() ) {
399       TCollection_AsciiString aStudyEntry (obj->GetAuxData());
400       aEntry2StEntry.Bind( aEntry,  aStudyEntry);
401       aStEntry2Entry.Bind( aStudyEntry, aEntry );
402     }
403   }
404
405   Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aScript);
406   Standard_Integer aLen = aSeq->Length(), objectCounter = 0, aStart = 1, aScriptLength = aScript.Length();
407   Resource_DataMapOfAsciiStringAsciiString aNameToEntry, anEntryToBadName;
408
409   //Replace entries by the names
410   TCollection_AsciiString anUpdatedScript, anEntry, aName, aBaseName("geomObj_"),
411     allowedChars ("qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321_");
412   if(aLen == 0) anUpdatedScript = aScript;
413
414   for(Standard_Integer i = 1; i <= aLen; i+=2) {
415     anUpdatedScript += aScript.SubString(aStart, aSeq->Value(i)-1);
416     anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i+1));
417     if(theObjectNames.IsBound(anEntry)) {
418       aName = theObjectNames.Find(anEntry);
419       // check validity of aName
420       bool isValidName = true;
421       if ( aName.IsIntegerValue() ) { // aName must not start with a digit
422         aName.Insert( 1, 'a' );
423         isValidName = false;
424       }
425       int p, p2=1; // replace not allowed chars
426       while ((p = aName.FirstLocationNotInSet(allowedChars, p2, aName.Length()))) {
427         aName.SetValue(p, '_');
428         p2=p;
429         isValidName = false;
430       }
431       if ( aNameToEntry.IsBound( aName ) && anEntry != aNameToEntry( aName ))
432       {  // diff objects have same name - make a new name by appending a digit
433         TCollection_AsciiString aName2;
434         Standard_Integer i = 0;
435         do {
436           aName2 = aName + "_" + ++i;
437         } while ( aNameToEntry.IsBound( aName2 ) && anEntry != aNameToEntry( aName2 ));
438         aName = aName2;
439         isValidName = false;
440       }
441       if ( !isValidName ) {
442         if ( isPublished )
443           anEntryToBadName.Bind( anEntry, theObjectNames.Find(anEntry) );
444         theObjectNames( anEntry ) = aName;
445       }
446     }
447     else {
448       do {
449         aName = aBaseName + TCollection_AsciiString(++objectCounter);
450       } while(aNameToEntry.IsBound(aName));
451       theObjectNames.Bind(anEntry, aName);
452     }
453     aNameToEntry.Bind(aName, anEntry); // to detect same name of diff objects
454
455     anUpdatedScript += aName;
456     aStart = aSeq->Value(i+1) + 1;
457   }
458
459   //Add final part of the script
460   if(aSeq->Value(aLen) < aScriptLength)  anUpdatedScript += aScript.SubString(aSeq->Value(aLen)+1, aScriptLength);
461  
462   // Make script to publish in study
463   if ( isPublished )
464   {
465     map< int, string > anEntryToCommandMap; // sort publishing commands by object entry
466     for (anEntryToNameIt.Initialize( theObjectNames );
467          anEntryToNameIt.More();
468          anEntryToNameIt.Next())
469     {
470       const TCollection_AsciiString& aEntry = anEntryToNameIt.Key();
471       const TCollection_AsciiString& aName = anEntryToNameIt.Value();
472       if ( !aEntry2StEntry.IsBound( aEntry ))
473         continue; // was not published
474       TCollection_AsciiString aCommand("\n\tgeompy."), aFatherEntry;
475
476       // find a father entry
477       const TCollection_AsciiString& aStudyEntry = aEntry2StEntry( aEntry );
478       TCollection_AsciiString aFatherStudyEntry =
479         aStudyEntry.SubString( 1, aStudyEntry.SearchFromEnd(":") - 1 );
480       if ( aStEntry2Entry.IsBound( aFatherStudyEntry ))
481         aFatherEntry = aStEntry2Entry( aFatherStudyEntry );
482
483       // make a command
484       if ( !aFatherEntry.IsEmpty() && theObjectNames.IsBound( aFatherEntry )) {
485         aCommand += "addToStudyInFather( ";
486         aCommand += theObjectNames( aFatherEntry ) + ", ";
487       }
488       else
489         aCommand += "addToStudy( ";
490       if ( anEntryToBadName.IsBound( aEntry ))
491         aCommand += aName + ", \"" + anEntryToBadName( aEntry ) + "\" )";
492       else 
493         aCommand += aName + ", \"" + aName + "\" )";
494
495       // bind a command to the last digit of the entry
496       int tag =
497         aEntry.SubString( aEntry.SearchFromEnd(":")+1, aEntry.Length() ).IntegerValue();
498       anEntryToCommandMap.insert( make_pair( tag, aCommand.ToCString() ));
499     }
500
501     // add publishing commands to the script
502     map< int, string >::iterator anEntryToCommand = anEntryToCommandMap.begin();
503     for ( ; anEntryToCommand != anEntryToCommandMap.end(); ++anEntryToCommand ) {
504       anUpdatedScript += (char*)anEntryToCommand->second.c_str();
505     }
506   }
507
508   anUpdatedScript += "\n\tpass\n";
509   aValidScript = true;
510
511   // fill _studyEntry2NameMap and build globalVars
512   TCollection_AsciiString globalVars;
513   _studyEntry2NameMap.Clear();
514   Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString aStEntryToEntryIt;
515   for (aStEntryToEntryIt.Initialize( aStEntry2Entry );
516        aStEntryToEntryIt.More();
517        aStEntryToEntryIt.Next() )
518   {
519     const TCollection_AsciiString & name = theObjectNames( aStEntryToEntryIt.Value() );
520     _studyEntry2NameMap.Bind (aStEntryToEntryIt.Key(), name );
521     if ( !globalVars.IsEmpty() )
522       globalVars += ", ";
523     globalVars += name;
524   }
525   if ( !globalVars.IsEmpty() ) {
526     globalVars.Insert( 1, "\n\tglobal " );
527     anUpdatedScript.Insert( posToInertGlobalVars, globalVars );
528   }
529   
530   return anUpdatedScript;
531 }
532
533 //=======================================================================
534 //function : GetDumpName
535 //purpose  : 
536 //=======================================================================
537
538 const char* GEOM_Engine::GetDumpName (const char* theStudyEntry) const
539 {
540   if ( _studyEntry2NameMap.IsBound( (char*)theStudyEntry ))
541     return _studyEntry2NameMap( (char*)theStudyEntry ).ToCString();
542
543   return NULL;
544 }
545
546 //=======================================================================
547 //function : GetAllDumpNames
548 //purpose  : 
549 //=======================================================================
550
551 Handle(TColStd_HSequenceOfAsciiString) GEOM_Engine::GetAllDumpNames() const
552 {
553   Handle(TColStd_HSequenceOfAsciiString) aRetSeq = new TColStd_HSequenceOfAsciiString;
554
555   Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString it (_studyEntry2NameMap);
556   for (; it.More(); it.Next()) {
557     aRetSeq->Append(it.Value());
558   }
559
560   return aRetSeq;
561 }
562
563
564 //===========================================================================
565 //                     Internal functions
566 //===========================================================================
567 void ProcessFunction(Handle(GEOM_Function)& theFunction, 
568                      TCollection_AsciiString& theScript,
569                      TColStd_MapOfTransient& theProcessed)
570 {
571   if(theFunction.IsNull() || theProcessed.Contains(theFunction)) return;
572
573 /*
574   TDF_LabelSequence aSeq;
575   theFunction->GetDependency(aSeq);
576   Standard_Integer aLen = aSeq.Length();
577   for(Standard_Integer i = 1; i<= aLen; i++) {
578     Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(aSeq.Value(i));
579     if(aFunction.IsNull()) continue;
580     ProcessFunction(aFunction, theScript, theProcessed);
581   }
582 */
583
584   TCollection_AsciiString aDescr = theFunction->GetDescription();
585   if(aDescr.Length() == 0) {
586     //cout << "Warning: the function has no description" << endl;
587     return;
588   }
589   //Check if its internal function which doesn't requires dumping
590   if(aDescr == "None") return;
591
592   theScript += "\n\t";
593   theScript += aDescr;
594  
595   theProcessed.Add(theFunction);
596   return;
597 }
598
599 //=============================================================================
600 /*!
601  *  FindEntries: Returns a sequence of start/end positions of entries in the string
602  */
603 //=============================================================================
604 Handle(TColStd_HSequenceOfInteger) FindEntries(TCollection_AsciiString& theString)
605 {
606   Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
607   Standard_Integer aLen = theString.Length();
608   Standard_Boolean isFound = Standard_False;
609
610   char* arr = theString.ToCString();
611   Standard_Integer i = 0, j;
612
613   while(i < aLen) {
614     int c = (int)arr[i];
615     j = i+1;
616     if(c >= 48 && c <= 57) { //Is digit?
617  
618       isFound = Standard_False;
619       while((j < aLen) && ((c >= 48 && c <= 57) || c == 58) ) { //Check if it is an entry
620         c = (int)arr[j++];  
621         if(c == 58) isFound = Standard_True;
622       }
623       
624       if(isFound && arr[j-2] != 58) { // last char should be a diggit
625         aSeq->Append(i+1); // +1 because AsciiString starts from 1
626         aSeq->Append(j-1);
627       }
628     }
629      
630     i = j;
631   }
632
633   return aSeq;
634 }