1 /**********************************************/
3 /* FILE: AliGNode.cxx */
4 /* PURPOSE: Tree elemnt of the geometry */
6 /* COMPILER: CC for HP-UX 9.x and 10. */
7 /* AUTHOR: Joana && David */
8 /* DATE: May 28, 1999 */
9 /* ADDRESS: jesanto@cern.ch, dcollado@cern.ch */
11 /**********************************************/
15 #include <TPadView3D.h>
19 #include "AliGeometry.h"
22 #include "AliGPCone.h"
23 #include "AliGSphere.h"
26 const Int_t kSonsInvisible = BIT(17);
27 Text_t* ROOT_FILE = "AliGeoDB.root";
31 //----------------------------------------------------------------------
33 AliGNode::AliGNode( AliGNode* node )
37 /* Copy Constructor */
38 fConfig = new AliGConfig( node->fConfig );
40 fMaterial = new AliGMaterial( node->fMaterial );
42 fNcopy = new TArrayI( *(node->fNcopy) );
43 fNname = node->fNname;
44 fNnode = new TArrayI( *(node->fNnode) );
45 fNode = new TObjArray( *(node->fNode) );
46 fNsons = node->fNsons;
47 fNtrans = new TArrayI( *(node->fNtrans) );
48 fParent = node->fParent;
50 fTitle = node->fTitle;
51 fTrans = new TObjArray(*(node->fTrans));
52 // fParent = new AliGNode(node->fParent);
55 if( !strcmp(node->fShape->ClassName(), "AliGBox") ) {
56 fShape = new AliGBox( (AliGBox*) node->fShape );
57 //fShape = new AliGBox(*(AliGBox*)node->fShape);
60 if( !strcmp(node->fShape->ClassName(), "AliGSphere") )
61 fShape = new AliGSphere( (AliGSphere*) node->fShape );
63 if( !strcmp(node->fShape->ClassName(), "AliGTube") )
64 fShape = new AliGTube( (AliGTube*) node->fShape );
66 if( !strcmp(node->fShape->ClassName(), "AliGCone") )
67 fShape = new AliGCone( (AliGCone*) node->fShape );
69 if( !strcmp(node->fShape->ClassName(), "AliGPCone") )
70 fShape = new AliGPCone( (AliGPCone*) node->fShape );
72 if( !strcmp(node->fShape->ClassName(), "AliGTRD1") )
73 fShape = new AliGTRD1( (AliGTRD1*) node->fShape );
83 /*cout << endl << " Comparacion." << endl;
84 cout << " El que paso por parametro:" << endl;
86 cout << " El resultado de la copia:" << endl;
91 /* Default Constructor */
99 fNode = new TObjArray();
105 fTrans = new TObjArray();
110 //----------------------------------------------------------------------
112 AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGBox* box, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
114 /* AliGNode Constructor for AliGBox shape */
117 fShape = new AliGBox(box); // Shape inside node
121 EndConstructor( name, id, title, material, matrixname, config );
124 //----------------------------------------------------------------------
126 AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGSphere* sphere, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
128 /* AliGNode Constructor for AliGSphere shape */
131 fShape = new AliGSphere(sphere); // Shape inside node
135 EndConstructor( name, id, title, material, matrixname, config );
138 //----------------------------------------------------------------------
140 AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGTube* tube, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
142 /* AliGNode Constructor for AliGTube shape */
145 fShape = new AliGTube(tube); // Shape inside node
149 EndConstructor( name, id, title, material, matrixname, config );
152 //----------------------------------------------------------------------
154 AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGCone* cone, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
156 /* AliGNode Constructor for AliGCone shape */
159 fShape = new AliGCone(cone); // Shape inside node
163 EndConstructor( name, id, title, material, matrixname, config );
166 //----------------------------------------------------------------------
169 AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGPCone* pcone, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
171 /* AliGNode Constructor for AliGPCone shape */
174 fShape = new AliGPCone(pcone); // Shape inside node
178 EndConstructor( name, id, title, material, matrixname, config );
181 //----------------------------------------------------------------------
184 AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGTRD1* trd1, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
186 /* AliGNode Constructor for AliGTRD1 shape */
189 fShape = new AliGTRD1(trd1); // Shape inside node
193 EndConstructor( name, id, title, material, matrixname, config );
196 //----------------------------------------------------------------------
198 void AliGNode::EndConstructor( Text_t* name, Int_t id, Text_t* title, AliGMaterial *material, const Text_t *matrixname, AliGConfig* config )
200 /* Finish the construction of AliGNodes */
202 fConfig = new AliGConfig(config);
203 fId = id; // Node id number
204 fMaterial = new AliGMaterial(material); // Material inside shape
206 char* TmpName = new char[strlen(name)+int(TMath::Log10((double) id)+3)];
207 sprintf(TmpName,"%s_%d",name,id);
208 fName = TmpName; // Complete node name
211 fNcopy = new TArrayI(50); // Array of integers containing the copy number (by family name)
212 fNname = name; // Node family name
213 fNnode = new TArrayI(50); // Array of integers containing every node son index
214 fNode = new TObjArray(100,0); // Array containing every (different)node son
216 fNtrans = new TArrayI(50); // Array of integers containing every transformation index
219 fTrans = new TObjArray(100,0); // Array containing every (different)transformation used
224 //-----------------------------------------------------------------------
226 AliGNode::AliGNode( Text_t* name, Int_t id, Text_t* title, AliGShape* shape, AliGMaterial* material, const Text_t* matrixname, AliGConfig* config )
228 /* AliGNode Constructor for an AliGShape */
232 EndConstructor( name, id, title, material, matrixname, config );
236 //----------------------------------------------------------------------
238 AliGNode::~AliGNode()
242 if(fConfig) delete fConfig;
243 if(fMaterial) delete fMaterial;
244 if(fNcopy) delete fNcopy;
245 if(fNnode) delete fNnode;
246 if(fNode) delete fNode;
247 if(fNtrans) delete fNtrans;
248 if(fShape) delete fShape;
249 if(fTrans) delete fTrans;
252 //----------------------------------------------------------------------
254 AliGNode* AliGNode::operator=( const AliGNode* node )
256 if( this == node ) return this; // special case.
258 fConfig = node->fConfig;
260 fMaterial = node->fMaterial;
262 fNcopy = node->fNcopy;
263 fNname = node->fNname;
264 fNnode = node->fNnode;
266 if( fNode ) fNode->Delete();
269 //for( int i=0; i<node->fNode->GetSize(); i++ )
270 for( int i=0; i<node->fNode->GetSize(); i++ )
271 fNode->AddLast(node->fNode->At(i));
274 fNsons = node->fNsons;
275 fNtrans = node->fNtrans;
276 fParent = node->fParent;
277 fShape = node->fShape;
278 fTitle = node->fTitle;
280 if( fTrans ) fTrans->Delete();
282 for( int i=0; i<node->fTrans->GetSize(); i++ )
283 fTrans->AddLast(node->fTrans->At(i));
285 //fTrans = node->fTrans;
290 //----------------------------------------------------------------------
292 void AliGNode::Add(AliGNode* son, AliGTransform* tran)
295 Int_t index = fNode->IndexOf((TObject*)son);
298 fNode->Add(son); // fNode is TObjArray
299 index = fNode->IndexOf((TObject*)son);
303 Int_t tranumber = fTrans->IndexOf((TObject*)tran);
304 if( tranumber == -1 ) {
306 tranumber = fTrans->IndexOf((TObject*)tran);
309 Int_t Nsons = this->GetfNsons();
312 for( Int_t i = 0; i<Nsons; i++ ) {
313 if( index == fNnode->At(i) ) {
314 if( fNtrans->At(i) == tranumber ) {
315 cout << "Error: Node already exists!";
321 if( ((AliGNode*)fNode->At(fNnode->At(i)))->fNname == son->fNname )
326 if( fNnode->GetSize() == Nsons ) {
328 IncreaseSize( Nsons+100, *fNnode );
329 IncreaseSize( Nsons+100, *fNtrans );
330 IncreaseSize( Nsons+100, *fNcopy );
333 fNnode->AddAt( index, Nsons ); // Add value of index at position Nsons
335 fNtrans->AddAt( tranumber, Nsons );
336 fNcopy->AddAt( copy, Nsons );
337 fNsons++; // Because we have added a new node
341 //----------------------------------------------------------------------
343 void AliGNode::IncreaseSize(Int_t total,TArrayI &array)
345 TArrayI *newarray = new TArrayI(array);
348 for( int i=0; i<newarray->GetSize(); i++ )
349 array[i] = (*newarray)[i];
354 //----------------------------------------------------------------------
356 Text_t* AliGNode::GetPath()
358 const int kMAXDEPTH = 128;
359 const AliGNode* d[kMAXDEPTH];
360 AliGNode* node = this;
361 int depth = 0, len = 0;
364 len = strlen(node->GetName()) + 1;
366 while (node->fParent && depth < kMAXDEPTH) {
367 node = node->fParent;
369 len += strlen (node->GetName()) + 1;
372 char* path = new char[len + 2];
374 for (int i = depth-1; i>=0; i--) {
375 if (i == depth-1) { // file or TROOT name
376 strcpy(path, d[i]->GetName());
377 if (i == 0) strcat(path, "/");
381 strcat(path, d[i]->GetName());
389 //----------------------------------------------------------------------
391 void AliGNode::Save( TFile* file )
393 if( fParent ) { // it's not the root node
394 // So I must check if the father node is in disk
396 if( file->cd(fParent->GetPath()) ) {
398 if( !gDirectory->Get(GetName()) )
399 file->mkdir( GetName() );
401 file->cd( GetPath() );
403 if( !gDirectory->Get( fShape->GetName() ) )
405 /* const Text_t* shapetype = fShape->ClassName();
406 if( !strcmp(shapetype,"AliGBox") ) {
410 if (!strcmp(shapetype,"AliGSphere")) {
414 if (!strcmp(shapetype,"AliGTube")) {
418 if (!strcmp(shapetype,"AliGCone")) {
422 if (!strcmp(shapetype,"AliGPCone")) {
423 cout << " Saving an AliGPCone:" << endl;
429 if (!strcmp(shapetype,"AliGTRD1")) {
441 if( !gDirectory->Get( fMaterial->GetName() ) )
446 /*cout << " Con capacidad: " << fConfig->GetFormula().Capacity() << " voy a grabar esta configuracion: " << fConfig->GetFormula().Data() << endl;*/
454 cout << " ERROR : Father exists but I can't find it. See AliGNode::Save, please..." << endl;
456 else { // if it's the root node
457 file->mkdir( GetName() );
458 file->cd( GetPath() );
467 /*cout << " Con capacidad: " << fConfig->GetFormula().Capacity() << " voy a grabar esta configuracion: " << fConfig->GetFormula().Data() << endl;*/
479 //----------------------------------------------------------------------
481 void AliGNode::SaveAll( TFile* file )
484 file->cd( fParent->GetPath() );
490 for( int i=0; i<fNsons; i++ ) {
491 cout << " Saving node: " << GetPath() << " with copy number " << << endl;
492 GetNodeFromfNnode(i)->SaveAll( file );
496 if( !gDirectory->Get(GetName()) ) {
499 for( int i=0; i<fNsons; i++ )
500 GetNodeFromfNnode(i)->SaveAll( file );
503 /* if (!file->cd(GetPath())) {
506 for( int i=0; i<fNsons; i++ )
507 GetNodeFromfNnode(i)->SaveAll( file );
512 //----------------------------------------------------------------------
514 void AliGNode::AddConfig( Text_t* name, Text_t* title, Text_t* detail, Int_t beg, Int_t end )
516 Int_t Nsons = GetfNsons();
518 TStringLong formula = "";
520 for( int i=0; i<Nsons; i++ ) {
521 Int_t index = fNnode->At(i); // Gets every node son's index
522 const Text_t* NodeName = ((AliGNode*)fNode->At(index))->GetName();
523 Int_t tranumber = fNtrans->At(i); // And the correspondent transform
524 const Text_t* TransfName = ((AliGTransform*)fTrans->At(tranumber))->GetName();
526 formula.Append(NodeName);
528 formula.Append(TransfName);
534 //cout << " Acabo de crear la formula: " << formula << endl << endl;
536 const Text_t* shapetype = fShape->ClassName();
537 const Text_t* shapename = fShape->GetName();
538 const Text_t* materialname = fMaterial->GetName();
540 AliGConfig* tmp = new AliGConfig( name, title, formula, detail, shapetype, shapename, materialname, beg, end );
542 //if(fConfig) delete fConfig;
547 //----------------------------------------------------------------------
549 /*void AliGNode::AddConfig( Text_t* name, Text_t* title, Text_t* detail, Int_t beg, Int_t end )
551 // Creates the configuration of a node using the information passed as arguments
552 // and building the formula of the level below by building the list of its sons
555 Int_t Nsons = GetfNsons();
557 char* formula = NULL;
559 cout << " Nsons = " << Nsons << endl;
561 for( int i=0; i<Nsons; i++ ) {
562 Int_t index = fNnode->At(i); // Gets every node son's index
563 const Text_t* NodeName = ((AliGNode*)fNode->At(index))->GetName();
564 Int_t tranumber = fNtrans->At(i); // And the correspondent transform
565 const Text_t* TransfName = ((AliGTransform*)fTrans->At(tranumber))->GetName();
567 int lenF, lenN, lenT;
568 lenF = lenN = lenT = 0;
570 cout << " i = " << i << " and fNsons = " << fNsons << endl;
573 lenF = strlen(formula);
574 cout << " formula = #" << formula << "#" << endl;
578 lenN = strlen(NodeName);
579 cout << " NodeName = #" << NodeName << "#" << endl;
583 lenT = strlen(TransfName);
584 cout << " TransfName = #" << TransfName << "#" << endl;
587 cout << " lenF: " << lenF << " - lenN: " << lenN << " - lenT: " << lenT << endl;
591 if( i != fNsons-1 ) {
592 cout << " Arriba" << endl;
593 formula2 = new char[lenF+lenN+lenT+2];
596 cout << " Embaixo" << endl;
597 formula2 = new char[lenF+lenN+lenT+1];
602 cout << "@@@ :) @@@" << endl;
605 strcpy( formula2, formula );
606 cout << "1 formula2 = #" << formula2 << "#" << endl;
610 strcat( formula2, NodeName );
611 cout << "2 formula2 = #" << formula2 << "#" << endl;
614 strcat( formula2, ":" );
617 strcat( formula2, TransfName );
618 cout << "3 formula2 = #" << formula2 << "#" << endl;
621 if( i != fNsons-1 ) {
622 strcat( formula2, "+" );
623 cout << "4 formula2 = #" << formula2 << "#" << endl;
626 //strcat( formula2, "\x0" );
627 //cout << "5 formula2 = #" << formula2 << "#" << endl;
629 cout << " Y formula2 tiene un tamanyo de: " << strlen(formula2) << " caracteres." << endl;
631 //if( formula ) delete [] formula;
632 formula = new char[strlen(formula2)];
633 strcpy( formula, formula2 );
634 if( formula2 ) delete [] formula2;
637 const Text_t* shapetype = fShape->ClassName();
638 const Text_t* shapename = fShape->GetName();
639 const Text_t* materialname = fMaterial->GetName();
641 AliGConfig* tmp = new AliGConfig( name, title, formula, detail, shapetype, shapename, materialname, beg, end );
643 if(fConfig) delete fConfig;
649 //-------------------------------------------------------------------------
651 void AliGNode::DrawShape(Option_t *option)
657 //----------------------------------------------------------------------
659 void AliGNode::Draw(Option_t* option)
662 TString opt = option;
664 //*-*- Clear pad if option "same" not given
666 if (!gROOT->GetMakeDefCanvas()) return;
667 (gROOT->GetMakeDefCanvas())();
669 if (!opt.Contains("same")) gPad->Clear();
671 //*-*- Draw Referenced node
672 //gGeometry->SetGeomLevel();
673 //gGeometry->UpdateTempMatrix();
677 //*-*- Create a 3-D View
678 TView *view = gPad->GetView();
681 view->SetAutoRange(kTRUE);
683 view->SetAutoRange(kFALSE);
687 //------------------------------------------------------------------
689 void AliGNode::Paint(Option_t *option)
692 TPadView3D *view3D=gPad->GetView3D();
694 //Int_t level = gGeometry->GeomLevel();
695 // restrict the levels for "range" option
696 //if (level > 3 && strcmp(option,"range") == 0) return;
697 //*-*- Update translation vector and rotation matrix for new level
699 // gGeometry->UpdateTempMatrix(fX,fY,fZ,fMatrix->GetMatrix(),fMatrix->IsReflection());
701 // view3D->UpdateNodeMatrix(this,option);
704 //*-*- Paint Referenced shape
705 // Int_t vis = fShape->GetVisibility();
706 // if ( vis == -1) return;
708 // if (nsons == 0) vis = 1;
712 // TAttLine::Modify();
713 // TAttFill::Modify();
714 //if (fVisibility && fShape->GetVisibility()) {
716 //fShape->SetLineColor(GetLineColor());
717 //fShape->SetLineStyle(GetLineStyle());
718 //fShape->SetLineWidth(GetLineWidth());
719 //fShape->SetFillColor(GetFillColor());
720 //fShape->SetFillStyle(GetFillStyle());
723 if (fNnode) nsons = GetfNsons();
725 view3D->SetAttNode((TNode*)this,option);
730 fShape->Paint(option);
732 cout << " Intente dibujar donde no habia shape!!! " << endl;
735 if ( TestBit(kSonsInvisible) ) return;
737 //*-*- Paint all sons
740 //gGeometry->PushLevel();
741 for( int i=0; i<nsons; i++ ) {
743 gAliGeometry->PushMatrix(gMatrix);
745 AliGNode* node = (AliGNode*) fNode->At(fNnode->At(i));
747 AliGTransform* trans = (AliGTransform*) fTrans->At(fNtrans->At(i));
748 gAliGeometry->UpdateMatrix(trans);
750 gAliGeometry->PopMatrix();
753 //gGeometry->PopLevel();
758 //--------------------------------------------------------------------
760 Int_t AliGNode::DistancetoPrimitive(Int_t px, Int_t py)
762 TView *view = gPad->GetView();
763 gPad->SetSelected(view);
767 //--------------------------------------------------------------------