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