0023022: This is desirable to access OpenGl extensions and core API (1.2+) in one...
[occt.git] / src / ImageUtility / ImageUtility_XWUD.cxx
1 // Modified     27/12/98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
2 //
3
4 #include <Image_Image.hxx>
5 #include <AlienImage_XAlienImage.hxx>
6 #include <OSD_Process.hxx>
7 #include <OSD_File.hxx>
8 #include <ImageUtility_XWUD.ixx>
9
10 #define LOPTIM
11 #ifndef LOPTIM
12 static Handle(AlienImage_XAlienImage) XAlienImage = new AlienImage_XAlienImage();
13 #else 
14 static Handle(AlienImage_XAlienImage)& _XAlienImage() {
15     static Handle(AlienImage_XAlienImage) XAlienImage = new AlienImage_XAlienImage();
16 return XAlienImage;
17 }
18 #define XAlienImage _XAlienImage()
19 #endif // LOPTIM
20
21 void ImageUtility_XWUD::XWUD( 
22                 const Handle(AlienImage_AlienUserImage)& aAlienImage,
23                 const Standard_CString aName,
24                 const Standard_CString xwudOptions )
25
26
27  if ( aAlienImage->IsKind(STANDARD_TYPE(AlienImage_XAlienImage) ) ) {
28         Handle(AlienImage_XAlienImage) aXImage =
29                 Handle(AlienImage_XAlienImage)::DownCast(aAlienImage) ;
30
31         aXImage->SetName( TCollection_AsciiString( aName ) ) ;
32
33         XWUD( aXImage, xwudOptions ) ;
34   }
35   else {
36     XWUD( aAlienImage->ToImage(), aName, xwudOptions ) ;
37   }
38 }
39
40 void ImageUtility_XWUD::XWUD( const Handle(Image_Image)& aImage,
41                                     const Standard_CString aName,
42                                     const Standard_CString xwudOptions )
43
44 { XAlienImage->Clear() ;
45   XAlienImage->FromImage( aImage ) ;
46
47   XAlienImage->SetName( TCollection_AsciiString( aName ) ) ;
48
49   XWUD( XAlienImage, xwudOptions ) ;
50 }
51
52 void ImageUtility_XWUD::XWUD( 
53         const Handle(AlienImage_XAlienImage)& aXImage,
54         const Standard_CString xwudOptions )
55
56
57   OSD_File File = OSD_File::BuildTemporary() ;
58
59 #ifdef TRACE
60   OSD_Path Path ;
61   TCollection_AsciiString Name ;
62
63   File.Path(Path) ;
64
65   Path.SystemName( Name ) ;
66
67   cout << "BuildTemporaryFile :" << Name << endl << flush ;
68 #endif
69
70   aXImage->Write( File ) ;
71
72   File.Close() ;
73
74   XWUD( File, xwudOptions ) ;
75 }
76
77
78 void ImageUtility_XWUD::XWUD( const OSD_File& File,
79                                     const Standard_CString xwudOptions )
80
81
82   TCollection_AsciiString s, Name ;
83   OSD_Path Path ;
84   OSD_Process Process ;
85
86   File.Path( Path ) ;
87
88   Path.SystemName( Name, OSD_Default ) ;
89
90   XWUD( Name.ToCString(), xwudOptions ) ;
91 }
92
93 void ImageUtility_XWUD::XWUD( const Standard_CString aName,
94                                     const Standard_CString xwudOptions )
95
96
97   TCollection_AsciiString s;
98   OSD_Process Process ;
99
100   s = TCollection_AsciiString("xwud ") 
101         + TCollection_AsciiString(xwudOptions) 
102         + TCollection_AsciiString(" -in ") 
103         + aName
104         + TCollection_AsciiString( "&" );
105
106   Process.Spawn( s ) ;
107
108 }
109