PageRenderTime 33ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/brlcad/tags/rel-5-0-beta/iges/check_names.c

https://bitbucket.org/vrrm/brl-cad-copy-for-fast-history-browsing-in-git
C | 693 lines | 578 code | 78 blank | 37 comment | 119 complexity | f8a36128d2317e83ecb33ca8ca8fbc4a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, LGPL-2.1, Apache-2.0, AGPL-3.0, LGPL-3.0, GPL-3.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, 0BSD, BSD-3-Clause
  1. /*
  2. * Authors -
  3. * John R. Anderson
  4. *
  5. * Source -
  6. * SLAD/BVLD/VMB
  7. * The U. S. Army Research Laboratory
  8. * Aberdeen Proving Ground, Maryland 21005
  9. *
  10. * Copyright Notice -
  11. * This software is Copyright (C) 1993 by the United States Army.
  12. * All rights reserved.
  13. */
  14. #include "./iges_struct.h"
  15. #include "./iges_extern.h"
  16. char *
  17. Add_brl_name( name )
  18. char *name;
  19. {
  20. struct name_list *ptr;
  21. int namelen;
  22. int i;
  23. int found=0;
  24. /* replace white space */
  25. namelen = strlen( name );
  26. if( namelen > NAMESIZE)
  27. {
  28. namelen = NAMESIZE;
  29. name[namelen] = '\0';
  30. }
  31. for( i=0 ; i<namelen ; i++ )
  32. {
  33. if( isspace( name[i] ) || name[i] == '/' )
  34. name[i] = '_';
  35. }
  36. /* Check if name already in list */
  37. ptr = name_root;
  38. while( ptr )
  39. {
  40. if( !strncmp( ptr->name, name, NAMESIZE ) )
  41. {
  42. found = 1;
  43. return( ptr->name );
  44. }
  45. ptr = ptr->next;
  46. }
  47. /* add this name to the list */
  48. ptr = (struct name_list *)rt_malloc( sizeof( struct name_list ), "Add_brl_name: ptr" );
  49. strcpy( ptr->name, name );
  50. ptr->next = name_root;
  51. name_root = ptr;
  52. return( ptr->name );
  53. }
  54. char *
  55. Make_unique_brl_name( name )
  56. char *name;
  57. {
  58. struct name_list *ptr;
  59. int found;
  60. int namelen;
  61. int char_ptr;
  62. int i,j;
  63. /* replace white space */
  64. namelen = strlen( name );
  65. for( i=0 ; i<namelen ; i++ )
  66. {
  67. if( isspace( name[i] ) || name[i] == '/' )
  68. name[i] = '_';
  69. }
  70. /* check if name is already unique */
  71. found = 0;
  72. ptr = name_root;
  73. while( ptr )
  74. {
  75. if( !strncmp( ptr->name, name, NAMESIZE ) )
  76. {
  77. found = 1;
  78. break;
  79. }
  80. ptr = ptr->next;
  81. }
  82. if( !found )
  83. return( Add_brl_name( name ) );
  84. /* name is not unique, make it unique with a single character suffix */
  85. if( namelen < NAMESIZE )
  86. char_ptr = namelen;
  87. else
  88. char_ptr = NAMESIZE - 1;
  89. i = 0;
  90. while( found && 'A'+i <= 'z' )
  91. {
  92. name[char_ptr] = 'A' + i;
  93. name[char_ptr+1] = '\0';
  94. found = 0;
  95. ptr = name_root;
  96. while( ptr )
  97. {
  98. if( !strncmp( ptr->name, name, NAMESIZE ) )
  99. {
  100. found = 1;
  101. break;
  102. }
  103. ptr = ptr->next;
  104. }
  105. i++;
  106. if( 'A'+i == '[' )
  107. i = 'a' - 'A';
  108. }
  109. if( !found )
  110. return( Add_brl_name( name ) );
  111. /* still not unique!!! Try two character suffix */
  112. char_ptr--;
  113. i = 0;
  114. j = 0;
  115. while( found && 'A'+i <= 'z' && 'A'+j <= 'z' )
  116. {
  117. name[char_ptr] = 'A'+i;
  118. name[char_ptr+1] = 'A'+j;
  119. name[char_ptr+2] = '\0';
  120. found = 0;
  121. ptr = name_root;
  122. while( ptr )
  123. {
  124. if( !strncmp( ptr->name, name, NAMESIZE ) )
  125. {
  126. found = 1;
  127. break;
  128. }
  129. ptr = ptr->next;
  130. }
  131. j++;
  132. if( 'A'+j == '[' )
  133. j = 'a' - 'A';
  134. if( 'A'+j > 'z' )
  135. {
  136. j = 0;
  137. i++;
  138. }
  139. if( 'A'+i == '[' )
  140. i = 'a' - 'A';
  141. }
  142. if( !found )
  143. {
  144. /* not likely */
  145. rt_log( "Could not make name unique: (%s)\n", name );
  146. rt_bomb( "Make_unique_brl_name: failed\n" );
  147. return( (char *)NULL ); /* make the compilers happy */
  148. }
  149. else
  150. return( Add_brl_name( name ) );
  151. }
  152. void
  153. Skip_field()
  154. {
  155. int done=0;
  156. int lencard;
  157. if( card[counter] == eof ) /* This is an empty field */
  158. {
  159. counter++;
  160. return;
  161. }
  162. else if( card[counter] == eor ) /* Up against the end of record */
  163. return;
  164. if( card[72] == 'P' )
  165. lencard = PARAMLEN;
  166. else
  167. lencard = CARDLEN;
  168. if( counter >= lencard )
  169. Readrec( ++currec );
  170. while( !done )
  171. {
  172. while( card[counter++] != eof && card[counter] != eor &&
  173. counter <= lencard );
  174. if( counter > lencard && card[counter] != eor && card[counter] != eof )
  175. Readrec( ++currec );
  176. else
  177. done = 1;
  178. }
  179. if( card[counter] == eor )
  180. counter--;
  181. }
  182. void
  183. Get_name( entityno , skip )
  184. int entityno;
  185. int skip;
  186. {
  187. int sol_num;
  188. int i,j,k;
  189. int no_of_assoc=0;
  190. int no_of_props=0;
  191. int name_de=0;
  192. char *name;
  193. if( dir[entityno]->param <= pstart )
  194. {
  195. rt_log( "Illegal parameter pointer for entity D%07d (%s)\n" ,
  196. dir[entityno]->direct , dir[entityno]->name );
  197. return;
  198. }
  199. Readrec( dir[entityno]->param );
  200. Readint( &sol_num , "" );
  201. for( i=0 ; i<skip ; i++ )
  202. Skip_field();
  203. /* skip over the associativities */
  204. Readint( &no_of_assoc , "" );
  205. for( k=0 ; k<no_of_assoc ; k++ )
  206. Readint( &j , "" );
  207. /* get property entity DE's */
  208. Readint( &no_of_props , "" );
  209. for( k=0 ; k<no_of_props ; k++ )
  210. {
  211. j = 0;
  212. Readint( &j , "" );
  213. if( dir[(j-1)/2]->type == 406 &&
  214. dir[(j-1)/2]->form == 15 )
  215. {
  216. /* this is a name */
  217. name_de = j;
  218. break;
  219. }
  220. }
  221. if( !name_de )
  222. return;
  223. Readrec( dir[(name_de-1)/2]->param );
  224. Readint( &sol_num , "" );
  225. if( sol_num != 406 )
  226. {
  227. /* this is not a property entity */
  228. rt_log( "Check_names: entity at DE %d is not a property entity\n" , name_de );
  229. return;
  230. }
  231. Readint( &i , "" );
  232. if( i != 1 )
  233. {
  234. rt_log( "Bad property entity, form 15 (name) should have only one value, not %d\n" , i );
  235. return;
  236. }
  237. Readname( &name , "" );
  238. dir[entityno]->name = Make_unique_brl_name( name );
  239. rt_free( (char *)name, "Get_name: name" );
  240. }
  241. void
  242. Get_drawing_name( entityno )
  243. int entityno;
  244. {
  245. int entity_type;
  246. int no_of_views;
  247. int no_of_annot;
  248. int no_of_assoc;
  249. int no_of_props;
  250. int i,j,k;
  251. int name_de=0;
  252. char *name;
  253. if( dir[entityno]->param <= pstart )
  254. {
  255. rt_log( "Illegal parameter pointer for entity D%07d (%s)\n" ,
  256. dir[entityno]->direct , dir[entityno]->name );
  257. return;
  258. }
  259. Readrec( dir[entityno]->param );
  260. Readint( &entity_type , "" );
  261. if( entity_type != 404 )
  262. {
  263. rt_log( "Get_drawing_name: entity at P%07d (type %d) is not a drawing entity\n" , dir[entityno]->param , entity_type );
  264. return;
  265. }
  266. Readint( &no_of_views , "" );
  267. for( i=0 ; i<no_of_views ; i++ )
  268. {
  269. for( j=0 ; j<3 ; j++ )
  270. Skip_field();
  271. }
  272. Readint( &no_of_annot , "" );
  273. for( i=0 ; i<no_of_annot ; i++ )
  274. Skip_field();
  275. /* skip over the associativities */
  276. Readint( &no_of_assoc , "" );
  277. for( k=0 ; k<no_of_assoc ; k++ )
  278. Readint( &j , "" );
  279. /* get property entity DE's */
  280. Readint( &no_of_props , "" );
  281. for( k=0 ; k<no_of_props ; k++ )
  282. {
  283. j = 0;
  284. Readint( &j , "" );
  285. if( dir[(j-1)/2]->type == 406 &&
  286. dir[(j-1)/2]->form == 15 )
  287. {
  288. /* this is a name */
  289. name_de = j;
  290. break;
  291. }
  292. }
  293. if( !name_de )
  294. return;
  295. Readrec( dir[(name_de-1)/2]->param );
  296. Readint( &entity_type , "" );
  297. if( entity_type != 406 )
  298. {
  299. /* this is not a property entity */
  300. rt_log( "Get_drawing_name: entity at DE %d is not a property entity\n" , name_de );
  301. return;
  302. }
  303. Readint( &i , "" );
  304. if( i != 1 )
  305. {
  306. rt_log( "Bad property entity, form 15 (name) should have only one value, not %d\n" , i );
  307. return;
  308. }
  309. Readname( &name , "" );
  310. dir[entityno]->name = Make_unique_brl_name( name );
  311. rt_free( (char *)name, "Get_name: name" );
  312. }
  313. void
  314. Get_csg_name( entityno )
  315. int entityno;
  316. {
  317. int sol_num;
  318. int i,j,k;
  319. int num;
  320. int skip;
  321. int no_of_assoc=0;
  322. int no_of_props=0;
  323. int name_de=0;
  324. char *name;
  325. if( dir[entityno]->param <= pstart )
  326. {
  327. rt_log( "Illegal parameter pointer for entity D%07d (%s)\n" ,
  328. dir[entityno]->direct , dir[entityno]->name );
  329. return;
  330. }
  331. Readrec( dir[entityno]->param );
  332. Readint( &sol_num , "" );
  333. Readint( &num , "" );
  334. if( sol_num == 180 )
  335. skip = num;
  336. else if( sol_num == 184 )
  337. skip = 2*num;
  338. else
  339. {
  340. rt_log( "Get_csg_name: entity (type %d), not a CSG\n" , sol_num );
  341. return;
  342. }
  343. for( i=0 ; i<skip ; i++ )
  344. Skip_field();
  345. /* skip over the associativities */
  346. Readint( &no_of_assoc , "" );
  347. for( k=0 ; k<no_of_assoc ; k++ )
  348. Readint( &j , "" );
  349. /* get property entity DE's */
  350. Readint( &no_of_props , "" );
  351. for( k=0 ; k<no_of_props ; k++ )
  352. {
  353. j = 0;
  354. Readint( &j , "" );
  355. if( dir[(j-1)/2]->type == 406 &&
  356. dir[(j-1)/2]->form == 15 )
  357. {
  358. /* this is a name */
  359. name_de = j;
  360. break;
  361. }
  362. }
  363. if( !name_de )
  364. return;
  365. Readrec( dir[(name_de-1)/2]->param );
  366. Readint( &sol_num , "" );
  367. if( sol_num != 406 )
  368. {
  369. /* this is not a property entity */
  370. rt_log( "Check_names: entity at DE %d is not a property entity\n" , name_de );
  371. return;
  372. }
  373. Readint( &i , "" );
  374. if( i != 1 )
  375. {
  376. rt_log( "Bad property entity, form 15 (name) should have only one value, not %d\n" , i );
  377. return;
  378. }
  379. Readname( &name , "" );
  380. dir[entityno]->name = Make_unique_brl_name( name );
  381. rt_free( (char *)name, "Get_name: name" );
  382. }
  383. void
  384. Get_brep_name( entityno )
  385. int entityno;
  386. {
  387. int sol_num;
  388. int i,j,k;
  389. int num;
  390. int skip;
  391. int no_of_assoc=0;
  392. int no_of_props=0;
  393. int name_de=0;
  394. char *name;
  395. if( dir[entityno]->param <= pstart )
  396. {
  397. rt_log( "Illegal parameter pointer for entity D%07d (%s)\n" ,
  398. dir[entityno]->direct , dir[entityno]->name );
  399. return;
  400. }
  401. Readrec( dir[entityno]->param );
  402. Readint( &sol_num , "" );
  403. if( sol_num != 186 )
  404. {
  405. rt_log( "Get_brep_name: Entity (type %d) is not a BREP\n" , sol_num );
  406. return;
  407. }
  408. Skip_field();
  409. Skip_field();
  410. Readint( &num , "" );
  411. skip = 2*num;
  412. for( i=0 ; i<skip ; i++ )
  413. Skip_field();
  414. /* skip over the associativities */
  415. Readint( &no_of_assoc , "" );
  416. for( k=0 ; k<no_of_assoc ; k++ )
  417. Readint( &j , "" );
  418. /* get property entity DE's */
  419. Readint( &no_of_props , "" );
  420. for( k=0 ; k<no_of_props ; k++ )
  421. {
  422. j = 0;
  423. Readint( &j , "" );
  424. if( dir[(j-1)/2]->type == 406 &&
  425. dir[(j-1)/2]->form == 15 )
  426. {
  427. /* this is a name */
  428. name_de = j;
  429. break;
  430. }
  431. }
  432. if( !name_de )
  433. return;
  434. Readrec( dir[(name_de-1)/2]->param );
  435. Readint( &sol_num , "" );
  436. if( sol_num != 406 )
  437. {
  438. /* this is not a property entity */
  439. rt_log( "Check_names: entity at DE %d is not a property entity\n" , name_de );
  440. return;
  441. }
  442. Readint( &i , "" );
  443. if( i != 1 )
  444. {
  445. rt_log( "Bad property entity, form 15 (name) should have only one value, not %d\n" , i );
  446. return;
  447. }
  448. Readname( &name , "" );
  449. dir[entityno]->name = Make_unique_brl_name( name );
  450. rt_free( (char *)name, "Get_name: name" );
  451. }
  452. void
  453. Get_subfig_name( entityno )
  454. int entityno;
  455. {
  456. int i;
  457. int def_de;
  458. int def_index;
  459. int entity_type;
  460. char *name;
  461. if( entityno >= totentities )
  462. rt_bomb( "Get_subfig_name: entityno too big!!\n" );
  463. if( dir[entityno]->type != 308 )
  464. {
  465. rt_log( "Get_subfig_name called with entity type %s, should be Subfigure Definition\n",
  466. iges_type( dir[entityno]->type ) );
  467. rt_bomb( "Get_subfig_name: bad type\n" );
  468. }
  469. if( dir[entityno]->param <= pstart )
  470. {
  471. rt_log( "Illegal parameter pointer for entity D%07d (%s)\n" ,
  472. dir[entityno]->direct , dir[entityno]->name );
  473. rt_bomb( "Get_subfig_name: Bad entity\n" );
  474. }
  475. Readrec( dir[entityno]->param );
  476. Readint( &entity_type, "" );
  477. if( entity_type != 308 )
  478. {
  479. rt_log( "Get_subfig_name: Read entity type %s, should be Subfigure Definition\n",
  480. iges_type( dir[entityno]->type ) );
  481. rt_bomb( "Get_subfig_name: bad type\n" );
  482. }
  483. Readint( &i, "" ); /* ignore depth */
  484. Readname( &name, "" ); /* get subfigure name */
  485. dir[entityno]->name = Add_brl_name( name );
  486. rt_free( (char *)name, "Get_name: name" );
  487. }
  488. void
  489. Check_names()
  490. {
  491. int i;
  492. rt_log( "Looking for Name Entities...\n" );
  493. for( i=0 ; i < totentities ; i++ )
  494. {
  495. switch( dir[i]->type )
  496. {
  497. case 152:
  498. Get_name( i , 13 );
  499. break;
  500. case 150:
  501. case 168:
  502. Get_name( i , 12 );
  503. break;
  504. case 156:
  505. Get_name( i , 9 );
  506. break;
  507. case 154:
  508. case 160:
  509. case 162:
  510. Get_name( i , 8 );
  511. break;
  512. case 164:
  513. Get_name( i , 5 );
  514. break;
  515. case 158:
  516. Get_name( i , 4 );
  517. break;
  518. case 180:
  519. case 184:
  520. Get_csg_name( i );
  521. break;
  522. case 186:
  523. Get_brep_name( i );
  524. break;
  525. case 308:
  526. Get_subfig_name( i );
  527. break;
  528. case 404:
  529. Get_drawing_name( i );
  530. break;
  531. case 410:
  532. if( dir[i]->form == 0 )
  533. Get_name( i , 8 );
  534. else if( dir[i]->form == 1 )
  535. Get_name( i , 22 );
  536. break;
  537. case 430:
  538. Get_name( i , 1 );
  539. break;
  540. default:
  541. break;
  542. }
  543. }
  544. rt_log( "Assigning names to entities without names...\n" );
  545. for( i=0 ; i < totentities ; i++ )
  546. {
  547. char tmp_name[NAMESIZE + 1];
  548. if( dir[i]->name == (char *)NULL )
  549. {
  550. switch( dir[i]->type )
  551. {
  552. case 150:
  553. sprintf( tmp_name , "block.%d" , i );
  554. dir[i]->name = Make_unique_brl_name( tmp_name );
  555. break;
  556. case 152:
  557. sprintf( tmp_name , "wedge.%d" , i );
  558. dir[i]->name = Make_unique_brl_name( tmp_name );
  559. break;
  560. case 154:
  561. sprintf( tmp_name , "cyl.%d" , i );
  562. dir[i]->name = Make_unique_brl_name( tmp_name );
  563. break;
  564. case 156:
  565. sprintf( tmp_name , "cone.%d" , i );
  566. dir[i]->name = Make_unique_brl_name( tmp_name );
  567. break;
  568. case 158:
  569. sprintf( tmp_name , "sphere.%d" , i );
  570. dir[i]->name = Make_unique_brl_name( tmp_name );
  571. break;
  572. case 160:
  573. sprintf( tmp_name , "torus.%d" , i );
  574. dir[i]->name = Make_unique_brl_name( tmp_name );
  575. break;
  576. case 162:
  577. sprintf( tmp_name , "revolution.%d" , i );
  578. dir[i]->name = Make_unique_brl_name( tmp_name );
  579. break;
  580. case 164:
  581. sprintf( tmp_name , "extrusion.%d" , i );
  582. dir[i]->name = Make_unique_brl_name( tmp_name );
  583. break;
  584. case 168:
  585. sprintf( tmp_name , "ell.%d" , i );
  586. dir[i]->name = Make_unique_brl_name( tmp_name );
  587. break;
  588. case 180:
  589. sprintf( tmp_name , "region.%d" , i );
  590. dir[i]->name = Make_unique_brl_name( tmp_name );
  591. break;
  592. case 184:
  593. sprintf( tmp_name , "group.%d" , i );
  594. dir[i]->name = Make_unique_brl_name( tmp_name );
  595. break;
  596. case 186:
  597. sprintf( tmp_name , "brep.%d" , i );
  598. dir[i]->name = Make_unique_brl_name( tmp_name );
  599. break;
  600. case 404:
  601. sprintf( tmp_name , "drawing.%d" , i );
  602. dir[i]->name = Make_unique_brl_name( tmp_name );
  603. break;
  604. case 410:
  605. sprintf( tmp_name , "view.%d" , i );
  606. dir[i]->name = Make_unique_brl_name( tmp_name );
  607. break;
  608. case 430:
  609. sprintf( tmp_name , "inst.%d" , i );
  610. dir[i]->name = Make_unique_brl_name( tmp_name );
  611. break;
  612. }
  613. }
  614. }
  615. }