]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Tools.cxx
Salome HOME
PAL9807
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : VisuGUI_Tools.cxx
25 //  Author : Sergey Anikin
26 //  Module : VISU
27
28
29 #include "VisuGUI_Tools.h"
30
31 #include "VISU_Gen_i.hh"
32 #include "VISU_Prs3d_i.hh"
33 #include "VISU_Result_i.hh"
34 #include "VISU_Table_i.hh"
35 #include "VISU_Mesh_i.hh"
36 #include "VISU_ViewManager_i.hh"
37
38 #include "VISU_Actor.h"
39
40 #include "SalomeApp_Module.h"
41 #include "SalomeApp_Study.h"
42 #include "SalomeApp_Application.h"
43 #include "SalomeApp_SelectionMgr.h"
44
45 #include "SALOME_ListIO.hxx"
46 #include "SALOME_ListIteratorOfListIO.hxx"
47
48 #include "SVTK_ViewWindow.h"
49 #include "SVTK_ViewModel.h"
50 #include "SVTK_Functor.h"
51
52 #include "VTKViewer_Algorithm.h"
53
54 #include "SPlot2d_ViewModel.h"
55 #include "Plot2d_ViewFrame.h"
56
57 #include "SUIT_Session.h"
58 #include "SUIT_MessageBox.h"
59
60 #include <vtkRenderer.h>
61 #include <vtkActorCollection.h>
62
63
64 //=============================================================================
65 namespace VISU
66 {
67   SUIT_Desktop*
68   GetDesktop(const CAM_Module* theModule)
69   {
70     return theModule->application()->desktop();
71   }
72
73   SalomeApp_SelectionMgr*
74   GetSelectionMgr(const SalomeApp_Module* theModule)
75   {
76     return theModule->getApp()->selectionMgr();
77   }
78
79   SalomeApp_Study*
80   GetAppStudy(const CAM_Module* theModule)
81   {
82     return
83       dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy());
84   }
85
86   _PTR(Study)
87   GetCStudy(const SalomeApp_Study* theStudy)
88   {
89     return theStudy->studyDS();
90   }
91
92   bool
93   IsStudyLocked( _PTR(Study) theStudy )
94   {
95     if( theStudy )
96       return theStudy->GetProperties()->IsLocked();
97     return true;
98   }
99
100   bool
101   CheckLock( _PTR(Study) theStudy )
102   {
103     if(IsStudyLocked(theStudy))
104       throw std::runtime_error(QObject::tr("WRN_STUDY_LOCKED").latin1());
105     return false;
106   }
107
108   VISU_Gen_i*
109   GetVisuGen(const CAM_Module* theModule)
110   {
111     static VISU_Gen_i* aGen = NULL;
112     if(!aGen){
113       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
114       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
115       VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
116       if(!CORBA::is_nil(aVISU)){
117         aGen = VISU_Gen_i::GetVisuGenImpl();
118         aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
119       }
120     }
121     if(!aGen)
122       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").latin1());
123     return aGen;
124   }
125
126   SALOME_MED::MED_Gen_var
127   GetMEDEngine()
128   {
129     static SALOME_MED::MED_Gen_var aGen;
130     if(CORBA::is_nil(aGen)){
131       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
132       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
133       aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
134     }
135     if(CORBA::is_nil(aGen))
136       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").latin1());
137     return aGen;
138   }
139
140
141   VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject)
142   {
143     VISU::Storable::TRestoringMap aMap;
144     if (theSObject) {
145       _PTR(GenericAttribute) anAttr;
146       if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
147         _PTR(AttributeComment) aComment (anAttr);
148         std::string aValue = aComment->Value();
149         QString aString (aValue.c_str());
150         VISU::Storable::StrToMap(aString, aMap);
151       }
152     }
153     return aMap;
154   }
155
156   QString getValue (_PTR(SObject) theSObject, QString theKey)
157   {
158     QString aStr("");
159     VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
160     if (!aMap.empty())
161       aStr = VISU::Storable::FindValue(aMap, theKey.latin1());
162     return aStr;
163   }
164
165   //------------------------------------------------------------
166   // Selection
167   CORBA::Object_var
168   GetSelectedObj(const SalomeApp_Study* theStudy,
169                  const QString& theEntry,
170                  VISU::Storable::TRestoringMap* theMap)
171   {
172     if (!theStudy || theEntry.isEmpty())
173       return CORBA::Object::_nil();
174
175     _PTR(Study) aStudy = GetCStudy(theStudy);
176     _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry.latin1());
177     if (aSObject) {
178       _PTR(GenericAttribute) anAttr;
179       if (theMap && aSObject->FindAttribute(anAttr,"AttributeComment")) {
180         _PTR(AttributeComment) aComment (anAttr);
181         std::string aValue = aComment->Value();
182         QString aString (aValue.c_str());
183         VISU::Storable::StrToMap(aString, *theMap);
184       }
185       return VISU::ClientSObjectToObject(aSObject);
186     }
187     return CORBA::Object::_nil();
188   }
189
190   CORBA::Object_var
191   GetSelectedObj(const SalomeApp_Module* theModule,
192                  Handle(SALOME_InteractiveObject)* theIO,
193                  VISU::Storable::TRestoringMap* theMap)
194   {
195     SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
196     SALOME_ListIO aListIO;
197     aSelectionMgr->selectedObjects(aListIO);
198     SALOME_ListIteratorOfListIO anIter(aListIO);
199     if(anIter.More()){
200       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
201       if(theIO)
202         *theIO = anIO;
203       if(anIO->hasEntry())
204         return GetSelectedObj( GetAppStudy(theModule), anIO->getEntry(), theMap );
205     }
206     return CORBA::Object::_nil();
207   }
208
209   VISU::Prs3d_i*
210   GetPrsToModify(const SalomeApp_Module* theModule,
211                  Handle(SALOME_InteractiveObject)* theIO,
212                  VISU::Storable::TRestoringMap* theMap)
213   {
214     if (CheckLock(GetCStudy(GetAppStudy(theModule))))
215       return NULL;
216     
217     CORBA::Object_var anObject = GetSelectedObj(theModule, theIO);
218     if (CORBA::is_nil(anObject)) 
219       return NULL;
220
221     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
222     if (!aServant.in()) 
223       return NULL;
224     
225     return dynamic_cast<VISU::Prs3d_i*>(aServant.in());
226   }
227
228   void
229   Add(SalomeApp_SelectionMgr* theSelectionMgr,
230       const Handle(SALOME_InteractiveObject)& theIO)
231   {
232     SALOME_ListIO aListIO;
233     theSelectionMgr->selectedObjects(aListIO);
234     aListIO.Append(theIO);
235     theSelectionMgr->setSelectedObjects(aListIO);
236   }
237
238   void
239   Remove(SalomeApp_SelectionMgr* theSelectionMgr,
240          const Handle(SALOME_InteractiveObject)& theIO)
241   {
242     if (theIO.IsNull()) return;
243     SALOME_ListIO aListIO, aNewListIO;
244     theSelectionMgr->selectedObjects(aListIO);
245     SALOME_ListIteratorOfListIO anIter (aListIO);
246     for (; anIter.More(); anIter.Next()) {
247       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
248       if (!anIO->isSame(theIO)) {
249         aNewListIO.Append(theIO);
250       }
251     }
252     theSelectionMgr->setSelectedObjects(aNewListIO);
253   }
254
255   /*!
256    * \brief Check, if "Delete" popup-menu can be put on current selection
257    *
258    * \param theModule - is used to access SelectionManager, Study and VISU_Gen
259    * \retval bool - returns TRUE if all currently selected objects are removable
260    */
261   bool
262   IsRemovableSelected (const SalomeApp_Module* theModule)
263   {
264     SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
265     SALOME_ListIO aListIO;
266     aSelectionMgr->selectedObjects(aListIO);
267
268     if (aListIO.Extent() < 1)
269       return false;
270
271     _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
272     if (!aStudy) return false;
273
274     // In some cases single selection can have its own popup-menu item for deletion
275     /*if (aListIO.Extent() == 1) {
276       Handle(SALOME_InteractiveObject) anIO = aListIO.First();
277       _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
278       if (aSObject) {
279         VISU::VISUType aType = (VISU::VISUType)getValue(aSObject, "myType").toInt();
280         if (aType == VISU::TVIEW3D) {
281           return false; // special case
282         }
283       }
284     }*/
285
286     SALOME_ListIteratorOfListIO anIter (aListIO);
287     for (; anIter.More(); anIter.Next()) {
288       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
289       if (anIO->hasEntry()) {
290         _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
291         VISU::Storable::TRestoringMap pMap;
292         if (aSObject) {
293           CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
294           if (!CORBA::is_nil(aCORBAObject)) {
295             VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
296             if (CORBA::is_nil(aRemovableObj)) {
297               // Not removable CORBA object
298               return false;
299             }
300           } else {
301             // Can be removed, if lays directly under VISU
302             // (first sub-level) or is a child of such an object
303             string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
304             _PTR(GenericAttribute) anAttr;
305             _PTR(AttributeComment) aComment;
306
307             bool isUnderVISU = false;
308             _PTR(SObject) aFatherSObject = aSObject->GetFather();
309             if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
310               _PTR(AttributeComment) aComment (anAttr);
311               aNAME = aComment->Value();
312               if (aNAME == aVisuNAME) {
313                 isUnderVISU = true;
314               }
315             }
316             if (!isUnderVISU) {
317               // Not directly under VISU component, check father
318               aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
319               if (!CORBA::is_nil(aCORBAObject)) {
320                 // Father has IOR
321                 return false;
322               }
323
324               isUnderVISU = false;
325               aFatherSObject = aFatherSObject->GetFather();
326               if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
327                 _PTR(AttributeComment) aComment (anAttr);
328                 aNAME = aComment->Value();
329                 if (aNAME == aVisuNAME) {
330                   isUnderVISU = true;
331                 }
332               }
333               if (!isUnderVISU) {
334                 // Father is not directly under VISU component
335                 return false;
336               }
337             }
338           }
339         }
340       }
341     }
342     return true;
343   }
344
345   //************************************************************
346   // Display/Erase
347
348   void
349   ErasePrs (const SalomeApp_Module* theModule,
350             CORBA::Object_ptr theObject, bool theUpdate)
351   {
352     if (!CORBA::is_nil(theObject)) {
353       VISU::Base_var aBase = VISU::Base::_narrow(theObject);
354       if (CORBA::is_nil(aBase)) return;
355       VISU::VISUType aType = aBase->GetType();
356       switch (aType) {
357       case VISU::TCURVE:
358         {
359           if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aBase).in()))
360             PlotCurve(theModule, aCurve, VISU::eErase );
361           break;
362         }
363       case VISU::TCONTAINER:
364         {
365           if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aBase).in()))
366             PlotContainer(theModule, aContainer, VISU::eErase );
367           break;
368         }
369       case VISU::TTABLE:
370         {
371           if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aBase).in()))
372             PlotTable(theModule, aTable, VISU::eErase );
373           break;
374         }
375       default:
376         {
377           if (VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aBase).in())) {
378             ErasePrs3d(theModule, aPrsObject);
379             if (theUpdate) {
380               if (SVTK_ViewWindow* vw = GetViewWindow(theModule))
381                 vw->Repaint();
382             }
383           }
384         }
385       } // switch (aType)
386     }
387   }
388
389   void
390   DeleteSObject (SalomeApp_Module* theModule,
391                  _PTR(Study)       theStudy,
392                  _PTR(SObject)     theSObject)
393   {
394     SalomeApp_Study* study = GetAppStudy( theModule );
395     study->deleteReferencesTo( theSObject );
396
397     _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
398     for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
399       _PTR(SObject) aChildSObject = aChildIter->Value();
400       study->deleteReferencesTo( aChildSObject );
401       CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
402       ErasePrs(theModule, aChildObj);
403     }
404
405     CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
406     if (!CORBA::is_nil(anObj)) {
407       ErasePrs(theModule, anObj);
408
409       VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
410       if (!CORBA::is_nil(aRemovableObject)) {
411         aRemovableObject->RemoveFromStudy();
412       }
413     } else {
414       // Remove aSObject together with all its sub-objects
415       
416       VISU::RemoveFromStudy(theSObject,
417                             false,  // remove not only IOR attribute, but Object With Children
418                             false); // not Destroy() sub-objects
419     }
420   }
421
422   void
423   DeletePrs3d(SalomeApp_Module* theModule,
424               VISU::Prs3d_i* thePrs,
425               const Handle(SALOME_InteractiveObject)& theIO)
426   {
427     if (!thePrs)
428       return;
429     if (CheckLock(GetCStudy(GetAppStudy(theModule))))
430       return;
431     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
432     CORBA::String_var anEntry = aSObject->GetID();
433     SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
434     Remove(aSelectionMgr,theIO);
435     TViewWindows aViewWindows = GetViews(theModule);
436     for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
437       SVTK_ViewWindow* aView = aViewWindows[i];
438       if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
439         aView->RemoveActor(anActor);
440         anActor->Delete();
441       }
442     }
443     thePrs->RemoveFromStudy();
444   }
445
446   void
447   ErasePrs3d(const SalomeApp_Module* theModule,
448              VISU::Prs3d_i* thePrs)
449   {
450     if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
451       VISU_Actor* anVISUActor = FindActor( vw, thePrs );
452       if (anVISUActor) {
453         anVISUActor->VisibilityOff();
454       }
455     }
456   }
457
458   //************************************************************
459   // Presentation management
460
461   void
462   ChangeRepresentation (const SalomeApp_Module* theModule,
463                         VISU::PresentationType  theType)
464   {
465     SUIT_ViewWindow* aView = GetActiveView(theModule, VTKViewer_Viewer::Type());
466     if (!aView) return;
467     SVTK_ViewWindow* vw  = (SVTK_ViewWindow*) aView;
468
469     Handle(SALOME_InteractiveObject) anIO;
470     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
471     if (CORBA::is_nil(anObject)) return;
472     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
473     if (!aServant.in()) return;
474
475     VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
476     if (aPrs3d) {
477       if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
478         switch (theType) {
479         case VISU::SHRINK:
480           if (anActor->IsShrunk())
481             anActor->UnShrink();
482           else
483             anActor->SetShrink();
484           break;
485         default:
486           if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
487             aMesh->SetPresentationType(theType);
488             RecreateActor(theModule, aMesh);
489           } else {
490             anActor->SetRepresentation(theType);
491           }
492         }
493         vw->Repaint();
494       }
495     }
496   }
497
498   //************************************************************
499   // SObject type
500
501   bool
502   CheckTimeStamp(const SalomeApp_Module* theModule,
503                  _PTR(SObject)&          theSObject,
504                  Handle(SALOME_InteractiveObject)* theIO)
505   {
506     Handle(SALOME_InteractiveObject) anIO;
507     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
508     if (theIO)
509       *theIO = anIO;
510     if (!anIO.IsNull() && anIO->hasEntry()){
511       _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
512       theSObject = aStudy->FindObjectID(anIO->getEntry());
513       QString aValue = getValue(theSObject,"myType");
514       if (aValue.toInt() == int(VISU::TTIMESTAMP))
515         return true;
516     }
517     SUIT_MessageBox::warn1(GetDesktop(theModule),
518                            QObject::tr("WRN_VISU"),
519                            QObject::tr("WRN_NO_AVAILABLE_DATA"),
520                            QObject::tr("BUT_OK") );
521     return false;
522   }
523
524   VISU::Result_i*
525   CheckResult(const SalomeApp_Module* theModule,
526               _PTR(SObject)           theSource,
527               VISU::Result_var&       theResult)
528   {
529     _PTR(SObject) aSObj = theSource->GetFather();
530     if (!aSObj)
531       return NULL;
532
533     aSObj = aSObj->GetFather();
534     if (!aSObj)
535       return NULL;
536
537     aSObj = aSObj->GetFather();
538     if (!aSObj)
539       return NULL;
540
541     CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
542     if (CORBA::is_nil(anObject)) {
543       aSObj = aSObj->GetFather();
544       if (!aSObj)
545         return NULL;
546       anObject = VISU::ClientSObjectToObject(aSObj);
547     }
548
549     if (CORBA::is_nil(anObject))
550       return NULL;
551
552     theResult = VISU::Result::_narrow(anObject);
553     VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
554     if (pResult == NULL)
555       SUIT_MessageBox::warn1(GetDesktop(theModule),
556                              QObject::tr("WRN_VISU"),
557                              QObject::tr("WRN_NO_AVAILABLE_DATA"),
558                              QObject::tr("BUT_OK"));
559     return pResult;
560   }
561
562   //************************************************************
563   // Views
564
565   SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
566   {
567     if(SalomeApp_Application* anApp = theModule->getApp()){
568       if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
569         if (!theType.isNull()) {
570           if (aViewManager->getType() != theType)
571             return 0;
572         }
573         return aViewManager->getActiveView();
574       }
575     }
576     return 0;
577   }
578
579   //************************************************************
580   // VTK View
581
582   TViewWindows
583   GetViews(const SalomeApp_Module* theModule)
584   {
585     TViewWindows aViewWindows;
586     if(SalomeApp_Application* anApp = theModule->getApp()){
587       ViewManagerList aViewManagerList;
588       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
589       QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
590       while(SUIT_ViewManager* aViewManager = anIter.current()){
591         QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
592         for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
593           if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
594             if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
595               aViewWindows.push_back(aView);
596         }
597         ++anIter;
598       }
599     }
600     return aViewWindows;
601   }
602
603   SVTK_ViewWindow*
604   GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
605   {
606     if(SalomeApp_Application* anApp = theModule->getApp()){
607       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
608         if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
609           return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
610         }
611       }
612     }
613     return NULL;
614   }
615
616
617   SVTK_ViewWindow*
618   GetViewWindow()
619   {
620     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
621       (SUIT_Session::session()->activeApplication());
622     if (anApp) {
623       if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
624         if (aViewManager->getType() == SVTK_Viewer::Type()) {
625           if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
626             return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
627           }
628         }
629       }
630     }
631     return NULL;
632   }
633
634   VISU_Actor*
635   PublishInView(const SalomeApp_Module* theModule,
636                 VISU::Prs3d_i* thePrs)
637   {
638     VISU_Actor* aActor = NULL;
639     if(!thePrs)
640       return aActor;
641     if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
642       QApplication::setOverrideCursor( Qt::waitCursor );
643       try{
644         if(aActor = thePrs->CreateActor())
645           aView->AddActor(aActor);
646       }catch(std::exception& exc){
647         SUIT_MessageBox::warn1(GetDesktop(theModule),
648                                QObject::tr("WRN_VISU"),
649                                QObject::tr("ERR_CANT_CREATE_ACTOR"),
650                                QObject::tr("BUT_OK"));
651       }
652       QApplication::restoreOverrideCursor();
653     }
654     return aActor;
655   }
656
657   VISU_Actor*
658   UpdateViewer(const SalomeApp_Module* theModule,
659                VISU::Prs3d_i* thePrs,
660                bool theDispOnly)
661   {
662     SVTK_ViewWindow* vw = GetViewWindow( theModule );
663     if (!vw) return NULL;
664
665     vtkRenderer *aRen = vw->getRenderer();
666     vtkActorCollection *anActColl = aRen->GetActors();
667
668     vtkActor *anActor;
669     VISU_Actor* anVISUActor = NULL;
670     VISU_Actor* aResActor = NULL;
671     for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
672       if(!SALOME_Actor::SafeDownCast(anActor))
673         continue;
674       if(anActor->IsA("VISU_Actor")){
675         anVISUActor = VISU_Actor::SafeDownCast(anActor);
676         VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
677         if(aPrs == NULL) continue;
678         if (thePrs == aPrs) {
679           aResActor = anVISUActor->GetParent();
680           thePrs->UpdateActor(aResActor);
681           aResActor->VisibilityOn();
682
683         } else if (theDispOnly) {
684           anVISUActor->GetParent()->VisibilityOff();
685         } else {
686         }
687       } else if (theDispOnly && anActor->GetVisibility()) {
688         anActor->VisibilityOff();
689       } else {
690       }
691     }
692     if (aResActor)
693       return aResActor;
694
695     anVISUActor = PublishInView( theModule, thePrs );
696     return anVISUActor;
697   }
698
699   void
700   RepaintViewWindows (const SalomeApp_Module* theModule,
701                       const Handle(SALOME_InteractiveObject)& theIObject)
702   {
703     TViewWindows aViewWindows;
704     if (SalomeApp_Application* anApp = theModule->getApp()) {
705       ViewManagerList aViewManagerList;
706       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
707       QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
708       while (SUIT_ViewManager* aViewManager = anIter.current()) {
709         QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
710         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
711           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
712             if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
713               if (vw->isVisible(theIObject)) {
714                 vw->getRenderer()->ResetCameraClippingRange();
715                 vw->Repaint();
716                 vw->highlight(theIObject, true, true);
717               }
718             }
719           }
720         }
721         ++anIter;
722       }
723     }
724   }
725
726   VISU_Actor*
727   FindActor(SVTK_ViewWindow* theViewWindow,
728             const char* theEntry)
729   {
730     using namespace VTK;
731     if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
732       if(vtkActorCollection* aCollection = aRenderer->GetActors()){
733         if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
734           return anActor->GetParent();
735         }
736       }
737     }
738     return NULL;
739   }
740
741   VISU_Actor*
742   FindActor(SVTK_ViewWindow* theViewWindow,
743             VISU::Prs3d_i* thePrs)
744   {
745     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
746     CORBA::String_var anEntry = aSObject->GetID();
747     return FindActor(theViewWindow,anEntry.in());
748   }
749
750   void
751   RecreateActor (const SalomeApp_Module* theModule,
752                  VISU::Prs3d_i* thePrs)
753   {
754     QApplication::setOverrideCursor(Qt::waitCursor);
755
756     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
757     CORBA::String_var anEntry = aSObject->GetID();
758
759     try {
760       thePrs->Update();
761
762       TViewWindows aViewWindows = GetViews(theModule);
763       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
764         SVTK_ViewWindow* aView = aViewWindows[i];
765         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
766           thePrs->UpdateActor(anActor);
767         }
768       }
769     } catch (std::runtime_error& ex) {
770       INFOS(ex.what());
771       QApplication::restoreOverrideCursor();
772       SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
773                               QObject::tr("ERR_CANT_BUILD_PRESENTATION") + " " + QObject::tr(ex.what()),
774                               QObject::tr("BUT_OK"));
775
776       TViewWindows aViewWindows = GetViews(theModule);
777       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
778         SVTK_ViewWindow* aView = aViewWindows[i];
779         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
780           aView->RemoveActor(anActor);
781           anActor->Delete();
782         }
783       }
784       return;
785     }
786     QApplication::restoreOverrideCursor();
787   }
788
789   //************************************************************
790   // Plot2d View
791
792   SPlot2d_Viewer*
793   GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
794   {
795     if(SalomeApp_Application* anApp = theModule->getApp()){
796       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
797         return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
798       }
799     }
800     return NULL;
801   }
802
803   // Internal function used by several public functions below
804   void
805   UpdateCurve(VISU::Curve_i* theCurve,
806               Plot2d_ViewFrame* aPlot,
807               SPlot2d_Curve* plotCurve,
808               int theDisplaying)
809   {
810     if ( theDisplaying == VISU::eErase ) {
811       if ( plotCurve )
812         aPlot->eraseCurve( plotCurve, false );
813     }
814     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
815       if ( plotCurve ) {
816         plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
817         //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
818         plotCurve->setVerTitle( theCurve->GetName() );
819         plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
820         plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
821         double* xList = 0;
822         double* yList = 0;
823         int     nbPoints = theCurve->GetData( xList, yList );
824         if ( nbPoints > 0 && xList && yList ) {
825           plotCurve->setData( xList, yList, nbPoints );
826         }
827         if ( !theCurve->IsAuto() ) {
828           plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
829           plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
830           SALOMEDS::Color color = theCurve->GetColor();
831           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
832         }
833         plotCurve->setAutoAssign( theCurve->IsAuto() );
834         aPlot->displayCurve( plotCurve, false );
835       }
836       else {
837         Plot2d_Curve* crv = theCurve->CreatePresentation();
838         if ( crv ) {
839           aPlot->displayCurve( crv, false );
840           theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
841           theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
842           SALOMEDS::Color newColor;
843           newColor.R = crv->getColor().red()/255.;
844           newColor.G = crv->getColor().green()/255.;
845           newColor.B = crv->getColor().blue()/255.;
846           theCurve->SetColor( newColor );
847           crv->setAutoAssign( theCurve->IsAuto() );
848         }
849       }
850     }
851   }
852
853   void
854   PlotTable(const SalomeApp_Module* theModule,
855             VISU::Table_i* table,
856             int theDisplaying)
857   {
858     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
859     if ( !aView )
860       return;
861     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
862     if ( !aPlot )
863       return;
864
865     if ( theDisplaying == VISU::eDisplayOnly )
866       aPlot->EraseAll();
867     QList<Plot2d_Curve> clist;
868     aPlot->getCurves( clist );
869     _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
870     _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
871     if ( TableSO ) {
872       _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
873       for ( ; Iter->More(); Iter->Next() ) {
874         CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
875         if( !CORBA::is_nil( childObject ) ) {
876           CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
877           if( !CORBA::is_nil( aCurve ) ) {
878             VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
879             SPlot2d_Curve* plotCurve = 0;
880             SPlot2d_Curve* tmpCurve;
881             for ( int i = 0; i < clist.count(); i++ ) {
882               tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
883               if (tmpCurve && tmpCurve->hasIO() &&
884                   !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
885                 plotCurve = tmpCurve;
886                 break;
887               }
888             }
889
890             UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
891
892             if ( theDisplaying == VISU::eErase && plotCurve ) {
893               clist.remove( plotCurve );
894             }
895           }
896         }
897       }
898       aPlot->Repaint();
899     }
900   }
901
902   void
903   PlotCurve(const SalomeApp_Module* theModule,
904             VISU::Curve_i* theCurve,
905             int theDisplaying)
906   {
907     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
908     if ( !aView )
909       return;
910     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
911     if ( !aPlot )
912       return;
913
914 //  if ( theDisplaying == VISU::eDisplayOnly )
915 //    aPlot->EraseAll();
916     QList<Plot2d_Curve> clist;
917     aPlot->getCurves( clist );
918     SPlot2d_Curve* plotCurve = 0;
919     SPlot2d_Curve* tmpCurve;
920     for (int i = 0; i < clist.count(); i++) {
921       tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
922       if (tmpCurve && tmpCurve->hasIO() &&
923           !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
924         plotCurve = tmpCurve;
925       } else if (theDisplaying == VISU::eDisplayOnly) {
926         aPlot->eraseCurve(clist.at(i));
927       }
928     }
929
930     UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
931
932     aPlot->Repaint();
933   }
934
935   void
936   PlotContainer(const SalomeApp_Module* theModule,
937                 VISU::Container_i* container,
938                 int theDisplaying)
939   {
940     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
941     if ( !aView )
942       return;
943     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
944     if ( !aPlot )
945       return;
946
947     if ( theDisplaying == VISU::eDisplayOnly )
948       aPlot->EraseAll();
949     QList<Plot2d_Curve> clist;
950     aPlot->getCurves( clist );
951     if ( container->GetNbCurves() > 0 ) {
952       int nbCurves = container->GetNbCurves();
953       for ( int k = 1; k <= nbCurves; k++ ) {
954         VISU::Curve_i* theCurve = container->GetCurve( k );
955         if ( theCurve && theCurve->IsValid() ) {
956           SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
957             (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
958
959           UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
960
961           if ( plotCurve && theDisplaying == VISU::eErase ) {
962             clist.remove( plotCurve );
963           }
964         }
965       }
966     }
967     aPlot->Repaint();
968   }
969
970   void
971   CreatePlot(SalomeApp_Module* theModule,
972              _PTR(SObject) theTableSO)
973   {
974     if ( IsSObjectTable(theTableSO) ) {
975       CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
976       CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
977       if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
978         VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
979         VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
980
981         if ( pContainer && pTable ) {
982           for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
983             CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
984             if( !CORBA::is_nil( aNewCurve ) ) {
985               VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
986               if ( pCrv ) {
987                 pContainer->AddCurve( pCrv->_this() );
988               }
989             }
990           }
991           PlotContainer( theModule, pContainer, VISU::eDisplay );
992         }
993       }
994     }
995   }
996
997   //************************************************************
998   // Others
999
1000   void CreateMesh (const SalomeApp_Module* theModule,
1001                     const Handle(SALOME_InteractiveObject)& theIO)
1002   {
1003     _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1004     //if (CheckLock(aStudy))
1005     //  return;
1006
1007     _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1008
1009     // Get VISU::Result
1010     VISU::Result_var aResult;
1011     VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1012     if (pResult == NULL)
1013       return;
1014
1015     Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1016     bool isExist;
1017     string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1018     if (!isExist)
1019       return;
1020
1021     CORBA::Object_var aMesh;
1022     string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1023 #ifdef CHECKTIME
1024     Utils_Timer timer;
1025     timer.Start();
1026 #endif
1027     if (aComment == "ENTITY") {
1028       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1029       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1030         aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1031     } else if (aComment == "FAMILY") {
1032       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1033       string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1034       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1035         aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1036           (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1037     } else if (aComment == "GROUP") {
1038       string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1039       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1040         aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1041     }
1042 #ifdef CHECKTIME
1043     timer.Stop();
1044     MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1045     timer.Show();
1046 #endif
1047
1048     QApplication::restoreOverrideCursor();
1049     VISU::Mesh_i* pPresent = NULL;
1050     if (!CORBA::is_nil(aMesh))
1051       pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1052     if (pPresent == NULL) {
1053       SUIT_MessageBox::warn1 (GetDesktop(theModule),
1054                               QObject::tr("WRN_VISU"),
1055                               QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1056                               QObject::tr("BUT_OK"));
1057       return;
1058     }
1059
1060     if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) {
1061       try {
1062 #ifdef CHECKTIME
1063         Utils_Timer timer;
1064         timer.Start();
1065 #endif
1066         PublishInView(theModule, pPresent);
1067         aView->onFitAll();
1068 #ifdef CHECKTIME
1069         timer.Stop();
1070         MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1071         timer.Show();
1072 #endif
1073         theModule->application()->putInfo(QObject::tr("INF_DONE"));
1074         // Make "Save" button active
1075         theModule->getApp()->updateActions();
1076       } catch (std::runtime_error& exc) {
1077         INFOS(exc.what());
1078         SUIT_MessageBox::warn1 (GetDesktop(theModule),
1079                                 QObject::tr("WRN_VISU"),
1080                                 QObject::tr("ERR_CANT_CREATE_ACTOR") + " " + QObject::tr(exc.what()),
1081                                 QObject::tr("BUT_OK"));
1082       }
1083     }
1084   }
1085
1086   // ========================================================================================
1087   // GetPrs3dList: find list of presentations for the given object
1088   // ========================================================================================
1089   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1090                                             const Handle(SALOME_InteractiveObject)& theIO)
1091   {
1092     std::vector<VISU::Prs3d_i*> aList;
1093     if (!theIO.IsNull() && theIO->hasEntry()) {
1094       _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1095       _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1096       aList = GetPrs3dList(theModule, aSObject);
1097     }
1098     return aList;
1099   }
1100
1101   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1102                                             _PTR(SObject) theObject)
1103   {
1104     std::vector<VISU::Prs3d_i*> aList; int k = 0;
1105     if (!theObject)
1106       return aList;
1107
1108     _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1109
1110     CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1111     if (!CORBA::is_nil(aCORBAObject)) {
1112       VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1113       if (!CORBA::is_nil(aVisuObj)) {
1114         VISU::VISUType aType = aVisuObj->GetType();
1115         switch (aType) {
1116         case VISU::TSCALARMAP:
1117         case VISU::TISOSURFACE:
1118         case VISU::TDEFORMEDSHAPE:
1119         case VISU::TCUTPLANES:
1120         case VISU::TCUTLINES:
1121         case VISU::TVECTORS:
1122         case VISU::TSTREAMLINES:
1123         case VISU::TPLOT3D:
1124           {
1125             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1126             if (aServant.in()) {
1127               VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1128               aList.resize(k+1);
1129               aList[k] = aPrsObject;
1130               k++;
1131             }
1132           }
1133           break;
1134         case VISU::TFIELD:
1135           {
1136             _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1137             _PTR(SObject) aTimeStamp;
1138             anIter->Next(); // First is reference on support
1139             for (; anIter->More(); anIter->Next()) {
1140               aTimeStamp = anIter->Value();
1141               if (!aTimeStamp) continue;
1142               std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1143               if (!aSubList.empty()) {
1144                 int n = aSubList.size();
1145                 aList.resize(k+n);
1146                 for (int i = 0; i < n; i++) {
1147                   aList[k] = aSubList[i];
1148                   k++;
1149                 }
1150               }
1151             }
1152           }
1153           break;
1154         }
1155       }
1156     } else {
1157       _PTR(GenericAttribute) anAttr;
1158       if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1159         _PTR(AttributeComment) aComment (anAttr);
1160         string aComm = aComment->Value();
1161         QString strIn (aComm.c_str());
1162         VISU::Storable::TRestoringMap pMap;
1163         VISU::Storable::StrToMap(strIn, pMap);
1164         bool isExist;
1165         VISU::VISUType aType =
1166           (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1167         if (isExist) {
1168           switch (aType) {
1169           case VISU::TFIELD:
1170             {
1171               _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1172               _PTR(SObject) aTimeStamp;
1173               anIter->Next(); // First is reference on support
1174               for (; anIter->More(); anIter->Next()) {
1175                 aTimeStamp = anIter->Value();
1176                 if (!aTimeStamp) continue;
1177                 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1178                 if (!aSubList.empty()) {
1179                   int n = aSubList.size();
1180                   aList.resize(k+n);
1181                   for (int i = 0; i < n; i++) {
1182                     aList[k] = aSubList[i];
1183                     k++;
1184                   }
1185                 }
1186               }
1187             }
1188             break;
1189           case VISU::TTIMESTAMP:
1190             {
1191               _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1192               _PTR(SObject) aPrs;
1193               for (; anIter->More(); anIter->Next()) {
1194                 aPrs = anIter->Value();
1195                 if (!aPrs) continue;
1196                 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1197                 if (!aSubList.empty()) {
1198                   int n = aSubList.size();
1199                   aList.resize(k+n);
1200                   for (int i = 0; i < n; i++) {
1201                     aList[k] = aSubList[i];
1202                     k++;
1203                   }
1204                 }
1205               }
1206             }
1207             break;
1208           }
1209         }
1210       }
1211     }
1212     return aList;
1213   }
1214 }