15 #define Printf Printf_opencascade
17 #include <TopoDS_Solid.hxx>
18 #include <BRepPrimAPI_MakeCylinder.hxx>
19 #include <BRep_Builder.hxx>
20 #include <TopoDS_Compound.hxx>
21 #include <TDocStd_Document.hxx>
22 #include <XCAFApp_Application.hxx>
23 #include <XCAFDoc_ShapeTool.hxx>
24 #include <XCAFDoc_ColorTool.hxx>
25 #include <XCAFDoc_DocumentTool.hxx>
26 #include <Quantity_Color.hxx>
27 #include <NCollection_Vector.hxx>
28 #include <STEPCAFControl_Writer.hxx>
30 #include <BRepBuilderAPI_MakePolygon.hxx>
31 #include <BRepBuilderAPI_MakeFace.hxx>
32 #include <BRepPrimAPI_MakeRevol.hxx>
33 #include <BRepBuilderAPI_Sewing.hxx>
34 #include <BRepBuilderAPI_MakeSolid.hxx>
35 #include <BRepBuilderAPI.hxx>
36 #include <BRepLib_MakeEdge.hxx>
38 #include <gp_Trsf.hxx>
39 #include <BRepBuilderAPI_Transform.hxx>
41 #include <TopExp_Explorer.hxx>
46 #include "G4PVPlacement.hh"
47 #include "G4SystemOfUnits.hh"
48 #include "G4NistManager.hh"
51 #include "G4GenericPolycone.hh"
52 #include "G4Polyhedra.hh"
53 #include "G4LogicalVolume.hh"
54 #include "G4VisAttributes.hh"
55 #include "G4SubtractionSolid.hh"
62 int linecolor,
double length):
65 mLength(length), mOffset(0.0), mActualDistance(0.0), mG4PhysicalVolume(0), mColorAlpha(-1.0)
69 mLabel = label ?
new TString(label) : 0;
77 return (!
eic->mUseDetectorHighlighting || (
eic->mUseDetectorHighlighting &&
mColorAlpha != -1.0));
107 int fillcolor =
eic->Palette().GetColor(tag);
108 if (fillcolor == -1) {
109 printf(
"Tag '%s' does not exist!\n", tag);
126 if (label && !label->IsNull())
140 if (etamin < 0.0) etamin = 0.0;
if (etamin > 1.0) etamin = 1.0;
141 if (etamax < 0.0) etamax = 0.0;
if (etamax > 1.0) etamax = 1.0;
166 eic->AddBoundaryModificationRequest(
this, refdet, toffset, how);
170 eic->AddBoundaryModificationRequest(
this,
eic->bck()->get(0), toffset, how);
171 eic->AddBoundaryModificationRequest(
this,
eic->fwd()->get(0), toffset, how);
174 eic->AddBoundaryModificationRequest(
this,
eic->mid()->get(0), toffset, how);
192 return stretch(refstack->
get(0), tlength, how);
200 TVector2
ip =
eic->GetIpLocation();
213 std::vector<TVector2> sides[2], vertices;
216 for(
unsigned vh=0; vh<2; vh++)
217 for(
unsigned tb=0; tb<2; tb++) {
218 for(
unsigned bf=0; bf<2; bf++) {
220 double sign = bf == tb ? -1.0 : 1.0;
221 auto &vtxarr = boundary->mCrackNodes[vh][tb];
228 std::vector<EtmLine2D> lines;
229 for(
unsigned ivtx=1; ivtx<vtxarr.size(); ivtx++)
230 lines.push_back(
EtmLine2D(vtxarr[ivtx-1], (vtxarr[ivtx]-vtxarr[ivtx-1]).Unit()));
232 for(
unsigned iln=0; iln<lines.size(); iln++) {
233 auto &line = lines[iln];
237 line.Shift(sign*(
eic->SafetyClearance()/2)*line.N());
240 qvtxarr.push_back(lines[0].X());
243 for(
unsigned iln=1; iln<lines.size(); iln++)
244 if (!lines[iln-1].IsParallel(lines[iln]))
245 qvtxarr.push_back(lines[iln-1].Cross(lines[iln]));
247 qvtxarr.push_back(vtxarr[vtxarr.size()-1] +
248 (sign*
eic->SafetyClearance()/2)*lines[lines.size()-1].N());
253 axis.Rotate(-
M_PI/2));
255 axis.Rotate(-
M_PI/2));
262 if ( central && fabs(to.
X().Y()) >
eic->GetIrRegionRadius())
return;
263 if (!central && fabs(to.
X().X()) >
eic->GetIrRegionLength()/2)
return;
267 sides[bf] =
eic->Band( vtxarr, from, to);
273 if (
mStack ==
eic->bck() && !bf && trim != 0.0 && trim != 1.0) trim = 1.0;
274 if (
mStack ==
eic->fwd() && bf && trim != 0.0 && trim != 1.0) trim = 1.0;
278 double dmin = 0.0, dmax = 0.0;
282 for(
unsigned ivtx=0; ivtx<sides[bf].size(); ivtx++) {
283 auto vtx = sides[bf][ivtx];
285 if (!ivtx || d < dmin) dmin =
d;
286 if (!ivtx || d > dmax) dmax =
d;
292 if (fabs(dmax - dmin) > 1E-6) {
294 double range = (dmax - dmin)*(tb ? 1.0 - trim : trim), limit = bf ? dmax - range : dmin + range;
297 EtmLine2D cut(ip + limit*thrust.
N(), -sign*axis);
303 for(
auto &
vtx: halves.first)
304 sides[bf].push_back(
vtx);
305 sides[bf].push_back(to.
Cross(cut));
307 for(
auto &
vtx: sides[bf]) {
309 TVector2 along =
vtx - d*thrust.
N();
311 vtx = along + limit*thrust.
N();
324 for(
unsigned ivtx=0; ivtx<sides[1].size(); ivtx++)
325 vertices.push_back(sides[1][sides[1].size()-1-ivtx]);
343 unsigned counter = 0;
348 if (*det->GetLabel() == *
GetLabel()) {
349 if (det ==
this)
return counter;
372 unsigned dim = polygon.size();
378 TVector2
ip =
eic->GetIpLocation();
382 for(
unsigned ivtx=0; ivtx<
dim; ivtx++) {
383 auto &pt = polygon[ivtx];
385 z[ivtx] = (pt.X() - z0)*cff;
386 r[ivtx] = pt.Y()*cff;
392 label = TString(name);
397 unsigned segmentation =
eic->GetAzimuthalSegmentation();
401 vpol =
new G4Polyhedra (label.Data(), 0., 360.*deg, segmentation,
dim, r,
z);
403 vpol =
new G4GenericPolycone(label.Data(), 0., 360.*deg,
dim, r,
z);
406 auto vc =
eic->GetVacuumChamber();
407 bool vc_cut_required = vc;
412 if (
mStack ==
eic->vtx() &&
eic->vtx()->GetDetector(0) !=
this) vc_cut_required =
false;
416 (
eic->vtx()->DetectorCount() || (
eic->mid()->GetDetector(0) !=
this)))
417 vc_cut_required =
false;
427 auto vout = vc && vc_cut_required ? vc->CutThisSolid(vpol, z0*cff) : vpol;
431 auto air = G4NistManager::Instance()->FindOrBuildMaterial(
"G4_AIR");
433 auto lout =
new G4LogicalVolume(vout, air, label.Data(), 0, 0, 0);
439 G4VisAttributes* visAtt =
new G4VisAttributes();
441 visAtt->SetColor(rcolor->GetRed(), rcolor->GetGreen(), rcolor->GetBlue(), 0.3);
442 visAtt->SetVisibility(
true);
443 visAtt->SetForceWireframe(
false);
444 visAtt->SetForceSolid(
true);
446 lout->SetVisAttributes(visAtt);
450 new G4PVPlacement(0, G4ThreeVector(0, 0, z0*cff), lout, label.Data(),
world,
false, 0);
483 printf(
"\n\n World volume was not define yet, sorry!\n\n");
495 std::vector<std::pair<const TColor*, const TopoDS_Shape*> > shape;
503 if (!
Polygons().size())
return shape;
506 unsigned dim = polygon.size();
509 double cff = 1.0, z0 = 0.0;
512 auto fpoly = BRepBuilderAPI_MakePolygon();
513 for(
auto const &pt: polygon)
514 fpoly.Add(gp_Pnt(pt.Y()*cff, 0.0, (pt.X()-z0)*cff));
518 auto fface = BRepBuilderAPI_MakeFace(fpoly);
519 gp_Ax1 axis(gp_Pnt(0,0,0), gp_Dir(0,0,1));
522 if (
eic->GetAzimuthalSegmentation()) {
523 double alfa = 2*
M_PI/
eic->GetAzimuthalSegmentation();
524 auto rpoly = BRepBuilderAPI_MakePolygon();
525 std::vector<gp_Pnt> front, rear;
526 std::vector<TopoDS_Face> sides;
528 for(
auto const &pt: polygon) {
529 double xx = pt.Y()*cff, yy = 0.0, zz = (pt.X()-z0)*cff;
530 double xq =
cos(alfa)*xx + sin(alfa)*yy;
531 double yq = -sin(alfa)*xx +
cos(alfa)*yy;
533 front.push_back(gp_Pnt(xx, yy, zz));
534 rear .push_back(gp_Pnt(xq, yq, zz));
536 rpoly.Add(gp_Pnt(xq, yq, zz));
540 auto rface = BRepBuilderAPI_MakeFace(rpoly);
542 for(
unsigned ivtx=0; ivtx<
dim; ivtx++) {
543 auto spoly = BRepBuilderAPI_MakePolygon();
545 spoly.Add(front[ ivtx ]);
546 spoly.Add( rear[ ivtx ]);
547 spoly.Add( rear[(ivtx+1)%dim]);
548 spoly.Add(front[(ivtx+1)%dim]);
551 sides.push_back(BRepBuilderAPI_MakeFace(spoly));
554 BRepBuilderAPI_Sewing *sew =
new BRepBuilderAPI_Sewing();
557 for(
unsigned ivtx=0; ivtx<
dim; ivtx++)
558 sew->Add(sides[ivtx]);
561 auto result = sew->SewedShape();
563 for (TopExp_Explorer itf(result,TopAbs_SHELL); itf.More(); itf.Next()) {
564 TopoDS_Shell &shell = (TopoDS_Shell&)itf.Current();
567 for(
unsigned iq=0; iq<
eic->GetAzimuthalSegmentation(); iq++) {
569 rZ.SetRotation(axis, alfa*iq);
570 BRepBuilderAPI_Transform rot(rZ);
572 auto buffer = BRepBuilderAPI_MakeSolid(shell).Solid();
575 shape.push_back(std::make_pair(rcolor,
new TopoDS_Shape(rot.ModifiedShape(
buffer))));
583 shape.push_back(std::make_pair(rcolor,
new TopoDS_Shape(BRepPrimAPI_MakeRevol(fface, axis))));