1 /*------------------------------------------------------------\
2 |                                                             |
3 | This file is part of the Alliance CAD System Copyright      |
4 | (C) Laboratoire LIP6 - D�partement ASIM Universite P&M Curie|
5 |                                                             |
6 | Home page      : http://www-asim.lip6.fr/alliance/          |
7 | E-mail         : mailto:alliance-users@asim.lip6.fr       |
8 |                                                             |
9 | This progam is  free software; you can redistribute it      |
10 | and/or modify it under the  terms of the GNU General Public |
11 | License as  published by the Free Software Foundation;      |
12 | either version 2 of the License, or (at your option) any    |
13 | later version.                                              |
14 |                                                             |
15 | Alliance VLSI  CAD System  is distributed  in the hope that |
16 | it  will be useful, but WITHOUT  ANY WARRANTY;              |
17 | without even the  implied warranty of MERCHANTABILITY or    |
18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General       |
19 | Public License for more details.                            |
20 |                                                             |
21 | You should have received a copy  of the GNU General Public  |
22 | License along with the GNU C Library; see the file COPYING. |
23 | If not, write to the Free Software Foundation, Inc.,        |
24 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                     |
25 |                                                             |
26 \------------------------------------------------------------*/
27 
28 /*------------------------------------------------------------\
29 |                                                             |
30 | Tool    :                   GRAAL                           |
31 |                                                             |
32 | File    :                   File.c                          |
33 |                                                             |
34 | Author  :                Jacomme Ludovic                    |
35 |                                                             |
36 | Date    :                  28.03.95                         |
37 |                                                             |
38 \------------------------------------------------------------*/
39 /*------------------------------------------------------------\
40 |                                                             |
41 |                         Include Files                       |
42 |                                                             |
43 \------------------------------------------------------------*/
44 
45 # include <stdio.h>
46 # include <string.h>
47 # include <Xm/Xm.h>
48 # include <Xm/FileSB.h>
49 # include <Xm/SelectioB.h>
50 # include <Xm/PushBG.h>
51 
52 # include "mut.h"
53 # include "mph.h"
54 # include "rds.h"
55 # include "rpr.h"
56 # include "rfm.h"
57 # include "GRM.h"
58 # include "GMX.h"
59 # include "GTB.h"
60 # include "GSB.h"
61 # include "GMF.h"
62 # include "GMV.h"
63 # include "GMT.h"
64 
65 # include "GMF_file.h"
66 
67 /*------------------------------------------------------------\
68 |                                                             |
69 |                           Constants                         |
70 |                                                             |
71 \------------------------------------------------------------*/
72 /*------------------------------------------------------------\
73 |                                                             |
74 |                            Types                            |
75 |                                                             |
76 \------------------------------------------------------------*/
77 /*------------------------------------------------------------\
78 |                                                             |
79 |                          Variables                          |
80 |                                                             |
81 \------------------------------------------------------------*/
82 
83   char GraalFileFilter[ 10 ]    = "*.";
84   char GraalFileExtention[ 10 ] = ".";
85 
86   char GraalFileBuffer[ 128 ];
87   char GraalFileDirectoryBuffer[ 512 ];
88 
89 /*------------------------------------------------------------\
90 |                                                             |
91 |                          Functions                          |
92 |                                                             |
93 \------------------------------------------------------------*/
94 /*------------------------------------------------------------\
95 |                                                             |
96 |                        GraalFileNew                         |
97 |                                                             |
98 \------------------------------------------------------------*/
99 
GraalFileNew()100 void GraalFileNew()
101 {
102   rdsbegin();
103 
104   GraalSetMouseCursor( GraalGraphicWindow, GRAAL_WATCH_CURSOR  );
105 
106   if ( GraalFigureMbk != (phfig_list *)NULL )
107   {
108     GraalDelEqui();
109     GraalDelPeek();
110     GraalDelSelect();
111     GraalDelDrucFigure();
112     GraalDelFigure();
113   }
114 
115   GraalChangeTopLevelTitle( (char *)NULL );
116 
117   GraalRecomputeBound = GRAAL_TRUE;
118 
119   GraalInitializeZoom();
120   GraalInitializeUndo();
121   GraalClearGraphicWindow( 0, 0, GraalGraphicDx, GraalGraphicDy );
122 
123   GraalRefreshGraphicWindow( 0, 0,
124                              GraalGraphicDx, GraalGraphicDy );
125 
126   GraalSetMouseCursor( GraalGraphicWindow, GRAAL_NORMAL_CURSOR );
127 
128   rdsend();
129 }
130 
131 /*------------------------------------------------------------\
132 |                                                             |
133 |                        GraalFileSave                        |
134 |                                                             |
135 \------------------------------------------------------------*/
136 
GraalFileSave()137 void GraalFileSave()
138 {
139   char Ok;
140 
141   rdsbegin();
142 
143   GraalSetMouseCursor( GraalGraphicWindow, GRAAL_WATCH_CURSOR  );
144 
145   Ok = GraalSaveFigure();
146 
147   GraalDisplayToolsMessage();
148 
149   if ( ! Ok )
150   {
151     GraalErrorMessage( GraalMainWindow, "Unable to save this figure !" );
152   }
153 
154   GraalInitializeUndo();
155 
156   GraalSetMouseCursor( GraalGraphicWindow, GRAAL_NORMAL_CURSOR  );
157 
158   rdsend();
159 }
160 
161 /*------------------------------------------------------------\
162 |                                                             |
163 |                        GraalFileSaveAs                      |
164 |                                                             |
165 \------------------------------------------------------------*/
166 
GraalFileSaveAs(FileName)167 void GraalFileSaveAs( FileName )
168 
169    char *FileName;
170 {
171   rdsins_list *InstanceRds;
172   char         Ok;
173 
174   rdsbegin();
175 
176   if ( FileName == (char *)NULL )
177   {
178     FileName = GraalFigureMbk->NAME;
179   }
180   else
181   {
182     FileName = namealloc( FileName );
183   }
184 
185   for ( InstanceRds  = GraalFigureRds->INSTANCE;
186         InstanceRds != (rdsins_list *)NULL;
187         InstanceRds  = InstanceRds->NEXT )
188   {
189     if ( InstanceRds->FIGNAME == FileName ) break;
190   }
191 
192   if ( InstanceRds != (rdsins_list *)NULL )
193   {
194     GraalErrorMessage( GraalMainWindow,
195                        "A figure cannot be part of itself !" );
196   }
197   else
198   {
199     GraalSetMouseCursor( GraalGraphicWindow, GRAAL_WATCH_CURSOR );
200 
201     GraalFigureMbk->NAME = FileName;
202     GraalFigureRds->NAME = FileName;
203 
204     GraalChangeTopLevelTitle( GraalFigureMbk->NAME );
205 
206     if ( GraalFigureRds->LAYERTAB[ RDS_ABOX ] != (rdsrec_list *)NULL )
207     {
208       GraalFigureRds->LAYERTAB[ RDS_ABOX ]->NAME = FileName;
209     }
210 
211     Ok = GraalSaveFigure();
212 
213     GraalDisplayToolsMessage();
214 
215     if ( ! Ok )
216     {
217       GraalErrorMessage( GraalMainWindow, "Unable to save this figure !" );
218     }
219 
220     GraalSetMouseCursor( GraalGraphicWindow, GRAAL_NORMAL_CURSOR );
221   }
222 
223   GraalInitializeUndo();
224 
225   rdsend();
226 }
227 
228 /*------------------------------------------------------------\
229 |                                                             |
230 |                        GraalFileOpen                        |
231 |                                                             |
232 \------------------------------------------------------------*/
233 
GraalFileOpen(FileName,DisplayFigure)234 void GraalFileOpen( FileName, DisplayFigure  )
235 
236   char *FileName;
237   int   DisplayFigure;
238 {
239   int         Index;
240   char       *SWAP_WORK_LIB = WORK_LIB;
241 
242   rdsbegin();
243 
244   GraalSetMouseCursor( GraalGraphicWindow, GRAAL_WATCH_CURSOR  );
245   GraalUndisplayCursor();
246 
247   if ( GraalFigureMbk != (phfig_list *)NULL )
248   {
249     GraalDelEqui();
250     GraalDelPeek();
251     GraalDelSelect();
252     GraalDelDrucFigure();
253     GraalInitializeUndo();
254     GraalDelFigure();
255   }
256 
257   GraalRecomputeBound = GRAAL_TRUE;
258 
259   if ( GRAAL_WORK_LIB == (char *)NULL )
260   {
261     GRAAL_WORK_LIB = WORK_LIB;
262   }
263 
264   for ( Index = strlen( FileName ); Index >= 0; Index-- )
265   {
266     if ( FileName[ Index ] == '/' ) break;
267   }
268 
269   if ( Index >= 0 )
270   {
271     strcpy( GraalFileDirectoryBuffer, FileName );
272     strcpy( GraalFileBuffer, FileName + Index + 1);
273 
274     GraalFileDirectoryBuffer[ Index + 1 ] = '\0';
275 
276     WORK_LIB = GraalFileDirectoryBuffer;
277   }
278   else
279   {
280     strcpy( GraalFileBuffer, FileName );
281 
282     WORK_LIB = GRAAL_WORK_LIB;
283   }
284 
285   Index = strlen( GraalFileBuffer ) - strlen( GraalFileExtention );
286 
287   if ( Index >= 0 )
288   {
289     if ( ! strcmp( GraalFileBuffer + Index, GraalFileExtention ) )
290     {
291       GraalFileBuffer[ Index ] = '\0';
292     }
293   }
294 
295   GraalFigureMbk = Graalgetphfig( GraalFileBuffer, 'A' );
296 
297   GraalInitializeUndo();
298 
299   GraalDisplayToolsMessage();
300 
301   if ( GraalFigureMbk == (phfig_list *)NULL )
302   {
303     GraalErrorMessage( GraalMainWindow, "Unable to open this figure !" );
304     GraalChangeTopLevelTitle( (char *)NULL );
305     GraalInitializeZoom();
306     GraalClearGraphicWindow( 0, 0, GraalGraphicDx, GraalGraphicDy );
307   }
308   else
309   {
310     GraalAddFigure();
311     GraalChangeTopLevelTitle( GraalFigureMbk->NAME );
312     GraalInitializeZoom();
313 
314     if ( DisplayFigure )
315     {
316       GraalDisplayFigure( 0, 0, GraalGraphicDx, GraalGraphicDy );
317     }
318   }
319 
320   if ( DisplayFigure )
321   {
322     GraalRefreshGraphicWindow( 0, 0,
323                                GraalGraphicDx, GraalGraphicDy );
324   }
325 
326   GraalSetMouseCursor( GraalGraphicWindow, GRAAL_NORMAL_CURSOR );
327   GraalDisplayCursor();
328 
329   WORK_LIB = SWAP_WORK_LIB;
330 
331   rdsend();
332 }
333