00001 00002 // exotkAIS_DisplayManager.cxx 00004 // Copyright (C) 2001 Stephane Routelous 00005 // 00006 // This file is part of exoTK. 00007 // 00008 // exoTK is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // exoTK is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with exoTK; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00028 #include <exotkAIS_DisplayManager.hxx> 00029 00030 #ifndef _AIS_InteractiveContext_HeaderFile 00031 #include <AIS_InteractiveContext.hxx> 00032 #endif 00033 #ifndef _AIS_InteractiveObject_HeaderFile 00034 #include <AIS_InteractiveObject.hxx> 00035 #endif 00036 #ifndef _Graphic3d_WNTGraphicDevice_HeaderFile 00037 #include <Graphic3d_WNTGraphicDevice.hxx> 00038 #endif 00039 #ifndef _exotkAIS_GraphicDevice_HeaderFile 00040 #include <exotkAIS_GraphicDevice.hxx> 00041 #endif 00042 #ifndef _TCollection_ExtendedString_HeaderFile 00043 #include <TCollection_ExtendedString.hxx> 00044 #endif 00045 #ifndef _V3d_Viewer_HeaderFile 00046 #include <V3d_Viewer.hxx> 00047 #endif 00048 #ifndef _AIS_SequenceOfInteractive_HeaderFile 00049 #include <AIS_SequenceOfInteractive.hxx> 00050 #endif 00051 #ifndef _Graphic3d_MaterialAspect_HeaderFile 00052 #include <Graphic3d_MaterialAspect.hxx> 00053 #endif 00054 #ifndef _AIS_Drawer_HeaderFile 00055 #include <AIS_Drawer.hxx> 00056 #endif 00057 #ifndef _Prs3d_ShadingAspect_HeaderFile 00058 #include <Prs3d_ShadingAspect.hxx> 00059 #endif 00060 00061 #ifndef _Standard_DefineHandle_HeaderFile 00062 #include <Standard_DefineHandle.hxx> 00063 #endif 00064 // 00065 IMPLEMENT_STANDARD_HANDLE(exotkAIS_DisplayManager, MMgt_TShared) 00066 IMPLEMENT_STANDARD_RTTI(exotkAIS_DisplayManager, MMgt_TShared) 00067 // 00068 // Foreach ancestors, we add a IMPLEMENT_STANDARD_SUPERTYPE and 00069 // a IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY macro. 00070 // We must respect the order: from the direct ancestor class 00071 // to the base class. 00072 // 00073 00074 IMPLEMENT_STANDARD_TYPE(exotkAIS_DisplayManager) 00075 IMPLEMENT_STANDARD_SUPERTYPE(MMgt_TShared) 00076 IMPLEMENT_STANDARD_SUPERTYPE(Standard_Transient) 00077 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY() 00078 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(MMgt_TShared) 00079 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(Standard_Transient) 00080 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END() 00081 IMPLEMENT_STANDARD_TYPE_END(exotkAIS_DisplayManager) 00082 00083 //================================================================================== 00084 // Function name : exotkAIS_DisplayManager::exotkAIS_DisplayManager 00085 //================================================================================== 00086 // Written by : Stephane Routelous - 2001-11-07 19:15:16 00087 // Description : 00088 // Return type : 00089 //================================================================================== 00090 exotkAIS_DisplayManager::exotkAIS_DisplayManager() 00091 { 00092 #ifdef WNT 00093 Handle_Graphic3d_WNTGraphicDevice theGraphicDevice = Handle_Graphic3d_WNTGraphicDevice::DownCast(exotkAIS_GraphicDevice::Instance()->GetGraphicDevice()); 00094 #else 00095 Handle_Aspect_GraphicDevice theGraphicDevice = exotkAIS_GraphicDevice::Instance()->GetGraphicDevice(); 00096 #endif 00097 00098 TCollection_ExtendedString a3DName("exotkAIS_DisplayManager"); 00099 Handle_V3d_Viewer theViewer = new V3d_Viewer(theGraphicDevice,a3DName.ToExtString(),"", 1000.0, 00100 V3d_XposYnegZpos, Quantity_NOC_GRAY30, 00101 V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT, 00102 Standard_True, Standard_False); 00103 00104 theViewer->SetDefaultLights(); 00105 theViewer->SetLightOn(); 00106 00107 00108 myAISContext =new AIS_InteractiveContext(theViewer); 00109 00110 // initialize the name seed 00111 myNameSeed = TCollection_AsciiString("Object"); 00112 // initialize the name counter 00113 myNameIndex = 1; 00114 } 00115 00116 //================================================================================== 00117 // Function name : exotkAIS_DisplayManager::exotkAIS_DisplayManager 00118 //================================================================================== 00119 // Written by : Stephane Routelous - 2001-11-07 19:15:19 00120 // Description : 00121 // Return type : 00122 //================================================================================== 00123 // Argument : const Handle_V3d_Viewer& aViewer 00124 exotkAIS_DisplayManager::exotkAIS_DisplayManager(const Handle_V3d_Viewer& aViewer) 00125 { 00126 myAISContext =new AIS_InteractiveContext(aViewer); 00127 00128 // initialize the name seed 00129 myNameSeed = TCollection_AsciiString("Object"); 00130 // initialize the name counter 00131 myNameIndex = 1; 00132 } 00133 00134 //================================================================================== 00135 // Function name : exotkAIS_DisplayManager::exotkAIS_DisplayManager 00136 //================================================================================== 00137 // Written by : Stephane Routelous - 2001-11-07 19:15:22 00138 // Description : 00139 // Return type : 00140 //================================================================================== 00141 // Argument : const Handle_AIS_InteractiveContext& anAISContext 00142 exotkAIS_DisplayManager::exotkAIS_DisplayManager(const Handle_AIS_InteractiveContext& anAISContext) 00143 { 00144 myAISContext = anAISContext; 00145 // initialize the name seed 00146 myNameSeed = TCollection_AsciiString("Object"); 00147 // initialize the name counter 00148 myNameIndex = 1; 00149 } 00150 00151 00152 //================================================================================== 00153 // Function name : exotkAIS_DisplayManager::~exotkAIS_DisplayManager 00154 //================================================================================== 00155 // Written by : Stephane Routelous - 2001-11-07 19:15:25 00156 // Description : 00157 // Return type : 00158 //================================================================================== 00159 exotkAIS_DisplayManager::~exotkAIS_DisplayManager() 00160 { 00161 } 00162 00163 00164 //================================================================================== 00165 // Function name : exotkAIS_DisplayManager::SetNameSeed 00166 //================================================================================== 00167 // Written by : Stephane Routelous - 2001-11-07 19:15:28 00168 // Description : 00169 // Return type : TCollection_AsciiString 00170 //================================================================================== 00171 // Argument : const TCollection_AsciiString &aNewSeed 00172 TCollection_AsciiString exotkAIS_DisplayManager::SetNameSeed(const TCollection_AsciiString &aNewSeed) 00173 { 00174 // get the old seed 00175 TCollection_AsciiString theOldSeed = myNameSeed; 00176 00177 // if the new seed is valid, change it 00178 if (!aNewSeed.IsEmpty()) 00179 { 00180 myNameSeed = aNewSeed; 00181 // reset the counter 00182 myNameIndex = 1; 00183 } 00184 // return the old seed 00185 return theOldSeed; 00186 } 00187 00188 //================================================================================== 00189 // Function name : exotkAIS_DisplayManager::NameSeed 00190 //================================================================================== 00191 // Written by : Stephane Routelous - 2001-11-07 19:15:30 00192 // Description : 00193 // Return type : TCollection_AsciiString 00194 //================================================================================== 00195 TCollection_AsciiString exotkAIS_DisplayManager::NameSeed() 00196 { 00197 return myNameSeed; 00198 } 00199 00200 00201 //================================================================================== 00202 // Function name : exotkAIS_DisplayManager::InteractiveContext 00203 //================================================================================== 00204 // Written by : Stephane Routelous - 2001-11-07 19:15:32 00205 // Description : 00206 // Return type : Handle_AIS_InteractiveContext& 00207 //================================================================================== 00208 Handle_AIS_InteractiveContext& exotkAIS_DisplayManager::InteractiveContext() 00209 { 00210 return myAISContext; 00211 } 00212 00213 //================================================================================== 00214 // Function name : exotkAIS_DisplayManager::NameExists 00215 //================================================================================== 00216 // Written by : Stephane Routelous - 2001-11-07 19:15:34 00217 // Description : 00218 // Return type : Standard_Boolean 00219 //================================================================================== 00220 // Argument : const TCollection_AsciiString &aNameToTest 00221 Standard_Boolean exotkAIS_DisplayManager::NameExists(const TCollection_AsciiString &aNameToTest) 00222 { 00223 // see in the map if the name already exists 00224 return myMap.IsBound1(aNameToTest); 00225 } 00226 00227 00228 00229 //================================================================================== 00230 // Function name : exotkAIS_DisplayManager::ObjectExists 00231 //================================================================================== 00232 // Written by : Stephane Routelous - 2001-12-03 21:39:59 00233 // Description : 00234 // Return type : Standard_Boolean 00235 //================================================================================== 00236 // Argument : const Handle_AIS_InteractiveObject& anObjectToTest 00237 Standard_Boolean exotkAIS_DisplayManager::ObjectExists(const Handle_AIS_InteractiveObject& anObjectToTest) 00238 { 00239 // see in the map if the object already exists 00240 return myMap.IsBound2(anObjectToTest); 00241 } 00242 00243 00244 //================================================================================== 00245 // Function name : exotkAIS_DisplayManager::Add 00246 //================================================================================== 00247 // Written by : Stephane Routelous - 2001-11-07 19:15:35 00248 // Description : 00249 // Return type : TCollection_AsciiString 00250 //================================================================================== 00251 // Argument : const Handle_AIS_InteractiveObject& anObjectToAdd 00252 // Argument : const TCollection_AsciiString& aProposedName /*= TCollection_AsciiString()*/ 00253 // Argument : const Standard_Integer aDisplayMode /*= 0*/ 00254 // Argument : const Standard_Boolean UpdateViewer /*= Standard_True*/ 00255 TCollection_AsciiString exotkAIS_DisplayManager::Add(const Handle_AIS_InteractiveObject& anObjectToAdd, const TCollection_AsciiString& aProposedName, const Standard_Integer aDisplayMode , const Standard_Boolean UpdateViewer ) 00256 { 00257 TCollection_AsciiString theReturnedName; 00258 00259 // the object to add is not valid, so return an empty string 00260 if (anObjectToAdd.IsNull()) 00261 return theReturnedName; 00262 00263 // if the name exists 00264 if ( aProposedName.IsEmpty() || NameExists(aProposedName)) 00265 { 00266 // generate a new name 00267 theReturnedName = myNameSeed + TCollection_AsciiString("_") + TCollection_AsciiString(myNameIndex); 00268 myNameIndex++; 00269 } 00270 else 00271 { 00272 theReturnedName = aProposedName; 00273 } 00274 00275 // the object is new 00276 if (!myMap.IsBound2(anObjectToAdd)) 00277 { 00278 // add it to the map 00279 myMap.Bind(theReturnedName, anObjectToAdd); 00280 // set its display mode 00281 anObjectToAdd->SetDisplayMode(aDisplayMode); 00282 // display it 00283 myAISContext->Display(anObjectToAdd, UpdateViewer); 00284 } 00285 else 00286 { 00287 // get the existing name of the object in the map 00288 theReturnedName = myMap.Find2(anObjectToAdd); 00289 // redisplay it 00290 myAISContext->Redisplay(anObjectToAdd, UpdateViewer); 00291 } 00292 00293 // return the name of the added object 00294 return theReturnedName; 00295 } 00296 00297 00298 00299 //================================================================================== 00300 // Function name : exotkAIS_DisplayManager::Remove 00301 //================================================================================== 00302 // Written by : Stephane Routelous - 2001-11-07 19:15:38 00303 // Description : 00304 // Return type : TCollection_AsciiString 00305 //================================================================================== 00306 // Argument : const Handle_AIS_InteractiveObject& anObjectToRemove 00307 // Argument : const Standard_Boolean UpdateViewer 00308 TCollection_AsciiString exotkAIS_DisplayManager::Remove(const Handle_AIS_InteractiveObject& anObjectToRemove, const Standard_Boolean UpdateViewer) 00309 { 00310 TCollection_AsciiString theRemovedObjectName; 00311 00312 // test if the object is known 00313 if (!anObjectToRemove.IsNull() && myMap.IsBound2(anObjectToRemove)) 00314 { 00315 // the object is found 00316 00317 // get its name 00318 theRemovedObjectName = Name(anObjectToRemove); 00319 00320 // unbind it from the map 00321 myMap.UnBind2(anObjectToRemove); 00322 00323 // remove it from the AISContext 00324 myAISContext->Remove(anObjectToRemove, UpdateViewer); 00325 } 00326 return theRemovedObjectName; 00327 } 00328 00329 //================================================================================== 00330 // Function name : exotkAIS_DisplayManager::Remove 00331 //================================================================================== 00332 // Written by : Stephane Routelous - 2001-11-07 19:15:40 00333 // Description : 00334 // Return type : TCollection_AsciiString 00335 //================================================================================== 00336 // Argument : const TCollection_AsciiString& anObjectNameToRemove 00337 // Argument : const Standard_Boolean UpdateViewer 00338 TCollection_AsciiString exotkAIS_DisplayManager::Remove(const TCollection_AsciiString& anObjectNameToRemove, const Standard_Boolean UpdateViewer) 00339 { 00340 TCollection_AsciiString theRemovedObjectName; 00341 // get the InteractiveObject from the name 00342 Handle_AIS_InteractiveObject theFoundIO = InteractiveObject(anObjectNameToRemove); 00343 00344 // try to remove it 00345 return Remove(theFoundIO, UpdateViewer); 00346 } 00347 00348 00349 //================================================================================== 00350 // Function name : exotkAIS_DisplayManager::InteractiveObject 00351 //================================================================================== 00352 // Written by : Stephane Routelous - 2001-11-07 19:15:42 00353 // Description : 00354 // Return type : Handle_AIS_InteractiveObject 00355 //================================================================================== 00356 // Argument : const TCollection_AsciiString &aNameToFind 00357 Handle_AIS_InteractiveObject exotkAIS_DisplayManager::InteractiveObject(const TCollection_AsciiString &aNameToFind) 00358 { 00359 // search in the map the InteractiveObject corresponding to the name 00360 Handle_AIS_InteractiveObject theFoundIO; 00361 if (myMap.IsBound1(aNameToFind)) 00362 { 00363 theFoundIO = myMap.Find1(aNameToFind); 00364 } 00365 return theFoundIO; 00366 } 00367 00368 00369 //================================================================================== 00370 // Function name : exotkAIS_DisplayManager::Name 00371 //================================================================================== 00372 // Written by : Stephane Routelous - 2001-11-07 19:15:43 00373 // Description : 00374 // Return type : TCollection_AsciiString 00375 //================================================================================== 00376 // Argument : const Handle_AIS_InteractiveObject &anObjectToFind 00377 TCollection_AsciiString exotkAIS_DisplayManager::Name(const Handle_AIS_InteractiveObject &anObjectToFind) 00378 { 00379 // search in the map the AsciiString corresponding to the InteractiveObject 00380 TCollection_AsciiString theFoundName; 00381 if (myMap.IsBound2(anObjectToFind)) 00382 { 00383 theFoundName = myMap.Find2(anObjectToFind); 00384 } 00385 return theFoundName; 00386 } 00387 00388 //================================================================================== 00389 // Function name : CurrentObjects 00390 //================================================================================== 00391 // Written by : Stephane Routelous - 2001-11-19 18:08:46 00392 // Description : 00393 // Return type : Standard_Boolean 00394 //================================================================================== 00395 // Argument : AIS_SequenceOfInteractive& aSequence 00396 Standard_Boolean exotkAIS_DisplayManager::CurrentObjects(AIS_SequenceOfInteractive& aSequence) 00397 { 00398 aSequence.Clear(); 00399 for ( myAISContext->InitCurrent() ; myAISContext->MoreCurrent() ; myAISContext->NextCurrent() ) 00400 { 00401 Handle_AIS_InteractiveObject theCurrent = myAISContext->Current(); 00402 aSequence.Append(theCurrent); 00403 } 00404 return (!aSequence.IsEmpty() ); 00405 } 00406 00407 00408 //================================================================================== 00409 // Function name : exotkAIS_DisplayManager::SetDisplayMode 00410 //================================================================================== 00411 // Written by : Stephane Routelous - 2001-12-03 21:42:20 00412 // Description : 00413 // Return type : void 00414 //================================================================================== 00415 // Argument : const Handle_AIS_InteractiveObject &anObject 00416 // Argument : const enum exotkAIS_DisplayMode aMode 00417 void exotkAIS_DisplayManager::SetDisplayMode(const Handle_AIS_InteractiveObject &anObject, const enum exotkAIS_DisplayMode aMode) 00418 { 00419 if ( ObjectExists(anObject) ) 00420 { 00421 myAISContext->SetDisplayMode(anObject,aMode,Standard_True); 00422 } 00423 } 00424 00425 00426 //================================================================================== 00427 // Function name : exotkAIS_DisplayManager::SetMaterial 00428 //================================================================================== 00429 // Written by : Stephane Routelous - 2001-12-05 16:00:18 00430 // Description : 00431 // Return type : void 00432 //================================================================================== 00433 // Argument : const Handle_AIS_InteractiveObject &anObject 00434 // Argument : const Graphic3d_MaterialAspect &aMaterial 00435 void exotkAIS_DisplayManager::SetMaterial(const Handle_AIS_InteractiveObject &anObject, const Graphic3d_MaterialAspect &aMaterial) 00436 { 00437 if ( ObjectExists(anObject) ) 00438 { 00439 // anObject->Attributes()->ShadingAspect()->SetMaterial(aMaterial); 00440 anObject->SetMaterial(aMaterial); 00441 myAISContext->Redisplay(anObject); 00442 } 00443 } 00444 00445 void exotkAIS_DisplayManager::SetTransparency(const Handle_AIS_InteractiveObject &anObject, const Standard_Real aTransparency) 00446 { 00447 if ( ObjectExists(anObject) ) 00448 { 00449 anObject->SetTransparency(aTransparency); 00450 myAISContext->Redisplay(anObject); 00451 } 00452 }
1.2.12 written by Dimitri van Heesch,
© 1997-2001