1 #ifdef OCCGEOMETRY
2
3 #include <mystdlib.h>
4 #include <myadt.hpp>
5 #include <linalg.hpp>
6 #include <csg.hpp>
7 #include <occgeom.hpp>
8
9
10 #include <inctcl.hpp>
11 #include <visual.hpp>
12
13 #include <meshing.hpp>
14 #include "../meshing/bcfunctions.hpp"
15
16 #include "vsocc.hpp"
17
18 // __declspec(dllimport) void AutoColourBcProps(Mesh & mesh, const char *bccolourfile);
19 // __declspec(dllimport) void GetFaceColours(Mesh & mesh, NgArray<Vec3d> & face_colours);
20 // __declspec(dllimport) bool ColourMatch(Vec3d col1, Vec3d col2, double eps = 2.5e-05);
21
22 extern "C" int Ng_occ_Init (Tcl_Interp * interp);
23
24
25
26 namespace netgen
27 {
28 extern DLL_HEADER shared_ptr<NetgenGeometry> ng_geometry;
29 extern DLL_HEADER shared_ptr<Mesh> mesh;
30 extern DLL_HEADER MeshingParameters mparam;
31 extern DLL_HEADER OCCParameters occparam;
32
33 char * err_needsoccgeometry = (char*) "This operation needs an OCC geometry";
34 extern char * err_needsmesh;
35 extern char * err_jobrunning;
36
37
38
39
40 class OCCGeometryRegister : public GeometryRegister
41 {
42 public:
43 virtual NetgenGeometry * Load (string filename) const;
44 virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const;
45
SetParameters(Tcl_Interp * interp)46 virtual void SetParameters (Tcl_Interp * interp)
47 {
48 occparam.resthminedgelen =
49 atof (Tcl_GetVar (interp, "::stloptions.resthminedgelen", 0));
50 occparam.resthminedgelenenable =
51 atoi (Tcl_GetVar (interp, "::stloptions.resthminedgelenenable", 0));
52 if(auto geo = dynamic_pointer_cast<OCCGeometry>(ng_geometry); geo)
53 geo->SetOCCParameters(occparam);
54 }
55 };
56
57
58
59
Ng_SetOCCVisParameters(ClientData clientData,Tcl_Interp * interp,int argc,tcl_const char * argv[])60 int Ng_SetOCCVisParameters (ClientData clientData,
61 Tcl_Interp * interp,
62 int argc, tcl_const char *argv[])
63 {
64 #ifdef OCCGEOMETRY
65 int showvolume;
66 OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.get());
67
68 showvolume = atoi (Tcl_GetVar (interp, "::occoptions.showvolumenr", 0));
69
70 if (occgeometry)
71 if (showvolume != vispar.occshowvolumenr)
72 {
73 if (showvolume < 0 || showvolume > occgeometry->NrSolids())
74 {
75 char buf[20];
76 sprintf (buf, "%5i", vispar.occshowvolumenr);
77 Tcl_SetVar (interp, "::occoptions.showvolumenr", buf, 0);
78 }
79 else
80 {
81 vispar.occshowvolumenr = showvolume;
82 if (occgeometry)
83 occgeometry -> changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
84 }
85 }
86
87 int temp;
88
89 temp = atoi (Tcl_GetVar (interp, "::occoptions.visproblemfaces", 0));
90
91 if ((bool) temp != vispar.occvisproblemfaces)
92 {
93 vispar.occvisproblemfaces = temp;
94 if (occgeometry)
95 occgeometry -> changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
96 }
97
98 vispar.occshowsurfaces = atoi (Tcl_GetVar (interp, "::occoptions.showsurfaces", 0));
99 vispar.occshowedges = atoi (Tcl_GetVar (interp, "::occoptions.showedges", 0));
100 vispar.occzoomtohighlightedentity = atoi (Tcl_GetVar (interp, "::occoptions.zoomtohighlightedentity", 0));
101 vispar.occdeflection = pow(10.0,-1-atof (Tcl_GetVar (interp, "::occoptions.deflection", 0)));
102
103 #endif
104
105
106
107
108
109 #ifdef ACIS
110 vispar.ACISshowfaces = atoi (Tcl_GetVar (interp, "::occoptions.showsurfaces", 0));
111 vispar.ACISshowedges = atoi (Tcl_GetVar (interp, "::occoptions.showedges", 0));
112 vispar.ACISshowsolidnr = atoi (Tcl_GetVar (interp, "::occoptions.showsolidnr", 0));
113 vispar.ACISshowsolidnr2 = atoi (Tcl_GetVar (interp, "::occoptions.showsolidnr2", 0));
114
115 #endif
116
117
118
119 return TCL_OK;
120 }
121
122
123
124
Ng_GetOCCData(ClientData clientData,Tcl_Interp * interp,int argc,tcl_const char * argv[])125 int Ng_GetOCCData (ClientData clientData,
126 Tcl_Interp * interp,
127 int argc, tcl_const char *argv[])
128 {
129 #ifdef OCCGEOMETRY
130 OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.get());
131
132 // static char buf[1000];
133 // buf[0] = 0;
134 stringstream str;
135
136 if (argc >= 2)
137 {
138 if (strcmp (argv[1], "getentities") == 0)
139 {
140 if (occgeometry)
141 {
142 occgeometry->GetTopologyTree(str);
143 }
144 }
145 }
146
147 Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
148
149 #endif
150 return TCL_OK;
151 }
152
153
154
Ng_OCCCommand(ClientData clientData,Tcl_Interp * interp,int argc,tcl_const char * argv[])155 int Ng_OCCCommand (ClientData clientData,
156 Tcl_Interp * interp,
157 int argc, tcl_const char *argv[])
158 {
159 #ifdef OCCGEOMETRY
160 OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.get());
161
162 stringstream str;
163 if (argc >= 2)
164 {
165 if (strcmp (argv[1], "isoccgeometryloaded") == 0)
166 {
167 if (occgeometry)
168 str << "1 " << flush;
169 else str << "0 " << flush;
170
171 Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
172 }
173 if (occgeometry)
174 {
175 if (strcmp (argv[1], "buildvisualizationmesh") == 0)
176 {
177 occgeometry->BuildVisualizationMesh(vispar.occdeflection);
178 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
179 }
180 if (strcmp (argv[1], "mesherror") == 0)
181 {
182 if (occgeometry->ErrorInSurfaceMeshing())
183 str << 1;
184 else
185 str << 0;
186 }
187 if (strcmp (argv[1], "sewfaces") == 0)
188 {
189 cout << "Before operation:" << endl;
190 occgeometry->PrintNrShapes();
191 occgeometry->SewFaces();
192 occgeometry->BuildFMap();
193 cout << endl << "After operation:" << endl;
194 occgeometry->PrintNrShapes();
195 occgeometry->BuildVisualizationMesh(vispar.occdeflection);
196 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
197 }
198 if (strcmp (argv[1], "makesolid") == 0)
199 {
200 cout << "Before operation:" << endl;
201 occgeometry->PrintNrShapes();
202 occgeometry->MakeSolid();
203 occgeometry->BuildFMap();
204 cout << endl << "After operation:" << endl;
205 occgeometry->PrintNrShapes();
206 occgeometry->BuildVisualizationMesh(vispar.occdeflection);
207 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
208 }
209 if (strcmp (argv[1], "upgradetopology") == 0)
210 {
211 cout << "Before operation:" << endl;
212 occgeometry->PrintNrShapes();
213 occgeometry->SewFaces();
214 occgeometry->MakeSolid();
215 occgeometry->BuildFMap();
216 cout << endl << "After operation:" << endl;
217 occgeometry->PrintNrShapes();
218 occgeometry->BuildVisualizationMesh(vispar.occdeflection);
219 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
220 }
221 if (strcmp (argv[1], "shapehealing") == 0)
222 {
223 occgeometry->tolerance =
224 atof (Tcl_GetVar (interp, "::occoptions.tolerance", 0));
225 occgeometry->fixsmalledges =
226 atoi (Tcl_GetVar (interp, "::occoptions.fixsmalledges", 0));
227 occgeometry->fixspotstripfaces =
228 atoi (Tcl_GetVar (interp, "::occoptions.fixspotstripfaces", 0));
229 occgeometry->sewfaces =
230 atoi (Tcl_GetVar (interp, "::occoptions.sewfaces", 0));
231 occgeometry->makesolids =
232 atoi (Tcl_GetVar (interp, "::occoptions.makesolids", 0));
233 occgeometry->splitpartitions =
234 atoi (Tcl_GetVar (interp, "::occoptions.splitpartitions", 0));
235
236 // cout << "Before operation:" << endl;
237 // occgeometry->PrintNrShapes();
238 occgeometry->HealGeometry();
239 occgeometry->BuildFMap();
240 // cout << endl << "After operation:" << endl;
241 // occgeometry->PrintNrShapes();
242 occgeometry->BuildVisualizationMesh(vispar.occdeflection);
243 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
244 }
245
246
247 if (strcmp (argv[1], "highlightentity") == 0)
248 {
249 if (strcmp (argv[2], "Face") == 0)
250 {
251 int nr = atoi (argv[3]);
252 occgeometry->LowLightAll();
253
254 occgeometry->fvispar[nr-1].Highlight();
255 if (vispar.occzoomtohighlightedentity)
256 occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
257 else
258 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
259 }
260 if (strcmp (argv[2], "Shell") == 0)
261 {
262 int nr = atoi (argv[3]);
263 occgeometry->LowLightAll();
264
265 TopExp_Explorer exp;
266 for (exp.Init (occgeometry->shmap(nr), TopAbs_FACE);
267 exp.More(); exp.Next())
268 {
269 int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
270 occgeometry->fvispar[i-1].Highlight();
271 }
272 if (vispar.occzoomtohighlightedentity)
273 occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
274 else
275 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
276 }
277 if (strcmp (argv[2], "Solid") == 0)
278 {
279 int nr = atoi (argv[3]);
280 occgeometry->LowLightAll();
281
282 TopExp_Explorer exp;
283 for (exp.Init (occgeometry->somap(nr), TopAbs_FACE);
284 exp.More(); exp.Next())
285 {
286 int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
287 occgeometry->fvispar[i-1].Highlight();
288 }
289 if (vispar.occzoomtohighlightedentity)
290 occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
291 else
292 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
293 }
294 /*
295 if (strcmp (argv[2], "CompSolid") == 0)
296 {
297 int nr = atoi (argv[3]);
298 occgeometry->LowLightAll();
299
300 TopExp_Explorer exp;
301 for (exp.Init (occgeometry->cmap(nr), TopAbs_FACE);
302 exp.More(); exp.Next())
303 {
304 int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
305 occgeometry->fvispar[i-1].Highlight();
306 }
307 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
308 }
309 */
310
311 if (strcmp (argv[2], "Edge") == 0)
312 {
313 int nr = atoi (argv[3]);
314 occgeometry->LowLightAll();
315
316 occgeometry->evispar[nr-1].Highlight();
317 if (vispar.occzoomtohighlightedentity)
318 occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
319 else
320 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
321 }
322 if (strcmp (argv[2], "Wire") == 0)
323 {
324 int nr = atoi (argv[3]);
325 occgeometry->LowLightAll();
326
327 TopExp_Explorer exp;
328 for (exp.Init (occgeometry->wmap(nr), TopAbs_EDGE);
329 exp.More(); exp.Next())
330 {
331 int i = occgeometry->emap.FindIndex (TopoDS::Edge(exp.Current()));
332 occgeometry->evispar[i-1].Highlight();
333 }
334 if (vispar.occzoomtohighlightedentity)
335 occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
336 else
337 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
338 }
339
340 if (strcmp (argv[2], "Vertex") == 0)
341 {
342 int nr = atoi (argv[3]);
343 occgeometry->LowLightAll();
344
345 occgeometry->vvispar[nr-1].Highlight();
346 if (vispar.occzoomtohighlightedentity)
347 occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
348 else
349 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
350 }
351
352 }
353
354
355
356 if (strcmp (argv[1], "show") == 0)
357 {
358 int nr = atoi (argv[3]);
359 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
360
361 if (strcmp (argv[2], "Face") == 0)
362 {
363 occgeometry->fvispar[nr-1].Show();
364 }
365 if (strcmp (argv[2], "Shell") == 0)
366 {
367 TopExp_Explorer exp;
368 for (exp.Init (occgeometry->shmap(nr), TopAbs_FACE);
369 exp.More(); exp.Next())
370 {
371 int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
372 occgeometry->fvispar[i-1].Show();
373 }
374 }
375 if (strcmp (argv[2], "Solid") == 0)
376 {
377 TopExp_Explorer exp;
378 for (exp.Init (occgeometry->somap(nr), TopAbs_FACE);
379 exp.More(); exp.Next())
380 {
381 int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
382 occgeometry->fvispar[i-1].Show();
383 }
384 }
385 if (strcmp (argv[2], "Edge") == 0)
386 {
387 occgeometry->evispar[nr-1].Show();
388 }
389 if (strcmp (argv[2], "Wire") == 0)
390 {
391 TopExp_Explorer exp;
392 for (exp.Init (occgeometry->wmap(nr), TopAbs_EDGE);
393 exp.More(); exp.Next())
394 {
395 int i = occgeometry->emap.FindIndex (TopoDS::Edge(exp.Current()));
396 occgeometry->evispar[i-1].Show();
397 }
398 }
399 }
400
401
402 if (strcmp (argv[1], "hide") == 0)
403 {
404 int nr = atoi (argv[3]);
405 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
406
407 if (strcmp (argv[2], "Face") == 0)
408 {
409 occgeometry->fvispar[nr-1].Hide();
410 }
411 if (strcmp (argv[2], "Shell") == 0)
412 {
413 TopExp_Explorer exp;
414 for (exp.Init (occgeometry->shmap(nr), TopAbs_FACE);
415 exp.More(); exp.Next())
416 {
417 int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
418 occgeometry->fvispar[i-1].Hide();
419 }
420 }
421 if (strcmp (argv[2], "Solid") == 0)
422 {
423 TopExp_Explorer exp;
424 for (exp.Init (occgeometry->somap(nr), TopAbs_FACE);
425 exp.More(); exp.Next())
426 {
427 int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
428 occgeometry->fvispar[i-1].Hide();
429 }
430 }
431 if (strcmp (argv[2], "Edge") == 0)
432 {
433 occgeometry->evispar[nr-1].Hide();
434 }
435 if (strcmp (argv[2], "Wire") == 0)
436 {
437 TopExp_Explorer exp;
438 for (exp.Init (occgeometry->wmap(nr), TopAbs_EDGE);
439 exp.More(); exp.Next())
440 {
441 int i = occgeometry->emap.FindIndex (TopoDS::Edge(exp.Current()));
442 occgeometry->evispar[i-1].Hide();
443 }
444 }
445 }
446
447
448
449 if (strcmp (argv[1], "findsmallentities") == 0)
450 {
451 stringstream str("");
452 occgeometry->CheckIrregularEntities(str);
453 Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
454 }
455 if (strcmp (argv[1], "getunmeshedfaceinfo") == 0)
456 {
457 occgeometry->GetUnmeshedFaceInfo(str);
458 Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
459 }
460 if (strcmp (argv[1], "getnotdrawablefaces") == 0)
461 {
462 occgeometry->GetNotDrawableFaces(str);
463 Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
464 }
465 if (strcmp (argv[1], "redrawstatus") == 0)
466 {
467 int i = atoi (argv[2]);
468 occgeometry->changed = i;
469 }
470 if (strcmp (argv[1], "swaporientation") == 0)
471 {
472 IGESControl_Writer writer("millimeters", 1);
473 writer.AddShape (occgeometry->shape);
474 writer.Write ("1.igs");
475 /*
476 int nr = atoi (argv[3]);
477
478 // const_cast<TopoDS_Shape&> (occgeometry->fmap(nr)).Reverse();
479
480 Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
481 rebuild->Apply(occgeometry->shape);
482
483 TopoDS_Shape sh;
484
485 // if (strcmp (argv[2], "CompSolid") == 0) sh = occgeometry->cmap(nr);
486 if (strcmp (argv[2], "Solid") == 0) sh = occgeometry->somap(nr);
487 if (strcmp (argv[2], "Shell") == 0) sh = occgeometry->shmap(nr);
488 if (strcmp (argv[2], "Face") == 0) sh = occgeometry->fmap(nr);
489 if (strcmp (argv[2], "Wire") == 0) sh = occgeometry->wmap(nr);
490 if (strcmp (argv[2], "Edge") == 0) sh = occgeometry->emap(nr);
491
492 rebuild->Replace(sh, sh.Reversed(), Standard_False);
493
494 TopoDS_Shape newshape = rebuild->Apply(occgeometry->shape, TopAbs_SHELL, 1);
495 occgeometry->shape = newshape;
496
497 occgeometry->BuildFMap();
498 occgeometry->BuildVisualizationMesh();
499 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
500 */
501 }
502 if (strcmp (argv[1], "marksingular") == 0)
503 {
504 int nr = atoi (argv[3]);
505 cout << "marking " << argv[2] << " " << nr << endl;
506 char buf[2]; buf[0] = '0'; buf[1] = 0;
507 bool sing = false;
508 if (strcmp (argv[2], "Face") == 0)
509 sing = occgeometry->fsingular[nr-1] = !occgeometry->fsingular[nr-1];
510 if (strcmp (argv[2], "Edge") == 0)
511 sing = occgeometry->esingular[nr-1] = !occgeometry->esingular[nr-1];
512 if (strcmp (argv[2], "Vertex") == 0)
513 sing = occgeometry->vsingular[nr-1] = !occgeometry->vsingular[nr-1];
514
515 if (sing) buf[0] = '1';
516
517 Tcl_SetVar (interp, "::ismarkedsingular", buf, 0);
518
519 stringstream str;
520 occgeometry->GetTopologyTree (str);
521
522 auto txt = str.str();
523 char* cstr = (char*) txt.c_str();
524
525 (*testout) << cstr << endl;
526
527 char helpstr[1000];
528
529 while (strchr (cstr, '}'))
530 {
531 strncpy (helpstr, cstr+2, strlen(strchr(cstr+2, '}')));
532 (*testout) << "***" << cstr << "***" << endl;
533 cstr = strchr (cstr, '}');
534 }
535 }
536 }
537 }
538
539 #endif
540 return TCL_OK;
541 }
542
543
544
545 #ifdef OCCGEOMETRY
546 /*
547 void OCCConstructGeometry (OCCGeometry & geom);
548
549 int Ng_OCCConstruction (ClientData clientData,
550 Tcl_Interp * interp,
551 int argc, tcl_const char *argv[])
552 {
553 if (occgeometry)
554 OCCConstructGeometry (*occgeometry);
555 return TCL_OK;
556 }
557 */
558 #endif
559
560
561
562
563 // Philippose - 30/01/2009
564 // TCL interface function for the Local Face Mesh size
565 // definition functionality
Ng_SurfaceMeshSize(ClientData clientData,Tcl_Interp * interp,int argc,tcl_const char * argv[])566 int Ng_SurfaceMeshSize (ClientData clientData,
567 Tcl_Interp * interp,
568 int argc, tcl_const char *argv[])
569 {
570 #ifdef OCCGEOMETRY
571
572 static char buf[100];
573
574 if (argc < 2)
575 {
576 Tcl_SetResult (interp, (char *)"Ng_SurfaceMeshSize needs arguments", TCL_STATIC);
577 return TCL_ERROR;
578 }
579
580 OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.get());
581 if (!occgeometry)
582 {
583 Tcl_SetResult (interp, (char *)"Ng_SurfaceMeshSize currently supports only OCC (STEP/IGES) Files", TCL_STATIC);
584 return TCL_ERROR;
585 }
586
587 // Update the face mesh sizes to reflect the global maximum mesh size
588 for(int i = 1; i <= occgeometry->NrFaces(); i++)
589 {
590 if(!occgeometry->GetFaceMaxhModified(i))
591 {
592 occgeometry->SetFaceMaxH(i, mparam.maxh, mparam);
593 }
594 }
595
596 if (strcmp (argv[1], "setsurfms") == 0)
597 {
598 int facenr = atoi (argv[2]);
599 double surfms = atof (argv[3]);
600 if (occgeometry && facenr >= 1 && facenr <= occgeometry->NrFaces())
601 occgeometry->SetFaceMaxH(facenr, surfms, mparam);
602
603 }
604
605 if (strcmp (argv[1], "setall") == 0)
606 {
607 double surfms = atof (argv[2]);
608 if (occgeometry)
609 {
610 int nrFaces = occgeometry->NrFaces();
611 for (int i = 1; i <= nrFaces; i++)
612 occgeometry->SetFaceMaxH(i, surfms, mparam);
613 }
614 }
615
616 if (strcmp (argv[1], "getsurfms") == 0)
617 {
618 int facenr = atoi (argv[2]);
619 if (occgeometry && facenr >= 1 && facenr <= occgeometry->NrFaces())
620 {
621 sprintf (buf, "%5.2f", occgeometry->GetFaceMaxH(facenr));
622 }
623 else
624 {
625 sprintf (buf, "%5.2f", mparam.maxh);
626 }
627 Tcl_SetResult (interp, buf, TCL_STATIC);
628 }
629
630 if (strcmp (argv[1], "getactive") == 0)
631 {
632 sprintf (buf, "%d", occgeometry->SelectedFace());
633 Tcl_SetResult (interp, buf, TCL_STATIC);
634 }
635
636 if (strcmp (argv[1], "setactive") == 0)
637 {
638 int facenr = atoi (argv[2]);
639 if (occgeometry && facenr >= 1 && facenr <= occgeometry->NrFaces())
640 {
641 occgeometry->SetSelectedFace (facenr);
642
643 occgeometry->LowLightAll();
644 occgeometry->fvispar[facenr-1].Highlight();
645 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
646 }
647 }
648
649 if (strcmp (argv[1], "getnfd") == 0)
650 {
651 if (occgeometry)
652 sprintf (buf, "%d", occgeometry->NrFaces());
653 else
654 sprintf (buf, "0");
655 Tcl_SetResult (interp, buf, TCL_STATIC);
656 }
657 return TCL_OK;
658 #else // No OCCGEOMETRY
659
660 Tcl_SetResult (interp, (char *)"Ng_SurfaceMeshSize currently supports only OCC (STEP/IGES) Files", TCL_STATIC);
661 return TCL_ERROR;
662
663 #endif // OCCGEOMETRY
664 }
665
666
667
668 // Philippose - 25/07/2010
669 // TCL interface function for extracting and eventually
670 // setting or editing the current colours present in the mesh
Ng_CurrentFaceColours(ClientData clientData,Tcl_Interp * interp,int argc,tcl_const char * argv[])671 int Ng_CurrentFaceColours (ClientData clientData,
672 Tcl_Interp * interp,
673 int argc, tcl_const char *argv[])
674 {
675 if(argc < 1)
676 {
677 Tcl_SetResult (interp, (char *)"Ng_GetCurrentFaceColours needs arguments", TCL_STATIC);
678 return TCL_ERROR;
679 }
680
681 if(!mesh)
682 {
683 Tcl_SetResult (interp, (char *)"Ng_GetCurrentFaceColours: Valid netgen mesh required...please mesh the Geometry first", TCL_STATIC);
684 return TCL_ERROR;
685 }
686
687 if(strcmp(argv[1], "getcolours") == 0)
688 {
689 stringstream outVar;
690 NgArray<Vec3d> face_colours;
691 GetFaceColours(*mesh, face_colours);
692
693 for(int i = 0; i < face_colours.Size();i++)
694 {
695 outVar << "{ " << face_colours[i].X(1)
696 << " " << face_colours[i].X(2)
697 << " " << face_colours[i].X(3)
698 << " } ";
699 }
700
701 tcl_const char * valuevar = argv[2];
702 Tcl_SetVar (interp, valuevar, (char*)outVar.str().c_str(), 0);
703 }
704
705 if(strcmp(argv[1], "showalso") == 0)
706 {
707 NgArray<Vec3d> face_colours;
708 GetFaceColours(*mesh,face_colours);
709
710 int colourind = atoi (argv[2]);
711
712 for(int i = 1; i <= mesh->GetNFD(); i++)
713 {
714 Array<SurfaceElementIndex> surfElems;
715 mesh->GetSurfaceElementsOfFace(i,surfElems);
716
717 if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
718 {
719 for(int j = 0; j < surfElems.Size(); j++)
720 {
721 mesh->SurfaceElement(surfElems[j]).Visible(1);
722 }
723 }
724 }
725
726 mesh->SetNextTimeStamp();
727 }
728
729 if(strcmp(argv[1], "hidealso") == 0)
730 {
731 NgArray<Vec3d> face_colours;
732 GetFaceColours(*mesh,face_colours);
733
734 int colourind = atoi (argv[2]);
735
736 for(int i = 1; i <= mesh->GetNFD(); i++)
737 {
738 Array<SurfaceElementIndex> surfElems;
739 mesh->GetSurfaceElementsOfFace(i,surfElems);
740
741 if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
742 {
743 for(int j = 0; j < surfElems.Size(); j++)
744 {
745 mesh->SurfaceElement(surfElems[j]).Visible(0);
746 }
747 }
748 }
749
750 mesh->SetNextTimeStamp();
751 }
752
753 if(strcmp(argv[1], "showonly") == 0)
754 {
755 NgArray<Vec3d> face_colours;
756 GetFaceColours(*mesh,face_colours);
757
758 int colourind = atoi (argv[2]);
759
760 for(int i = 1; i <= mesh->GetNFD(); i++)
761 {
762 Array<SurfaceElementIndex> surfElems;
763 mesh->GetSurfaceElementsOfFace(i,surfElems);
764
765 if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
766 {
767 for(int j = 0; j < surfElems.Size(); j++)
768 {
769 mesh->SurfaceElement(surfElems[j]).Visible(1);
770 }
771 }
772 else
773 {
774 for(int j = 0; j < surfElems.Size(); j++)
775 {
776 mesh->SurfaceElement(surfElems[j]).Visible(0);
777 }
778 }
779 }
780
781 mesh->SetNextTimeStamp();
782 }
783
784 if(strcmp(argv[1], "hideonly") == 0)
785 {
786 NgArray<Vec3d> face_colours;
787 GetFaceColours(*mesh,face_colours);
788
789 int colourind = atoi (argv[2]);
790
791 for(int i = 1; i <= mesh->GetNFD(); i++)
792 {
793 Array<SurfaceElementIndex> surfElems;
794 mesh->GetSurfaceElementsOfFace(i,surfElems);
795
796 if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
797 {
798 for(int j = 0; j < surfElems.Size(); j++)
799 {
800 mesh->SurfaceElement(surfElems[j]).Visible(0);
801 }
802 }
803 else
804 {
805 for(int j = 0; j < surfElems.Size(); j++)
806 {
807 mesh->SurfaceElement(surfElems[j]).Visible(1);
808 }
809 }
810 }
811
812 mesh->SetNextTimeStamp();
813 }
814
815 if(strcmp(argv[1], "showall") == 0)
816 {
817 for(int i = 1; i <= mesh->GetNSE(); i++)
818 {
819 mesh->SurfaceElement(i).Visible(1);
820 }
821
822 mesh->SetNextTimeStamp();
823 }
824
825 if(strcmp(argv[1], "hideall") == 0)
826 {
827 for(int i = 1; i <= mesh->GetNSE(); i++)
828 {
829 mesh->SurfaceElement(i).Visible(0);
830 }
831
832 mesh->SetNextTimeStamp();
833 }
834
835 return TCL_OK;
836 }
837
838
839
840
841 // Philippose - 10/03/2009
842 // TCL interface function for the Automatic Colour-based
843 // definition of boundary conditions for OCC Geometry
Ng_AutoColourBcProps(ClientData clientData,Tcl_Interp * interp,int argc,tcl_const char * argv[])844 int Ng_AutoColourBcProps (ClientData clientData,
845 Tcl_Interp * interp,
846 int argc, tcl_const char *argv[])
847 {
848 if(argc < 1)
849 {
850 Tcl_SetResult (interp, (char *)"Ng_AutoColourBcProps needs arguments", TCL_STATIC);
851 return TCL_ERROR;
852 }
853
854 if(!mesh)
855 {
856 Tcl_SetResult (interp, (char *)"Ng_AutoColourBcProps: Valid netgen mesh required...please mesh the Geometry first", TCL_STATIC);
857 return TCL_ERROR;
858 }
859
860 if(strcmp(argv[1], "auto") == 0)
861 {
862 AutoColourBcProps(*mesh, 0);
863 }
864
865 if(strcmp(argv[1], "profile") == 0)
866 {
867 AutoColourBcProps(*mesh, argv[2]);
868 }
869
870 return TCL_OK;
871 }
872
873
Ng_SetOCCParameters(ClientData clientData,Tcl_Interp * interp,int argc,tcl_const char * argv[])874 int Ng_SetOCCParameters (ClientData clientData,
875 Tcl_Interp * interp,
876 int argc, tcl_const char *argv[])
877 {
878 OCCGeometryRegister reg;
879 reg.SetParameters (interp);
880 /*
881 occparam.resthcloseedgefac =
882 atof (Tcl_GetVar (interp, "::stloptions.resthcloseedgefac", 0));
883
884 occparam.resthcloseedgeenable =
885 atoi (Tcl_GetVar (interp, "::stloptions.resthcloseedgeenable", 0));
886 */
887 return TCL_OK;
888 }
889
890
891
892
Load(string filename) const893 NetgenGeometry * OCCGeometryRegister :: Load (string filename) const
894 {
895 const char * lgfilename = filename.c_str();
896
897
898 /*
899 if (strcmp (&cfilename[strlen(cfilename)-3], "geo") == 0)
900 {
901 PrintMessage (1, "Load OCCG geometry file ", cfilename);
902
903 extern OCCGeometry * ParseOCCG (istream & istr);
904
905 ifstream infile(cfilename);
906
907 OCCGeometry * hgeom = ParseOCCG (infile);
908 if (!hgeom)
909 throw NgException ("geo-file should start with 'algebraic3d'");
910
911 hgeom -> FindIdenticSurfaces(1e-8 * hgeom->MaxSize());
912 return hgeom;
913 }
914 */
915
916
917 if ((strcmp (&lgfilename[strlen(lgfilename)-4], "iges") == 0) ||
918 (strcmp (&lgfilename[strlen(lgfilename)-3], "igs") == 0) ||
919 (strcmp (&lgfilename[strlen(lgfilename)-3], "IGS") == 0) ||
920 (strcmp (&lgfilename[strlen(lgfilename)-4], "IGES") == 0))
921 {
922 PrintMessage (1, "Load IGES geometry file ", lgfilename);
923 OCCGeometry * occgeometry = LoadOCC_IGES (lgfilename);
924 return occgeometry;
925 }
926
927 else if ((strcmp (&lgfilename[strlen(lgfilename)-4], "step") == 0) ||
928 (strcmp (&lgfilename[strlen(lgfilename)-3], "stp") == 0) ||
929 (strcmp (&lgfilename[strlen(lgfilename)-3], "STP") == 0) ||
930 (strcmp (&lgfilename[strlen(lgfilename)-4], "STEP") == 0))
931 {
932 PrintMessage (1, "Load STEP geometry file ", lgfilename);
933 OCCGeometry * occgeometry = LoadOCC_STEP (lgfilename);
934 return occgeometry;
935 }
936 else if ((strcmp (&lgfilename[strlen(lgfilename)-4], "brep") == 0) ||
937 (strcmp (&lgfilename[strlen(lgfilename)-4], "Brep") == 0) ||
938 (strcmp (&lgfilename[strlen(lgfilename)-4], "BREP") == 0))
939 {
940 PrintMessage (1, "Load BREP geometry file ", lgfilename);
941 OCCGeometry * occgeometry = LoadOCC_BREP (lgfilename);
942 return occgeometry;
943 }
944
945 return NULL;
946 }
947
948
949 static VisualSceneOCCGeometry vsoccgeom;
950
GetVisualScene(const NetgenGeometry * geom) const951 VisualScene * OCCGeometryRegister :: GetVisualScene (const NetgenGeometry * geom) const
952 {
953 OCCGeometry * geometry = dynamic_cast<OCCGeometry*> (ng_geometry.get());
954 if (geometry)
955 {
956 vsoccgeom.SetGeometry (geometry);
957 return &vsoccgeom;
958 }
959 return NULL;
960 }
961
962
963
964 }
965
966
967
968 using namespace netgen;
969
Ng_occ_Init(Tcl_Interp * interp)970 int Ng_occ_Init (Tcl_Interp * interp)
971 {
972 geometryregister.Append (new OCCGeometryRegister);
973
974
975 Tcl_CreateCommand (interp, "Ng_SetOCCVisParameters",
976 Ng_SetOCCVisParameters,
977 (ClientData)NULL,
978 (Tcl_CmdDeleteProc*) NULL);
979
980 Tcl_CreateCommand (interp, "Ng_GetOCCData",
981 Ng_GetOCCData,
982 (ClientData)NULL,
983 (Tcl_CmdDeleteProc*) NULL);
984
985 /*
986 #ifdef OCCGEOMETRY
987 Tcl_CreateCommand (interp, "Ng_OCCConstruction",
988 Ng_OCCConstruction,
989 (ClientData)NULL,
990 (Tcl_CmdDeleteProc*) NULL);
991 #endif
992 */
993
994 Tcl_CreateCommand (interp, "Ng_OCCCommand",
995 Ng_OCCCommand,
996 (ClientData)NULL,
997 (Tcl_CmdDeleteProc*) NULL);
998
999
1000 Tcl_CreateCommand (interp, "Ng_SetOCCParameters", Ng_SetOCCParameters,
1001 (ClientData)NULL,
1002 (Tcl_CmdDeleteProc*) NULL);
1003
1004
1005
1006 // Philippose - 30/01/2009
1007 // Register the TCL Interface Command for local face mesh size
1008 // definition
1009 Tcl_CreateCommand (interp, "Ng_SurfaceMeshSize", Ng_SurfaceMeshSize,
1010 (ClientData)NULL,
1011 (Tcl_CmdDeleteProc*) NULL);
1012
1013 Tcl_CreateCommand (interp, "Ng_AutoColourBcProps", Ng_AutoColourBcProps,
1014 (ClientData)NULL,
1015 (Tcl_CmdDeleteProc*) NULL);
1016
1017 // Philippose - 25/07/2010
1018 // Register the TCL Interface Command for handling the face colours
1019 // present in the mesh
1020 Tcl_CreateCommand(interp, "Ng_CurrentFaceColours", Ng_CurrentFaceColours,
1021 (ClientData)NULL,
1022 (Tcl_CmdDeleteProc*) NULL);
1023
1024
1025 return TCL_OK;
1026 }
1027
1028 #endif
1029
1030