| 1 | #include "contmodex.h" | 
|---|
| 2 |  | 
|---|
| 3 | #include "pigncont.h" | 
|---|
| 4 | #include <typeinfo> | 
|---|
| 5 |  | 
|---|
| 6 | #include <vector> | 
|---|
| 7 | #include <string> | 
|---|
| 8 | #include "nobjmgr.h" | 
|---|
| 9 |  | 
|---|
| 10 | #include "pidrawer.h" | 
|---|
| 11 | #include "nomgadapter.h" | 
|---|
| 12 | #include "servnobjm.h" | 
|---|
| 13 |  | 
|---|
| 14 |  | 
|---|
| 15 | /* --Methode-- */ | 
|---|
| 16 | ContModExecutor::ContModExecutor(PIACmd* mpiac, PIStdImgApp* app) | 
|---|
| 17 | { | 
|---|
| 18 |  | 
|---|
| 19 | //PIACmd * mpiac; | 
|---|
| 20 | //NamedObjMgr omg; | 
|---|
| 21 | //mpiac = omg.GetImgApp()->CmdInterpreter(); | 
|---|
| 22 |  | 
|---|
| 23 | //cout << " ContModExecutor::ContModExecutor() mpiac = " << (unsigned long)mpiac << endl; | 
|---|
| 24 | cout << " registration of contour commands "<<endl; | 
|---|
| 25 | string hgrp,kw,usage; | 
|---|
| 26 |  | 
|---|
| 27 | hgrp = "Obj. Display"; | 
|---|
| 28 |  | 
|---|
| 29 | kw = "contour"; | 
|---|
| 30 | usage = "Creates and displays a ContourDrawer "; | 
|---|
| 31 | usage += "\n Usage: contour objectName [graphic_att/specific_opt] "; | 
|---|
| 32 | usage += "\n Specific Options "; | 
|---|
| 33 | usage += "\n    ncont=[number of contours (automatic levels) ] "; | 
|---|
| 34 | usage += "\n    niv/lev=[values for contours, separated by ','] "; | 
|---|
| 35 | usage += "\n    lstep=[nomber,first_value,increment for contours ] "; | 
|---|
| 36 | usage += "\n    bspline : use bspline algo for contour " ; | 
|---|
| 37 | usage += "\n    3spl : use cubic spline algo for contour " ; | 
|---|
| 38 | usage += "\n    labon : put labels for contours " ; | 
|---|
| 39 |  | 
|---|
| 40 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 41 |  | 
|---|
| 42 | hgrp = "Obj. Display"; | 
|---|
| 43 | kw = "ntcont"; | 
|---|
| 44 | usage = "Creates and displays a ContourDrawer (from a NTuple)"; | 
|---|
| 45 | usage += "\n Usage: ntcont NTupleName varx vary varz [graphic_att/specific_opt] "; | 
|---|
| 46 | usage += "\n        specific options "; | 
|---|
| 47 | usage += "\n    ncont=[number of contours (automatic levels) ] "; | 
|---|
| 48 | usage += "\n    niv/lev=[values for contours, separated by ','] "; | 
|---|
| 49 | usage += "\n    lstep=[nomber,first_value,increment for contours ] "; | 
|---|
| 50 | usage += "\n    bspline : use bspline algo for contour " ; | 
|---|
| 51 | usage += "\n    3spl : use cubic spline algo for contour " ; | 
|---|
| 52 | usage += "\n    labon : put labels for contours " ; | 
|---|
| 53 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 54 |  | 
|---|
| 55 | //cout << " Out of ContModExecutor::ContModExecutor() " << endl; | 
|---|
| 56 |  | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 |  | 
|---|
| 60 |  | 
|---|
| 61 | /* --Methode-- */ | 
|---|
| 62 | ContModExecutor::~ContModExecutor() | 
|---|
| 63 | { | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | /* --Methode-- */ | 
|---|
| 67 | int ContModExecutor::Execute(string& kw, vector<string>& tokens, string& toks) | 
|---|
| 68 | { | 
|---|
| 69 |  | 
|---|
| 70 | int nz=-1; | 
|---|
| 71 | double z0,dz; | 
|---|
| 72 |  | 
|---|
| 73 | if ( kw == "contour") { | 
|---|
| 74 | NamedObjMgr omg; | 
|---|
| 75 | PIContourDrawer * contdrw = NULL; | 
|---|
| 76 | string dopt=""; | 
|---|
| 77 |  | 
|---|
| 78 | if (tokens.size() < 1) { | 
|---|
| 79 | cout << "Usage: contour ObjName [graphic_att/specficic_opt: SEE HELP] " << endl; | 
|---|
| 80 | return(0); | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | //   dopt = "same,thinline";  Si tu veux des valeurs par defaut | 
|---|
| 84 | //if (tokens.size() > 1)  dopt = tokens[1]; | 
|---|
| 85 | //omg.PrintObj(tokens[0]); | 
|---|
| 86 | NObjMgrAdapter* obja = omg.GetObjAdapter(tokens[0]); | 
|---|
| 87 | if (obja == NULL) { | 
|---|
| 88 | cout << "contour Error , No object with name " << tokens[0] << endl; | 
|---|
| 89 | return(0); | 
|---|
| 90 | } | 
|---|
| 91 | string ctyp = typeid(*obja).name(); | 
|---|
| 92 | cout << " objet de type "<<ctyp <<endl; | 
|---|
| 93 | AnyDataObj* ob = obja->GetDataObj(); | 
|---|
| 94 | if (ob == NULL) { | 
|---|
| 95 | cerr << "Error - NULL object ! in " <<  tokens[0] << endl; | 
|---|
| 96 | return(0); | 
|---|
| 97 | } | 
|---|
| 98 | ctyp = typeid(*ob).name(); | 
|---|
| 99 | cout << " objet de type "<<ctyp <<endl; | 
|---|
| 100 | cout << " ContModExecutor::Execute recuperation du p2darrayadapter "<<endl; | 
|---|
| 101 | if (tokens.size() > 1) dopt = tokens[1]; | 
|---|
| 102 | P2DArrayAdapter* arr = obja->Get2DArray(dopt); | 
|---|
| 103 | if (arr != NULL) { | 
|---|
| 104 | contdrw = new PIContourDrawer(arr,true           ); | 
|---|
| 105 | }else{ | 
|---|
| 106 | cout <<"contour ERREUR : OBJET "<<tokens[0]<<" N'A PAS DE P2DARRADAPTOR "<<endl; | 
|---|
| 107 | return(0); | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 |  | 
|---|
| 111 | cout << " contour: Creating PIContourDrawer() for object" << tokens[0] << endl; | 
|---|
| 112 |  | 
|---|
| 113 | cout << " contour: Determination of contour lines ..."<< contdrw <<endl; | 
|---|
| 114 | contdrw->CalcContour(); | 
|---|
| 115 | //NTuple *out = contdrw->MyIso(); | 
|---|
| 116 | //NTuple *truc = new NTuple(*out); | 
|---|
| 117 | //string nom = "isoc"; | 
|---|
| 118 | //if(out!=NULL) omg.AddObj(truc,nom   ); | 
|---|
| 119 | cout << " ===>>> success ! "<< contdrw <<endl; | 
|---|
| 120 |  | 
|---|
| 121 | // On affiche le Drawer | 
|---|
| 122 | int wrsid = 0; | 
|---|
| 123 |  | 
|---|
| 124 | string name = "contour"; | 
|---|
| 125 | cout << " ContModExecutor::Execute() : name "<<name<<" " <<"| dopt |"<<dopt<<"| contdrw |"<<contdrw<<endl; | 
|---|
| 126 | wrsid = omg.GetImgApp()->DispScDrawer(contdrw, name, dopt); | 
|---|
| 127 | cout << " fin de ContModExecutor::Execute() "<< endl; | 
|---|
| 128 |  | 
|---|
| 129 |  | 
|---|
| 130 | // Ne pas oublier d'associer le wrsid a l'objet si on utilise le P2DArrayAdapter* arr | 
|---|
| 131 | omg.AddWRsId(tokens[0], wrsid); | 
|---|
| 132 |  | 
|---|
| 133 |  | 
|---|
| 134 | } | 
|---|
| 135 | if ( kw == "ntcont"){ | 
|---|
| 136 | NamedObjMgr omg; | 
|---|
| 137 | PIContourDrawer * contdrw = NULL; | 
|---|
| 138 | string dopt=""; | 
|---|
| 139 | bool adel; | 
|---|
| 140 | //cout << " essai avec ntuple "<<tokens.size()<<endl; | 
|---|
| 141 | if (tokens.size() < 4) { | 
|---|
| 142 | cout << "Usage: contour NtName varx vary varz [graphic_att/specific_opt: SEE HELP]" | 
|---|
| 143 | << endl; | 
|---|
| 144 | return(0); | 
|---|
| 145 | } | 
|---|
| 146 | dopt=""; | 
|---|
| 147 | NObjMgrAdapter* obja = omg.GetObjAdapter(tokens[0]); | 
|---|
| 148 | if (obja == NULL) { | 
|---|
| 149 | cout << "ntcont Error , No NTuple with name " << tokens[0] << endl; | 
|---|
| 150 | return(0); | 
|---|
| 151 | } | 
|---|
| 152 |  | 
|---|
| 153 | NTupleInterface *ntin = obja->GetNTupleInterface(adel); | 
|---|
| 154 | //cout << " tokens.size() "<< tokens.size()<<endl; | 
|---|
| 155 | //for (int k=0; k<tokens.size() ; k++)cout<<"| k "<<k<<" tok |"<<tokens[k]; | 
|---|
| 156 | //cout <<endl; | 
|---|
| 157 | if (tokens.size() > 4) dopt = tokens[4]; | 
|---|
| 158 | if (tokens.size() > 6){ | 
|---|
| 159 | dz = atof(tokens[6].c_str()); | 
|---|
| 160 | z0 = atof(tokens[7].c_str()); | 
|---|
| 161 | cout << " ContModExecutor::Execute [NT] nz,z,dz : "<<nz<<" , "<<z0 << " , " << dz<<endl; | 
|---|
| 162 | contdrw = new PIContourDrawer(ntin,adel,&nz,&z0,&dz); | 
|---|
| 163 | } | 
|---|
| 164 | if (tokens.size() > 5){ | 
|---|
| 165 | nz = atoi(tokens[5].c_str()); | 
|---|
| 166 | cout << " ContModExecutor::Execute [NT] nz : "<<nz<< endl; | 
|---|
| 167 | contdrw = new PIContourDrawer(ntin,adel,&nz           ); | 
|---|
| 168 | }else { | 
|---|
| 169 | contdrw = new PIContourDrawer(ntin,adel           ); | 
|---|
| 170 | } | 
|---|
| 171 | cout << " ntcont: Creating PIContourDrawer() for object " << tokens[0] << endl; | 
|---|
| 172 |  | 
|---|
| 173 | cout << " ntcont : Determination of contour lines ..." <<endl; | 
|---|
| 174 | contdrw->CalcContour(); | 
|---|
| 175 |  | 
|---|
| 176 | NTuple *out = contdrw->MyIso(); | 
|---|
| 177 | if(out!=NULL){ | 
|---|
| 178 | NTuple *truc = new NTuple(*out); | 
|---|
| 179 | string nom = "isoc"; | 
|---|
| 180 | //truc->Write("isocur.ppf"); | 
|---|
| 181 | //out->Write("outcur.ppf"); | 
|---|
| 182 | omg.AddObj(truc,nom   ); | 
|---|
| 183 | } | 
|---|
| 184 | /****************/ | 
|---|
| 185 | cout << " ===>>> success ! "<<endl; | 
|---|
| 186 |  | 
|---|
| 187 | // On affiche le Drawer | 
|---|
| 188 | int wrsid = 0; | 
|---|
| 189 | bool fgsr = true; | 
|---|
| 190 |  | 
|---|
| 191 | string name = "contour"; | 
|---|
| 192 |  | 
|---|
| 193 | wrsid = omg.GetImgApp()->DispScDrawer(contdrw, name, dopt); | 
|---|
| 194 |  | 
|---|
| 195 | // Ne pas oublier d'associer le wrsid a l'objet si on utilise le P2DArrayAdapter* arr | 
|---|
| 196 | omg.AddWRsId(tokens[0], wrsid); | 
|---|
| 197 |  | 
|---|
| 198 | } | 
|---|
| 199 |  | 
|---|
| 200 |  | 
|---|
| 201 |  | 
|---|
| 202 | return(0); | 
|---|
| 203 |  | 
|---|
| 204 | } | 
|---|
| 205 |  | 
|---|
| 206 |  | 
|---|
| 207 |  | 
|---|