Branch data Line data Source code
1 : : #include "iGeom.h"
2 : : #include <vector>
3 : : #include <iostream>
4 : : #include <stdio.h>
5 : : #include <fstream>
6 : : #include <assert.h>
7 : :
8 : : // helper macro for igeom
9 : : #define ASSERT(A) if (!(A)) failed(#A,__FILE__,__LINE__)
10 : : #define CHECK( STR ) if (err != iBase_SUCCESS) return Print_Error( STR, err, geom, __FILE__, __LINE__ )
11 : : int Tag_Body( iGeom_Instance geom, const iBase_TagHandle tag, const std::string id, const iBase_EntityHandle body);
12 : : int Tag_Get( iGeom_Instance geom, const iBase_TagHandle tag, const iBase_EntityHandle body);
13 : : bool Print_Error( const char* desc,
14 : : int err,
15 : : iGeom_Instance geom,
16 : : const char* file,
17 : : int line );
18 : 1 : int main(){
19 : : int err;
20 : : iGeom_Instance geom;
21 : 1 : double dSide = 10.0, dHeight = 10.0, dRad = 3.0;
22 : 1 : iBase_EntityHandle assm = NULL, cyl = NULL, tmp_cyl = NULL, tmp_new = NULL;
23 [ + - ]: 1 : std::string geomFile = "test.occ";
24 : :
25 : :
26 [ + - ]: 1 : iGeom_newGeom( 0, &geom, &err, 0 );
27 : :
28 : 1 : iBase_TagHandle pin_tag = NULL, name_tag = NULL;
29 : 1 : char* tag_name_pin = (char*)"PIN";
30 : 1 : char* tag_name = (char*)"NAME";
31 [ + - ]: 1 : iGeom_getTagHandle(geom, tag_name_pin, &pin_tag, &err, 3);
32 [ + - ]: 1 : if(err == iBase_TAG_NOT_FOUND){
33 : :
34 [ + - ]: 1 : iGeom_createTag(geom, tag_name_pin, 1, iBase_INTEGER, &pin_tag, &err, 3);
35 : :
36 : : }
37 : :
38 [ + - ]: 1 : iGeom_getTagHandle(geom, tag_name, &name_tag, &err, 4);
39 [ - + ]: 1 : if(err == iBase_TAG_NOT_FOUND){
40 : :
41 [ # # ]: 0 : iGeom_createTag(geom, tag_name, 1, iBase_INTEGER, &name_tag, &err, 4);
42 : :
43 : : }
44 : :
45 : : // creating prism
46 [ + - ][ + - ]: 1 : std::cout << "\n\n\nCreating Prism\n" << std::endl;
47 : : iGeom_createPrism(geom, dHeight, 6,
48 : : dSide, dSide,
49 [ + - ]: 1 : &assm, &err);
50 [ + - ][ + - ]: 2 : std::string one = "1";
51 [ + - ][ + - ]: 1 : Tag_Body(geom, pin_tag, one, assm);
[ + - ]
52 [ + - ]: 1 : Tag_Get (geom, pin_tag, assm);
53 [ + - ]: 1 : std::cout << "name tag: ";
54 [ + - ][ + - ]: 2 : std::string a = "a";
55 [ + - ][ + - ]: 1 : Tag_Body(geom, name_tag, a, assm);
[ + - ]
56 [ + - ]: 1 : Tag_Get (geom, name_tag, assm);
57 : :
58 [ + - ][ + - ]: 1 : std::cout << "\n\n\nCreating Cylinder\n" << std::endl;
59 : : // create cylinder
60 [ + - ]: 1 : iGeom_createCylinder(geom, dHeight, dRad, dRad, &cyl, &err);
61 [ + - ][ + - ]: 2 : std::string two = "2";
62 [ + - ][ + - ]: 1 : Tag_Body(geom, pin_tag, two, cyl);
[ + - ]
63 [ + - ]: 1 : Tag_Get(geom, pin_tag, cyl);
64 : :
65 [ + - ]: 1 : std::cout << "name tag: ";
66 [ + - ][ + - ]: 2 : std::string b = "b";
67 [ + - ][ + - ]: 1 : Tag_Body(geom, name_tag, b, cyl);
[ + - ]
68 [ + - ]: 1 : Tag_Get (geom, name_tag, cyl);
69 : :
70 : : // Copy
71 [ + - ]: 1 : iGeom_copyEnt(geom, cyl, &tmp_cyl, &err);
72 [ + - ][ + - ]: 1 : std::cout << "\n\n After copy operation\n" << std::endl;
73 [ + - ]: 1 : Tag_Get(geom, pin_tag, tmp_cyl);
74 [ + - ][ + - ]: 1 : std::cout << "\ngetting name tag " << std::endl;
75 [ + - ]: 1 : Tag_Get(geom, name_tag, tmp_cyl);
76 : :
77 : : // Substract
78 [ + - ]: 1 : iGeom_subtractEnts(geom, assm, tmp_cyl, &tmp_new, &err);
79 [ + - ][ + - ]: 1 : std::cout << "\n\n After subtract operation\n" << std::endl;
80 [ + - ]: 1 : Tag_Get(geom, pin_tag, tmp_new);
81 [ + - ][ + - ]: 1 : std::cout << "\n getting name tag " << std::endl;
82 [ + - ]: 1 : Tag_Get(geom, name_tag, tmp_new);
83 : :
84 : : // save
85 [ + - ][ + - ]: 1 : iGeom_save(geom, geomFile.c_str(), NULL, &err, geomFile.length() , 0);
[ + - ]
86 : :
87 : : //check that the two single volume bodys' attributes are exported as SINGLELUMP%
88 [ + - ][ + - ]: 2 : std::string search = "SINGLELUMP%";
89 [ + - ][ + - ]: 2 : std::ifstream Myfile;
90 [ + - ][ + - ]: 1 : Myfile.open (geomFile.c_str());
91 : 1 : int found = 0;
92 [ + - ][ + - ]: 2 : std::string line;
93 : : size_t offset;
94 [ + - ][ + - ]: 1 : if(Myfile.is_open())
95 : : {
96 [ + - ][ + + ]: 707 : while(!Myfile.eof())
97 : : {
98 [ + - ]: 706 : getline(Myfile,line);
99 [ + - ][ + + ]: 706 : if ((offset = line.find(search, 0)) != std::string::npos)
100 : 4 : found ++;
101 : : }
102 [ + - ]: 1 : Myfile.close();
103 : : }
104 : :
105 [ - + ]: 1 : assert (found == 4);
106 : :
107 [ + - ]: 1 : return 0;
108 : : }
109 : :
110 : :
111 : 4 : int Tag_Body( iGeom_Instance geom, const iBase_TagHandle tag, const std::string id, const iBase_EntityHandle body)
112 : : //---------------------------------------------------------------------------
113 : : //Function: Tag body with pin number
114 : : //Input: none
115 : : //Output: none
116 : : //---------------------------------------------------------------------------
117 : : {
118 : 4 : int err = 0;
119 : :
120 [ + - ][ + - ]: 4 : iGeom_setData(geom, body, tag, id.c_str(), id.size(), &err);
[ + - ]
121 [ + - ][ + - ]: 4 : std::cout<<"\nset pin tag - " << id<< " on " << body << std::endl;
[ + - ][ + - ]
[ + - ]
122 : 4 : return 0;
123 : : }
124 : :
125 : :
126 : :
127 : 8 : int Tag_Get(iGeom_Instance geom, const iBase_TagHandle tag, const iBase_EntityHandle body)
128 : : //---------------------------------------------------------------------------
129 : : //Function: Tag get
130 : : //Input: none
131 : : //Output: none
132 : : //---------------------------------------------------------------------------
133 : : {
134 : 8 : int err = 0, bytes;
135 [ + - ]: 8 : iGeom_getTagSizeBytes( geom, tag, &bytes, &err );
136 [ - + ][ # # ]: 8 : CHECK( "Can't get size" );
137 : :
138 [ + - ]: 8 : std::vector<char> data(bytes);
139 : :
140 : : //just check if pin tag exist, IT'S NOT USED IN THIS FUNCTION
141 : 8 : iBase_TagHandle pin1 = NULL;
142 : 8 : char* p = (char*)"PIN";
143 : :
144 [ + - ]: 8 : iGeom_getTagHandle(geom, p, &pin1, &err, 3);
145 [ - + ][ # # ]: 8 : CHECK( "PIN tag doesn't exist" );
146 : :
147 [ + - ]: 8 : void* ptr = &data[0];
148 : 8 : int junk1 = bytes, junk2;
149 [ + - ]: 8 : iGeom_getData( geom, body, tag, (void**)&ptr, &junk1, &junk2, &err );
150 [ + + ][ + - ]: 8 : CHECK( "failed to getData for tag" );
151 [ + - ][ + - ]: 6 : std::cout << "Able to get this tag: "<<*(void**)ptr << " on " << body <<std::endl;
[ + - ][ + - ]
[ + - ]
152 [ + - ]: 8 : return 0;
153 : : }
154 : :
155 : :
156 : :
157 : : // print error function definition (iGeom)
158 : 2 : bool Print_Error( const char* desc,
159 : : int err,
160 : : iGeom_Instance geom,
161 : : const char* file,
162 : : int line )
163 : : {
164 : : char buffer[1024];
165 [ + - ]: 2 : iGeom_getDescription( geom, buffer, sizeof(buffer) );
166 : 2 : buffer[sizeof(buffer)-1] = '\0';
167 : :
168 [ + - ][ + - ]: 2 : std::cerr << "ERROR: " << desc << std::endl
[ + - ]
169 [ + - ][ + - ]: 2 : << " Error code: " << err << std::endl
[ + - ]
170 [ + - ][ + - ]: 2 : << " Error desc: " << buffer << std::endl
[ + - ]
171 [ + - ][ + - ]: 2 : << " At : " << file << ':' << line << std::endl
[ + - ][ + - ]
172 [ + - ]: 2 : ;
173 : :
174 : 2 : return false; // must always return false or CHECK macro will break
175 [ + - ][ + - ]: 4 : }
|