// Exports the whole configuration as one fused part to an IGES file void CTiglExportIges::ExportFusedIGES(const std::string& filename) { if (filename.empty()) { LOG(ERROR) << "Error: Empty filename in ExportFusedIGES."; return; } PTiglFusePlane fuser = _config.AircraftFusingAlgo(); fuser->SetResultMode(HALF_PLANE_TRIMMED_FF); assert(fuser); PNamedShape fusedAirplane = fuser->FusedPlane(); PNamedShape farField = fuser->FarField(); if (!fusedAirplane) { throw CTiglError("Error computing fused airplane.", TIGL_NULL_POINTER); } try { ListPNamedShape l; l.push_back(fusedAirplane); l.push_back(farField); // add intersections const ListPNamedShape& ints = fuser->Intersections(); ListPNamedShape::const_iterator it; for (it = ints.begin(); it != ints.end(); ++it) { l.push_back(*it); } ExportShapes(l, filename); } catch (CTiglError&) { throw CTiglError("Cannot export fused Airplane as IGES", TIGL_ERROR); } }
CGroupShapes::CGroupShapes(const ListPNamedShape& list) { if (list.size() == 1) { _result = list[0]; return; } BRep_Builder b; TopoDS_Compound c; b.MakeCompound(c); for (ListPNamedShape::const_iterator it=list.begin(); it != list.end(); ++it) { PNamedShape shape = *it; if (!shape) { continue; } b.Add(c, shape->Shape()); } _result = PNamedShape(new CNamedShape(c, "ShapeGroup")); // apply face names from the shapes for (ListPNamedShape::const_iterator it=list.begin(); it != list.end(); ++it) { PNamedShape shape = *it; if (!shape) { continue; } CBooleanOperTools::AppendNamesToShape(shape, _result); } }
/** * @todo: it would be nice if this algorithm would support * some progress bar interface */ void CTiglFusePlane::Perform() { if (_hasPerformed) { return; } CTiglUIDManager& uidManager = _myconfig.GetUIDManager(); CTiglAbstractPhysicalComponent* rootComponent = uidManager.GetRootComponent(); if (!rootComponent) { LOG(ERROR) << "Root component of plane not found. Cannot create fused plane."; return; } _result = FuseWithChilds(rootComponent); CCPACSFarField& farfield = _myconfig.GetFarField(); if (farfield.GetFieldType() != NONE && (_mymode == FULL_PLANE_TRIMMED_FF || _mymode == HALF_PLANE_TRIMMED_FF)) { PNamedShape ff = farfield.GetLoft(); BOPCol_ListOfShape aLS; aLS.Append(_result->Shape()); aLS.Append(ff->Shape()); BOPAlgo_PaveFiller dsfill; dsfill.SetArguments(aLS); dsfill.Perform(); CTrimShape trim1(_result, ff, dsfill, INCLUDE); PNamedShape resulttrimmed = trim1.NamedShape(); CTrimShape trim2(ff, _result, dsfill, EXCLUDE); _farfield = trim2.NamedShape(); _result = resulttrimmed; // trim intersections with far field ListPNamedShape::iterator intIt = _intersections.begin(); ListPNamedShape newInts; for (; intIt != _intersections.end(); ++intIt) { PNamedShape inters = *intIt; if (!inters) { continue; } TopoDS_Shape sh = inters->Shape(); sh = BRepAlgoAPI_Common(sh, ff->Shape()); if (! sh.IsNull()) { inters->SetShape(sh); newInts.push_back(inters); } } _intersections = newInts; } if (_result) { _result->SetName(_myconfig.GetUID().c_str()); _result->SetShortName("AIRCRAFT"); } _hasPerformed = true; }
// Exports the whole configuration as IGES file // All wing- and fuselage segments are exported as single bodys void CTiglExportIges::ExportIGES(const std::string& filename) const { if ( filename.empty()) { LOG(ERROR) << "Error: Empty filename in ExportIGES."; return; } ListPNamedShape shapes; // Export all wings of the configuration for (int w = 1; w <= _config.GetWingCount(); w++) { CCPACSWing& wing = _config.GetWing(w); for (int i = 1; i <= wing.GetSegmentCount(); i++) { CCPACSWingSegment& segment = (tigl::CCPACSWingSegment &) wing.GetSegment(i); PNamedShape loft = segment.GetLoft(); shapes.push_back(loft); } } // Export all fuselages of the configuration for (int f = 1; f <= _config.GetFuselageCount(); f++) { CCPACSFuselage& fuselage = _config.GetFuselage(f); for (int i = 1; i <= fuselage.GetSegmentCount(); i++) { CCPACSFuselageSegment& segment = (tigl::CCPACSFuselageSegment &) fuselage.GetSegment(i); PNamedShape loft = segment.GetLoft(); shapes.push_back(loft); } } CCPACSFarField& farfield = _config.GetFarField(); if (farfield.GetFieldType() != NONE) { shapes.push_back(farfield.GetLoft()); } // write iges try { ExportShapes(shapes, filename); } catch (CTiglError&) { throw CTiglError("Cannot export airplane in CTiglExportIges", TIGL_ERROR); } }
ListPNamedShape GroupFaces(const PNamedShape shape, tigl::ShapeGroupMode groupType) { ListPNamedShape shapeList; if (!shape) { return shapeList; } if (groupType == tigl::NAMED_COMPOUNDS) { BRep_Builder b; TopTools_IndexedMapOfShape faceMap; std::map<PNamedShape, TopoDS_Shape> map; TopExp::MapShapes(shape->Shape(), TopAbs_FACE, faceMap); if (faceMap.Extent() == 0) { // return the shape as is shapeList.push_back(shape); return shapeList; } for (int iface = 1; iface <= faceMap.Extent(); ++iface) { TopoDS_Face face = TopoDS::Face(faceMap(iface)); PNamedShape origin = shape->GetFaceTraits(iface-1).Origin(); std::map<PNamedShape, TopoDS_Shape>::iterator it = map.find(origin); if (it == map.end()) { TopoDS_Compound c; b.MakeCompound(c); b.Add(c, face); map[origin] = c; } else { TopoDS_Shape& c = it->second; b.Add(c, face); } } // create Named Shapes std::map<PNamedShape, TopoDS_Shape>::iterator it; for (it = map.begin(); it != map.end(); ++it) { PNamedShape origin = it->first; TopoDS_Shape toposhape = it->second; PNamedShape curshape; if (origin) { curshape = PNamedShape(new CNamedShape(toposhape, origin->Name())); curshape->SetShortName(origin->ShortName()); } else { curshape = PNamedShape(new CNamedShape(toposhape, shape->Name())); curshape->SetShortName(shape->ShortName()); } // set the original face traits CBooleanOperTools::AppendNamesToShape(shape, curshape); // make shells curshape = CBooleanOperTools::Shellify(curshape); shapeList.push_back(curshape); } } else if (groupType == tigl::WHOLE_SHAPE) { shapeList.push_back(shape); } else if (groupType == tigl::FACES) { // store each face as an own shape TopTools_IndexedMapOfShape faceMap; TopExp::MapShapes(shape->Shape(), TopAbs_FACE, faceMap); if (faceMap.Extent() == 0) { // return the shape as is shapeList.push_back(shape); return shapeList; } for (int iface = 1; iface <= faceMap.Extent(); ++iface) { TopoDS_Face face = TopoDS::Face(faceMap(iface)); const CFaceTraits& traits = shape->GetFaceTraits(iface-1); PNamedShape faceShape; if (traits.Origin()) { faceShape = PNamedShape(new CNamedShape(face, traits.Origin()->Name())); faceShape->SetShortName(traits.Origin()->ShortName()); } else { faceShape = PNamedShape(new CNamedShape(face, shape->Name())); faceShape->SetShortName(shape->ShortName()); } faceShape->SetFaceTraits(0, shape->GetFaceTraits(iface-1)); shapeList.push_back(faceShape); } } return shapeList; }
// Save a sequence of shapes in IGES Format void CTiglExportIges::ExportShapes(const ListPNamedShape& shapes, const std::string& filename) const { IGESControl_Controller::Init(); if ( filename.empty()) { LOG(ERROR) << "Error: Empty filename in ExportShapes."; return; } ListPNamedShape::const_iterator it; // scale all shapes to mm ListPNamedShape shapeScaled; for (it = shapes.begin(); it != shapes.end(); ++it) { PNamedShape pshape = *it; if (pshape) { CTiglTransformation trafo; trafo.AddScaling(1000,1000,1000); PNamedShape pScaledShape(new CNamedShape(*pshape)); pScaledShape->SetShape(trafo.Transform(pshape->Shape())); shapeScaled.push_back(pScaledShape); } } ListPNamedShape list; for (it = shapeScaled.begin(); it != shapeScaled.end(); ++it) { ListPNamedShape templist = GroupFaces(*it, _groupMode); for (ListPNamedShape::iterator it2 = templist.begin(); it2 != templist.end(); ++it2) { list.push_back(*it2); } } SetTranslationParameters(); IGESControl_Writer igesWriter("MM", 0); igesWriter.Model()->ApplyStatic(); int level = 0; for (it = list.begin(); it != list.end(); ++it) { PNamedShape pshape = *it; AddToIges(pshape, igesWriter, level++); } igesWriter.ComputeModel(); if (igesWriter.Write(const_cast<char*>(filename.c_str())) != Standard_True) { throw CTiglError("Error: Export of shapes to IGES file failed in CCPACSImportExport::SaveIGES", TIGL_ERROR); } }
PNamedShape CTiglFusePlane::FuseWithChilds(CTiglAbstractPhysicalComponent* parent) { assert(parent != NULL); PNamedShape parentShape (parent->GetLoft()); if (parentShape) { if (_mymode == FULL_PLANE || _mymode == FULL_PLANE_TRIMMED_FF) { PNamedShape rootShapeMirr = parent->GetMirroredLoft(); parentShape = CMergeShapes(parentShape, rootShapeMirr); } } CTiglAbstractPhysicalComponent::ChildContainerType childs = parent->GetChildren(false); CTiglAbstractPhysicalComponent::ChildContainerType::iterator childIt; if (childs.size() == 0) { return parentShape; } ListPNamedShape childShapes; for (childIt = childs.begin(); childIt != childs.end(); ++childIt) { CTiglAbstractPhysicalComponent* child = *childIt; if (!child) { continue; } PNamedShape childShape = FuseWithChilds(child); childShapes.push_back(childShape); } CFuseShapes fuser(parentShape, childShapes); PNamedShape result = fuser.NamedShape(); // trim previous intersections ListPNamedShape::iterator intIt = _intersections.begin(); ListPNamedShape newInts; for (; intIt != _intersections.end(); ++intIt) { PNamedShape inters = *intIt; if (!inters) { continue; } TopoDS_Shape sh = inters->Shape(); if (parentShape) { sh = BRepAlgoAPI_Cut(sh, parentShape->Shape()); } if (!sh.IsNull()) { inters->SetShape(sh); newInts.push_back(inters); } } _intersections = newInts; // insert intersections ListPNamedShape::const_iterator it = fuser.Intersections().begin(); for (; it != fuser.Intersections().end(); it++) { if (*it) { _intersections.push_back(*it); } } return result; }