]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Tools.cxx
Salome HOME
Change representation: check type of object (VISU or not) before getting servant...
[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
473     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
474     if (CORBA::is_nil(aVisuObj)) return;
475
476     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
477     if (!aServant.in()) return;
478
479     VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
480     if (aPrs3d) {
481       if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
482         switch (theType) {
483         case VISU::SHRINK:
484           if (anActor->IsShrunk())
485             anActor->UnShrink();
486           else
487             anActor->SetShrink();
488           break;
489         default:
490           if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
491             aMesh->SetPresentationType(theType);
492             RecreateActor(theModule, aMesh);
493           } else {
494             anActor->SetRepresentation(theType);
495           }
496         }
497         vw->Repaint();
498       }
499     }
500   }
501
502   //************************************************************
503   // SObject type
504
505   bool
506   CheckTimeStamp(const SalomeApp_Module* theModule,
507                  _PTR(SObject)&          theSObject,
508                  Handle(SALOME_InteractiveObject)* theIO)
509   {
510     Handle(SALOME_InteractiveObject) anIO;
511     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
512     if (theIO)
513       *theIO = anIO;
514     if (!anIO.IsNull() && anIO->hasEntry()){
515       _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
516       theSObject = aStudy->FindObjectID(anIO->getEntry());
517       QString aValue = getValue(theSObject,"myType");
518       if (aValue.toInt() == int(VISU::TTIMESTAMP))
519         return true;
520     }
521     SUIT_MessageBox::warn1(GetDesktop(theModule),
522                            QObject::tr("WRN_VISU"),
523                            QObject::tr("WRN_NO_AVAILABLE_DATA"),
524                            QObject::tr("BUT_OK") );
525     return false;
526   }
527
528   VISU::Result_i*
529   CheckResult(const SalomeApp_Module* theModule,
530               _PTR(SObject)           theSource,
531               VISU::Result_var&       theResult)
532   {
533     _PTR(SObject) aSObj = theSource->GetFather();
534     if (!aSObj)
535       return NULL;
536
537     aSObj = aSObj->GetFather();
538     if (!aSObj)
539       return NULL;
540
541     aSObj = aSObj->GetFather();
542     if (!aSObj)
543       return NULL;
544
545     CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
546     if (CORBA::is_nil(anObject)) {
547       aSObj = aSObj->GetFather();
548       if (!aSObj)
549         return NULL;
550       anObject = VISU::ClientSObjectToObject(aSObj);
551     }
552
553     if (CORBA::is_nil(anObject))
554       return NULL;
555
556     theResult = VISU::Result::_narrow(anObject);
557     VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
558     if (pResult == NULL)
559       SUIT_MessageBox::warn1(GetDesktop(theModule),
560                              QObject::tr("WRN_VISU"),
561                              QObject::tr("WRN_NO_AVAILABLE_DATA"),
562                              QObject::tr("BUT_OK"));
563     return pResult;
564   }
565
566   //************************************************************
567   // Views
568
569   SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
570   {
571     if(SalomeApp_Application* anApp = theModule->getApp()){
572       if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
573         if (!theType.isNull()) {
574           if (aViewManager->getType() != theType)
575             return 0;
576         }
577         return aViewManager->getActiveView();
578       }
579     }
580     return 0;
581   }
582
583   //************************************************************
584   // VTK View
585
586   TViewWindows
587   GetViews(const SalomeApp_Module* theModule)
588   {
589     TViewWindows aViewWindows;
590     if(SalomeApp_Application* anApp = theModule->getApp()){
591       ViewManagerList aViewManagerList;
592       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
593       QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
594       while(SUIT_ViewManager* aViewManager = anIter.current()){
595         QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
596         for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
597           if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
598             if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
599               aViewWindows.push_back(aView);
600         }
601         ++anIter;
602       }
603     }
604     return aViewWindows;
605   }
606
607   SVTK_ViewWindow*
608   GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
609   {
610     if(SalomeApp_Application* anApp = theModule->getApp()){
611       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
612         if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
613           return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
614         }
615       }
616     }
617     return NULL;
618   }
619
620
621   SVTK_ViewWindow*
622   GetViewWindow()
623   {
624     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
625       (SUIT_Session::session()->activeApplication());
626     if (anApp) {
627       if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
628         if (aViewManager->getType() == SVTK_Viewer::Type()) {
629           if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
630             return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
631           }
632         }
633       }
634     }
635     return NULL;
636   }
637
638   VISU_Actor*
639   PublishInView(const SalomeApp_Module* theModule,
640                 VISU::Prs3d_i* thePrs)
641   {
642     VISU_Actor* aActor = NULL;
643     if(!thePrs)
644       return aActor;
645     if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
646       QApplication::setOverrideCursor( Qt::waitCursor );
647       try{
648         if(aActor = thePrs->CreateActor())
649           aView->AddActor(aActor);
650       }catch(std::exception& exc){
651         SUIT_MessageBox::warn1(GetDesktop(theModule),
652                                QObject::tr("WRN_VISU"),
653                                QObject::tr("ERR_CANT_CREATE_ACTOR"),
654                                QObject::tr("BUT_OK"));
655       }
656       QApplication::restoreOverrideCursor();
657     }
658     return aActor;
659   }
660
661   VISU_Actor*
662   UpdateViewer(const SalomeApp_Module* theModule,
663                VISU::Prs3d_i* thePrs,
664                bool theDispOnly)
665   {
666     SVTK_ViewWindow* vw = GetViewWindow( theModule );
667     if (!vw) return NULL;
668
669     vtkRenderer *aRen = vw->getRenderer();
670     vtkActorCollection *anActColl = aRen->GetActors();
671
672     vtkActor *anActor;
673     VISU_Actor* anVISUActor = NULL;
674     VISU_Actor* aResActor = NULL;
675     for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
676       if(!SALOME_Actor::SafeDownCast(anActor))
677         continue;
678       if(anActor->IsA("VISU_Actor")){
679         anVISUActor = VISU_Actor::SafeDownCast(anActor);
680         VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
681         if(aPrs == NULL) continue;
682         if (thePrs == aPrs) {
683           aResActor = anVISUActor->GetParent();
684           thePrs->UpdateActor(aResActor);
685           aResActor->VisibilityOn();
686
687         } else if (theDispOnly) {
688           anVISUActor->GetParent()->VisibilityOff();
689         } else {
690         }
691       } else if (theDispOnly && anActor->GetVisibility()) {
692         anActor->VisibilityOff();
693       } else {
694       }
695     }
696     if (aResActor)
697       return aResActor;
698
699     anVISUActor = PublishInView( theModule, thePrs );
700     return anVISUActor;
701   }
702
703   void
704   RepaintViewWindows (const SalomeApp_Module* theModule,
705                       const Handle(SALOME_InteractiveObject)& theIObject)
706   {
707     TViewWindows aViewWindows;
708     if (SalomeApp_Application* anApp = theModule->getApp()) {
709       ViewManagerList aViewManagerList;
710       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
711       QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
712       while (SUIT_ViewManager* aViewManager = anIter.current()) {
713         QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
714         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
715           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
716             if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
717               if (vw->isVisible(theIObject)) {
718                 vw->getRenderer()->ResetCameraClippingRange();
719                 vw->Repaint();
720                 vw->highlight(theIObject, true, true);
721               }
722             }
723           }
724         }
725         ++anIter;
726       }
727     }
728   }
729
730   VISU_Actor*
731   FindActor(SVTK_ViewWindow* theViewWindow,
732             const char* theEntry)
733   {
734     using namespace VTK;
735     if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
736       if(vtkActorCollection* aCollection = aRenderer->GetActors()){
737         if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
738           return anActor->GetParent();
739         }
740       }
741     }
742     return NULL;
743   }
744
745   VISU_Actor*
746   FindActor(SVTK_ViewWindow* theViewWindow,
747             VISU::Prs3d_i* thePrs)
748   {
749     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
750     CORBA::String_var anEntry = aSObject->GetID();
751     return FindActor(theViewWindow,anEntry.in());
752   }
753
754   void
755   RecreateActor (const SalomeApp_Module* theModule,
756                  VISU::Prs3d_i* thePrs)
757   {
758     QApplication::setOverrideCursor(Qt::waitCursor);
759
760     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
761     CORBA::String_var anEntry = aSObject->GetID();
762
763     try {
764       thePrs->Update();
765
766       TViewWindows aViewWindows = GetViews(theModule);
767       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
768         SVTK_ViewWindow* aView = aViewWindows[i];
769         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
770           thePrs->UpdateActor(anActor);
771         }
772       }
773     } catch (std::runtime_error& ex) {
774       INFOS(ex.what());
775       QApplication::restoreOverrideCursor();
776       SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
777                               QObject::tr("ERR_CANT_BUILD_PRESENTATION") + " " + QObject::tr(ex.what()),
778                               QObject::tr("BUT_OK"));
779
780       TViewWindows aViewWindows = GetViews(theModule);
781       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
782         SVTK_ViewWindow* aView = aViewWindows[i];
783         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
784           aView->RemoveActor(anActor);
785           anActor->Delete();
786         }
787       }
788       return;
789     }
790     QApplication::restoreOverrideCursor();
791   }
792
793   //************************************************************
794   // Plot2d View
795
796   SPlot2d_Viewer*
797   GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
798   {
799     if(SalomeApp_Application* anApp = theModule->getApp()){
800       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
801         return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
802       }
803     }
804     return NULL;
805   }
806
807   // Internal function used by several public functions below
808   void
809   UpdateCurve(VISU::Curve_i* theCurve,
810               Plot2d_ViewFrame* aPlot,
811               SPlot2d_Curve* plotCurve,
812               int theDisplaying)
813   {
814     if ( theDisplaying == VISU::eErase ) {
815       if ( plotCurve )
816         aPlot->eraseCurve( plotCurve, false );
817     }
818     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
819       if ( plotCurve ) {
820         plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
821         //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
822         plotCurve->setVerTitle( theCurve->GetName() );
823         plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
824         plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
825         double* xList = 0;
826         double* yList = 0;
827         int     nbPoints = theCurve->GetData( xList, yList );
828         if ( nbPoints > 0 && xList && yList ) {
829           plotCurve->setData( xList, yList, nbPoints );
830         }
831         if ( !theCurve->IsAuto() ) {
832           plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
833           plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
834           SALOMEDS::Color color = theCurve->GetColor();
835           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
836         }
837         plotCurve->setAutoAssign( theCurve->IsAuto() );
838         aPlot->displayCurve( plotCurve, false );
839       }
840       else {
841         Plot2d_Curve* crv = theCurve->CreatePresentation();
842         if ( crv ) {
843           aPlot->displayCurve( crv, false );
844           theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
845           theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
846           SALOMEDS::Color newColor;
847           newColor.R = crv->getColor().red()/255.;
848           newColor.G = crv->getColor().green()/255.;
849           newColor.B = crv->getColor().blue()/255.;
850           theCurve->SetColor( newColor );
851           crv->setAutoAssign( theCurve->IsAuto() );
852         }
853       }
854     }
855   }
856
857   void
858   PlotTable(const SalomeApp_Module* theModule,
859             VISU::Table_i* table,
860             int theDisplaying)
861   {
862     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
863     if ( !aView )
864       return;
865     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
866     if ( !aPlot )
867       return;
868
869     if ( theDisplaying == VISU::eDisplayOnly )
870       aPlot->EraseAll();
871     QList<Plot2d_Curve> clist;
872     aPlot->getCurves( clist );
873     _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
874     _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
875     if ( TableSO ) {
876       _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
877       for ( ; Iter->More(); Iter->Next() ) {
878         CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
879         if( !CORBA::is_nil( childObject ) ) {
880           CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
881           if( !CORBA::is_nil( aCurve ) ) {
882             VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
883             SPlot2d_Curve* plotCurve = 0;
884             SPlot2d_Curve* tmpCurve;
885             for ( int i = 0; i < clist.count(); i++ ) {
886               tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
887               if (tmpCurve && tmpCurve->hasIO() &&
888                   !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
889                 plotCurve = tmpCurve;
890                 break;
891               }
892             }
893
894             UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
895
896             if ( theDisplaying == VISU::eErase && plotCurve ) {
897               clist.remove( plotCurve );
898             }
899           }
900         }
901       }
902       aPlot->Repaint();
903     }
904   }
905
906   void
907   PlotCurve(const SalomeApp_Module* theModule,
908             VISU::Curve_i* theCurve,
909             int theDisplaying)
910   {
911     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
912     if ( !aView )
913       return;
914     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
915     if ( !aPlot )
916       return;
917
918 //  if ( theDisplaying == VISU::eDisplayOnly )
919 //    aPlot->EraseAll();
920     QList<Plot2d_Curve> clist;
921     aPlot->getCurves( clist );
922     SPlot2d_Curve* plotCurve = 0;
923     SPlot2d_Curve* tmpCurve;
924     for (int i = 0; i < clist.count(); i++) {
925       tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
926       if (tmpCurve && tmpCurve->hasIO() &&
927           !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
928         plotCurve = tmpCurve;
929       } else if (theDisplaying == VISU::eDisplayOnly) {
930         aPlot->eraseCurve(clist.at(i));
931       }
932     }
933
934     UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
935
936     aPlot->Repaint();
937   }
938
939   void
940   PlotContainer(const SalomeApp_Module* theModule,
941                 VISU::Container_i* container,
942                 int theDisplaying)
943   {
944     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
945     if ( !aView )
946       return;
947     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
948     if ( !aPlot )
949       return;
950
951     if ( theDisplaying == VISU::eDisplayOnly )
952       aPlot->EraseAll();
953     QList<Plot2d_Curve> clist;
954     aPlot->getCurves( clist );
955     if ( container->GetNbCurves() > 0 ) {
956       int nbCurves = container->GetNbCurves();
957       for ( int k = 1; k <= nbCurves; k++ ) {
958         VISU::Curve_i* theCurve = container->GetCurve( k );
959         if ( theCurve && theCurve->IsValid() ) {
960           SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
961             (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
962
963           UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
964
965           if ( plotCurve && theDisplaying == VISU::eErase ) {
966             clist.remove( plotCurve );
967           }
968         }
969       }
970     }
971     aPlot->Repaint();
972   }
973
974   void
975   CreatePlot(SalomeApp_Module* theModule,
976              _PTR(SObject) theTableSO)
977   {
978     if ( IsSObjectTable(theTableSO) ) {
979       CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
980       CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
981       if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
982         VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
983         VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
984
985         if ( pContainer && pTable ) {
986           for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
987             CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
988             if( !CORBA::is_nil( aNewCurve ) ) {
989               VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
990               if ( pCrv ) {
991                 pContainer->AddCurve( pCrv->_this() );
992               }
993             }
994           }
995           PlotContainer( theModule, pContainer, VISU::eDisplay );
996         }
997       }
998     }
999   }
1000
1001   //************************************************************
1002   // Others
1003
1004   void CreateMesh (const SalomeApp_Module* theModule,
1005                     const Handle(SALOME_InteractiveObject)& theIO)
1006   {
1007     _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1008     //if (CheckLock(aStudy))
1009     //  return;
1010
1011     _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1012
1013     // Get VISU::Result
1014     VISU::Result_var aResult;
1015     VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1016     if (pResult == NULL)
1017       return;
1018
1019     Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1020     bool isExist;
1021     string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1022     if (!isExist)
1023       return;
1024
1025     CORBA::Object_var aMesh;
1026     string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1027 #ifdef CHECKTIME
1028     Utils_Timer timer;
1029     timer.Start();
1030 #endif
1031     if (aComment == "ENTITY") {
1032       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1033       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1034         aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1035     } else if (aComment == "FAMILY") {
1036       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1037       string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1038       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1039         aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1040           (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1041     } else if (aComment == "GROUP") {
1042       string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1043       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1044         aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1045     }
1046 #ifdef CHECKTIME
1047     timer.Stop();
1048     MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1049     timer.Show();
1050 #endif
1051
1052     QApplication::restoreOverrideCursor();
1053     VISU::Mesh_i* pPresent = NULL;
1054     if (!CORBA::is_nil(aMesh))
1055       pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1056     if (pPresent == NULL) {
1057       SUIT_MessageBox::warn1 (GetDesktop(theModule),
1058                               QObject::tr("WRN_VISU"),
1059                               QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1060                               QObject::tr("BUT_OK"));
1061       return;
1062     }
1063
1064     if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) {
1065       try {
1066 #ifdef CHECKTIME
1067         Utils_Timer timer;
1068         timer.Start();
1069 #endif
1070         PublishInView(theModule, pPresent);
1071         aView->onFitAll();
1072 #ifdef CHECKTIME
1073         timer.Stop();
1074         MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1075         timer.Show();
1076 #endif
1077         theModule->application()->putInfo(QObject::tr("INF_DONE"));
1078         // Make "Save" button active
1079         theModule->getApp()->updateActions();
1080       } catch (std::runtime_error& exc) {
1081         INFOS(exc.what());
1082         SUIT_MessageBox::warn1 (GetDesktop(theModule),
1083                                 QObject::tr("WRN_VISU"),
1084                                 QObject::tr("ERR_CANT_CREATE_ACTOR") + " " + QObject::tr(exc.what()),
1085                                 QObject::tr("BUT_OK"));
1086       }
1087     }
1088   }
1089
1090   // ========================================================================================
1091   // GetPrs3dList: find list of presentations for the given object
1092   // ========================================================================================
1093   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1094                                             const Handle(SALOME_InteractiveObject)& theIO)
1095   {
1096     std::vector<VISU::Prs3d_i*> aList;
1097     if (!theIO.IsNull() && theIO->hasEntry()) {
1098       _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1099       _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1100       aList = GetPrs3dList(theModule, aSObject);
1101     }
1102     return aList;
1103   }
1104
1105   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1106                                             _PTR(SObject) theObject)
1107   {
1108     std::vector<VISU::Prs3d_i*> aList; int k = 0;
1109     if (!theObject)
1110       return aList;
1111
1112     _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1113
1114     CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1115     if (!CORBA::is_nil(aCORBAObject)) {
1116       VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1117       if (!CORBA::is_nil(aVisuObj)) {
1118         VISU::VISUType aType = aVisuObj->GetType();
1119         switch (aType) {
1120         case VISU::TSCALARMAP:
1121         case VISU::TISOSURFACE:
1122         case VISU::TDEFORMEDSHAPE:
1123         case VISU::TCUTPLANES:
1124         case VISU::TCUTLINES:
1125         case VISU::TVECTORS:
1126         case VISU::TSTREAMLINES:
1127         case VISU::TPLOT3D:
1128           {
1129             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1130             if (aServant.in()) {
1131               VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1132               aList.resize(k+1);
1133               aList[k] = aPrsObject;
1134               k++;
1135             }
1136           }
1137           break;
1138         case VISU::TFIELD:
1139           {
1140             _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1141             _PTR(SObject) aTimeStamp;
1142             anIter->Next(); // First is reference on support
1143             for (; anIter->More(); anIter->Next()) {
1144               aTimeStamp = anIter->Value();
1145               if (!aTimeStamp) continue;
1146               std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1147               if (!aSubList.empty()) {
1148                 int n = aSubList.size();
1149                 aList.resize(k+n);
1150                 for (int i = 0; i < n; i++) {
1151                   aList[k] = aSubList[i];
1152                   k++;
1153                 }
1154               }
1155             }
1156           }
1157           break;
1158         }
1159       }
1160     } else {
1161       _PTR(GenericAttribute) anAttr;
1162       if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1163         _PTR(AttributeComment) aComment (anAttr);
1164         string aComm = aComment->Value();
1165         QString strIn (aComm.c_str());
1166         VISU::Storable::TRestoringMap pMap;
1167         VISU::Storable::StrToMap(strIn, pMap);
1168         bool isExist;
1169         VISU::VISUType aType =
1170           (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1171         if (isExist) {
1172           switch (aType) {
1173           case VISU::TFIELD:
1174             {
1175               _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1176               _PTR(SObject) aTimeStamp;
1177               anIter->Next(); // First is reference on support
1178               for (; anIter->More(); anIter->Next()) {
1179                 aTimeStamp = anIter->Value();
1180                 if (!aTimeStamp) continue;
1181                 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1182                 if (!aSubList.empty()) {
1183                   int n = aSubList.size();
1184                   aList.resize(k+n);
1185                   for (int i = 0; i < n; i++) {
1186                     aList[k] = aSubList[i];
1187                     k++;
1188                   }
1189                 }
1190               }
1191             }
1192             break;
1193           case VISU::TTIMESTAMP:
1194             {
1195               _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1196               _PTR(SObject) aPrs;
1197               for (; anIter->More(); anIter->Next()) {
1198                 aPrs = anIter->Value();
1199                 if (!aPrs) continue;
1200                 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1201                 if (!aSubList.empty()) {
1202                   int n = aSubList.size();
1203                   aList.resize(k+n);
1204                   for (int i = 0; i < n; i++) {
1205                     aList[k] = aSubList[i];
1206                     k++;
1207                   }
1208                 }
1209               }
1210             }
1211             break;
1212           }
1213         }
1214       }
1215     }
1216     return aList;
1217   }
1218 }