// Set the face traits
    void SetFaceTraits (PNamedShape loft) 
    { 
        // designated names of the faces
        std::vector<std::string> names(5);
        names[0]="Bottom";
        names[1]="Top";
        names[2]="TrailingEdge";
        names[3]="Inside";
        names[4]="Outside";

        // map of faces
        TopTools_IndexedMapOfShape map;
        TopExp::MapShapes(loft->Shape(),   TopAbs_FACE, map);

        // check if number of faces is correct (only valid for ruled surfaces lofts)
        if (map.Extent() != 5 && map.Extent() != 4) {
            LOG(ERROR) << "CCPACSWingSegment: Unable to determine face names in ruled surface loft";
            return;
        }
        // remove trailing edge name if there is no trailing edge
        if (map.Extent() == 4) {
            names.erase(names.begin()+2);
        }
        // set face trait names
        for (int i = 0; i < map.Extent(); i++) {
            CFaceTraits traits = loft->GetFaceTraits(i);
            traits.SetName(names[i].c_str());
            loft->SetFaceTraits(i, traits);
        }
    }
//=======================================================================
//function : Execute
//purpose  :
//=======================================================================
Standard_Integer GEOM_SubShapeDriver::Execute(TFunction_Logbook& log) const
{
  if (Label().IsNull()) return 0;
  Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());

  GEOM_ISubShape aCI (aFunction);

  TDF_Label aLabel = aCI.GetMainShape()->GetOwnerEntry();
  if (aLabel.IsRoot()) return 0;
  Handle(GEOM_Object) anObj = GEOM_Object::GetObject(aLabel);
  if (anObj.IsNull()) return 0;
  TopoDS_Shape aMainShape = anObj->GetValue();
  if (aMainShape.IsNull()) return 0;

  Handle(TColStd_HArray1OfInteger) anIndices = aCI.GetIndices();
  if (anIndices.IsNull() || anIndices->Length() <= 0) return 0;

  BRep_Builder B;
  TopoDS_Compound aCompound;
  TopoDS_Shape aShape;

  if (anIndices->Length() == 1 && anIndices->Value(1) == -1) { //The empty sub-shape
    B.MakeCompound(aCompound);
    aShape = aCompound;
  }
  else {
    TopTools_IndexedMapOfShape aMapOfShapes;
    TopExp::MapShapes(aMainShape, aMapOfShapes);

    if (anIndices->Length() > 1) {
      B.MakeCompound(aCompound);

      for (int i = anIndices->Lower(); i <= anIndices->Upper(); i++) {
        if (aMapOfShapes.Extent() < anIndices->Value(i))
          Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
        TopoDS_Shape aSubShape = aMapOfShapes.FindKey(anIndices->Value(i));
        if (aSubShape.IsNull()) continue;
        B.Add(aCompound,aSubShape);
      }

      aShape = aCompound;
    }
    else {
      int i = anIndices->Lower();
      if (aMapOfShapes.Extent() < anIndices->Value(i))
        Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
      aShape = aMapOfShapes.FindKey(anIndices->Value(i));
    }
  }

  if (aShape.IsNull()) return 0;

  aFunction->SetValue(aShape);

  log.SetTouched(Label());

  return 1;
}
 void LowLightAll()
 {
    for (int i = 1; i <= fmap.Extent(); i++)
       fvispar[i-1].Lowlight();
    for (int i = 1; i <= emap.Extent(); i++)
       evispar[i-1].Lowlight();
    for (int i = 1; i <= vmap.Extent(); i++)
       vvispar[i-1].Lowlight();
 }
void ViewProviderShapeBinder::highlightReferences(const bool on, bool /*auxillery*/)
{
    Part::Feature* obj;
    std::vector<std::string> subs;

    if(getObject()->isDerivedFrom(PartDesign::ShapeBinder::getClassTypeId()))
        PartDesign::ShapeBinder::getFilteredReferences(&static_cast<PartDesign::ShapeBinder*>(getObject())->Support, obj, subs);
    else
        return;

    PartGui::ViewProviderPart* svp = dynamic_cast<PartGui::ViewProviderPart*>(
                Gui::Application::Instance->getViewProvider(obj));
    if (svp == NULL) return;

    if (on) {
         if (!subs.empty() && originalLineColors.empty()) {
            TopTools_IndexedMapOfShape eMap;
            TopExp::MapShapes(obj->Shape.getValue(), TopAbs_EDGE, eMap);
            originalLineColors = svp->LineColorArray.getValues();
            std::vector<App::Color> lcolors = originalLineColors;
            lcolors.resize(eMap.Extent(), svp->LineColor.getValue());

            TopExp::MapShapes(obj->Shape.getValue(), TopAbs_FACE, eMap);
            originalFaceColors = svp->DiffuseColor.getValues();
            std::vector<App::Color> fcolors = originalFaceColors;
            fcolors.resize(eMap.Extent(), svp->ShapeColor.getValue());

            for (std::string e : subs) {
                // Note: stoi may throw, but it strictly shouldn't happen
                if(e.substr(4) == "Edge") {
                    int idx = std::stoi(e.substr(4)) - 1;
                    assert ( idx>=0 );
                    if ( idx < (ssize_t) lcolors.size() )
                        lcolors[idx] = App::Color(1.0,0.0,1.0); // magenta
                }
                else if(e.substr(4) == "Face")  {
                    int idx = std::stoi(e.substr(4)) - 1;
                    assert ( idx>=0 );
                    if ( idx < (ssize_t) fcolors.size() )
                        fcolors[idx] = App::Color(1.0,0.0,1.0); // magenta
                }
            }
            svp->LineColorArray.setValues(lcolors);
            svp->DiffuseColor.setValues(fcolors);
        }
    } else {
        if (!subs.empty() && !originalLineColors.empty()) {
            svp->LineColorArray.setValues(originalLineColors);
            originalLineColors.clear();
            
            svp->DiffuseColor.setValues(originalFaceColors);
            originalFaceColors.clear();
        }
    }
}
void FaceMakerExtrusion::Build()
{
    this->NotDone();
    this->myGenerated.Clear();
    this->myShapesToReturn.clear();
    this->myShape = TopoDS_Shape();
    TopoDS_Shape inputShape;
    if (mySourceShapes.empty())
        throw Base::Exception("No input shapes!");
    if (mySourceShapes.size() == 1){
        inputShape = mySourceShapes[0];
    } else {
        TopoDS_Builder builder;
        TopoDS_Compound cmp;
        builder.MakeCompound(cmp);
        for (const TopoDS_Shape& sh: mySourceShapes){
            builder.Add(cmp, sh);
        }
        inputShape = cmp;
    }

    std::vector<TopoDS_Wire> wires;
    TopTools_IndexedMapOfShape mapOfWires;
    TopExp::MapShapes(inputShape, TopAbs_WIRE, mapOfWires);

    // if there are no wires then check also for edges
    if (mapOfWires.IsEmpty()) {
        TopTools_IndexedMapOfShape mapOfEdges;
        TopExp::MapShapes(inputShape, TopAbs_EDGE, mapOfEdges);
        for (int i=1; i<=mapOfEdges.Extent(); i++) {
            BRepBuilderAPI_MakeWire mkWire(TopoDS::Edge(mapOfEdges.FindKey(i)));
            wires.push_back(mkWire.Wire());
        }
    }
    else {
        wires.reserve(mapOfWires.Extent());
        for (int i=1; i<=mapOfWires.Extent(); i++) {
            wires.push_back(TopoDS::Wire(mapOfWires.FindKey(i)));
        }
    }

    if (!wires.empty()) {
        //try {
            TopoDS_Shape res = FaceMakerCheese::makeFace(wires);
            if (!res.IsNull())
                this->myShape = res;
        //}
        //catch (...) {

        //}
    }

    this->Done();

}
void ViewProviderMultiCommon::updateData(const App::Property* prop)
{
    PartGui::ViewProviderPart::updateData(prop);
    if (prop->getTypeId() == Part::PropertyShapeHistory::getClassTypeId()) {
        const std::vector<Part::ShapeHistory>& hist = static_cast<const Part::PropertyShapeHistory*>
            (prop)->getValues();
        Part::MultiCommon* objBool = static_cast<Part::MultiCommon*>(getObject());
        std::vector<App::DocumentObject*> sources = objBool->Shapes.getValues();
        if (hist.size() != sources.size())
            return;

        const TopoDS_Shape& boolShape = objBool->Shape.getValue();
        TopTools_IndexedMapOfShape boolMap;
        TopExp::MapShapes(boolShape, TopAbs_FACE, boolMap);

        std::vector<App::Color> colBool;
        colBool.resize(boolMap.Extent(), this->ShapeColor.getValue());

        bool setColor=false;
        int index=0;
        for (std::vector<App::DocumentObject*>::iterator it = sources.begin(); it != sources.end(); ++it, ++index) {
            Part::Feature* objBase = dynamic_cast<Part::Feature*>(*it);
            if (!objBase)
                continue;
            const TopoDS_Shape& baseShape = objBase->Shape.getValue();
 
            TopTools_IndexedMapOfShape baseMap;
            TopExp::MapShapes(baseShape, TopAbs_FACE, baseMap);

            Gui::ViewProvider* vpBase = Gui::Application::Instance->getViewProvider(objBase);
            std::vector<App::Color> colBase = static_cast<PartGui::ViewProviderPart*>(vpBase)->DiffuseColor.getValues();
            if (static_cast<int>(colBase.size()) == baseMap.Extent()) {
                applyColor(hist[index], colBase, colBool);
                setColor = true;
            }
            else if (!colBase.empty() && colBase[0] != this->ShapeColor.getValue()) {
                colBase.resize(baseMap.Extent(), colBase[0]);
                applyColor(hist[index], colBase, colBool);
                setColor = true;
            }
        }

        if (setColor)
            this->DiffuseColor.setValues(colBool);
    }
    else if (prop->getTypeId() == App::PropertyLinkList::getClassTypeId()) {
        std::vector<App::DocumentObject*> pShapes = static_cast<const App::PropertyLinkList*>(prop)->getValues();
        for (std::vector<App::DocumentObject*>::iterator it = pShapes.begin(); it != pShapes.end(); ++it) {
            if (*it)
                Gui::Application::Instance->hideViewProvider(*it);
        }
    }
}
//=======================================================================
//function : FacePassKey
//purpose  : 
//=======================================================================
void GEOMAlgo_GlueDetector::FacePassKey(const TopoDS_Face& aF, 
					GEOMAlgo_PassKeyShape& aPK)
{
  Standard_Integer i, aNbE;
  TopoDS_Shape aER;
  TopTools_ListOfShape aLE;
  TopTools_IndexedMapOfShape aME;
  //
  TopExp::MapShapes(aF, TopAbs_EDGE, aME);
  //
  aNbE=aME.Extent();
  for (i=1; i<=aNbE; ++i) {
    const TopoDS_Shape& aE=aME(i);
    //
    const TopoDS_Edge& aEE=*((TopoDS_Edge*)&aE);
    if (BRep_Tool::Degenerated(aEE)) {
      continue;
    }
    // 
    if (myOrigins.IsBound(aE)) {
      aER=myOrigins.Find(aE);
    }
    else {
      aER=aE;
    }
    aLE.Append(aER);
  }
  aPK.SetShapes(aLE);
}
Exemple #8
0
void DrawUtil::countEdges(const char* text, const TopoDS_Shape& s)
{
    TopTools_IndexedMapOfShape mapOfEdges;
    TopExp::MapShapes(s, TopAbs_EDGE, mapOfEdges);
    int num = mapOfEdges.Extent();
    Base::Console().Message("COUNT - %s has %d edges\n",text,num);
}
//=======================================================================
//function : FillContainers
//purpose  :
//=======================================================================
void GEOMAlgo_Gluer2::FillContainers(const TopAbs_ShapeEnum aType)
{
  Standard_Boolean bHasImage, bToReverse;
  Standard_Integer i, aNbW;
  TopoDS_Shape aWnew, aEnew;
  TopoDS_Iterator aItS;
  BRep_Builder aBB;
  TopTools_IndexedMapOfShape aMW;
  TopTools_MapOfShape aMFence;
  //
  myErrorStatus=0;
  myWarningStatus=0;
  //
  TopExp::MapShapes(myArgument, aType, aMW);
  //
  aNbW=aMW.Extent();
  for (i=1; i<=aNbW; ++i) {
    const TopoDS_Shape& aW=aMW(i);
    //
    if (!aMFence.Add(aW)) {
      continue;
    }
    //
    bHasImage=HasImage(aW);
    if (!bHasImage) {
      continue;
    }
    //
    GEOMAlgo_Tools3D::MakeContainer(aType, aWnew);
    aWnew.Orientation(aW.Orientation());
    //
    aItS.Initialize(aW);
    for (; aItS.More(); aItS.Next()) {
      const TopoDS_Shape& aE=aItS.Value();
      if (myOrigins.IsBound(aE)) {
        aEnew=myOrigins.Find(aE);
        //
        bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aEnew, aE, myContext);
        if (bToReverse) {
          aEnew.Reverse();
        }
        //
        aBB.Add(aWnew, aEnew);
      }
      else {
        aBB.Add(aWnew, aE);
      }
    }
    //
    //myImages / myOrigins
    TopTools_ListOfShape aLSD;
    //
    aLSD.Append(aW);
    myImages.Bind(aWnew, aLSD);
    myOrigins.Bind(aW, aWnew);
    //
  }//for (i=1; i<=aNbE; ++i) {
}
//=======================================================================
//function : BuildResult
//purpose  :
//=======================================================================
void GEOMAlgo_Gluer2::BuildResult()
{
  Standard_Boolean bHasImage;
  TopoDS_Shape aCnew, aCXnew;
  TopoDS_Iterator aItC;
  BRep_Builder aBB;
  //
  myErrorStatus=0;
  myWarningStatus=0;
  //
  aItC.Initialize(myArgument);
  for (; aItC.More(); aItC.Next()) {
    const TopoDS_Shape& aCx=aItC.Value();
    bHasImage=HasImage(aCx);
    if (bHasImage) {
      break;
    }
  }
  //
  if (!bHasImage) {
    myShape=myArgument;
    return;
  }
  //
  GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew);
  //
  aItC.Initialize(myArgument);
  for (; aItC.More(); aItC.Next()) {
    const TopoDS_Shape& aCX=aItC.Value();
    if (myOrigins.IsBound(aCX)) {
      aCXnew=myOrigins.Find(aCX);
      aCXnew.Orientation(aCX.Orientation());
      aBB.Add(aCnew, aCXnew);
    }
    else {
      aBB.Add(aCnew, aCX);
    }
  }
  //
  if (!myKeepNonSolids) {
    Standard_Integer i, aNb;
    TopoDS_Shape aCnew1;
    TopTools_IndexedMapOfShape aM;
    //
    GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew1);
    //
    TopExp::MapShapes(aCnew, TopAbs_SOLID, aM);

    aNb=aM.Extent();
    for (i=1; i<=aNb; ++i) {
      const TopoDS_Shape& aS=aM(i);
      aBB.Add(aCnew1, aS);
    }
    aCnew=aCnew1;
  }
  //
  myShape=aCnew;
}
      // Philippose - 17/01/2009
      // Sets the currently selected face
      void SetSelectedFace(int facenr)
      {
         face_sel_status = 0;

         if((facenr >= 1) && (facenr <= fmap.Extent()))
         {
            face_sel_status[facenr-1] = 1;
         }
      }
    void addFacesToSelection(Gui::View3DInventorViewer* /*viewer*/,
                             const Gui::ViewVolumeProjection& proj,
                             const Base::Polygon2d& polygon,
                             const TopoDS_Shape& shape)
    {
        try {
            TopTools_IndexedMapOfShape M;

            TopExp_Explorer xp_face(shape,TopAbs_FACE);
            while (xp_face.More()) {
                M.Add(xp_face.Current());
                xp_face.Next();
            }

            App::Document* appdoc = doc->getDocument();
            for (Standard_Integer k = 1; k <= M.Extent(); k++) {
                const TopoDS_Shape& face = M(k);

                TopExp_Explorer xp_vertex(face,TopAbs_VERTEX);
                while (xp_vertex.More()) {
                    gp_Pnt p = BRep_Tool::Pnt(TopoDS::Vertex(xp_vertex.Current()));
                    Base::Vector3d pt2d;
                    pt2d = proj(Base::Vector3d(p.X(), p.Y(), p.Z()));
                    if (polygon.Contains(Base::Vector2d(pt2d.x, pt2d.y))) {
#if 0
                        // TODO
                        if (isVisibleFace(k-1, SbVec2f(pt2d.x, pt2d.y), viewer))
#endif
                        {
                            std::stringstream str;
                            str << "Face" << k;
                            Gui::Selection().addSelection(appdoc->getName(), obj->getNameInDocument(), str.str().c_str());
                            break;
                        }
                    }
                    xp_vertex.Next();
                }

                //GProp_GProps props;
                //BRepGProp::SurfaceProperties(face, props);
                //gp_Pnt c = props.CentreOfMass();
                //Base::Vector3d pt2d;
                //pt2d = proj(Base::Vector3d(c.X(), c.Y(), c.Z()));
                //if (polygon.Contains(Base::Vector2d(pt2d.x, pt2d.y))) {
                //    if (isVisibleFace(k-1, SbVec2f(pt2d.x, pt2d.y), viewer)) {
                //        std::stringstream str;
                //        str << "Face" << k;
                //        Gui::Selection().addSelection(appdoc->getName(), obj->getNameInDocument(), str.str().c_str());
                //    }
                //}
            }
        }
        catch (...) {
        }
    }
//=======================================================================
//function : FillBRepShapes
//purpose  :
//=======================================================================
void GEOMAlgo_Gluer2::FillBRepShapes(const TopAbs_ShapeEnum theType)
{
  Standard_Boolean bHasImage, bIsToWork;
  Standard_Integer i, aNbE;
  TopoDS_Iterator aItS;
  TopoDS_Shape aEnew;
  TopTools_IndexedMapOfShape aME;
  TopTools_MapOfShape aMFence;
  TopTools_ListIteratorOfListOfShape aItLS;
  //
  myErrorStatus=0;
  myWarningStatus=0;
  //
  TopExp::MapShapes(myArgument, theType, aME);
  //
  aNbE=aME.Extent();
  for (i=1; i<=aNbE; ++i) {
    const TopoDS_Shape& aE=aME(i);
    //
    if (!aMFence.Add(aE)) {
      continue;
    }
    //
    bIsToWork=myOriginsToWork.IsBound(aE);
    bHasImage=HasImage(aE);
    if (!bHasImage && !bIsToWork) {
      continue;
    }
    //
    MakeBRepShapes(aE, aEnew);
    //
    //myImages / myOrigins
    if (bIsToWork) {
      const TopoDS_Shape& aSkey=myOriginsToWork.Find(aE);
      const TopTools_ListOfShape& aLSD=myImagesToWork.Find(aSkey);
      //
      myImages.Bind(aEnew, aLSD);
      //
      aItLS.Initialize(aLSD);
      for (; aItLS.More(); aItLS.Next()) {
        const TopoDS_Shape& aEx=aItLS.Value();
        myOrigins.Bind(aEx, aEnew);
        //
        aMFence.Add(aEx);
      }
    }
    else {
      TopTools_ListOfShape aLSD;
      //
      aLSD.Append(aE);
      myImages.Bind(aEnew, aLSD);
      myOrigins.Bind(aE, aEnew);
    }
  }//for (i=1; i<=aNbF; ++i) {
}
Exemple #14
0
int OCCSurface::get_loops( DLIList<OCCLoop*>& result_list )
{
  TopTools_IndexedMapOfShape M;
  TopExp::MapShapes(*myTopoDSFace, TopAbs_WIRE, M);
  int ii;
  for (ii=1; ii<=M.Extent(); ii++) {
     TopologyBridge *loop = OCCQueryEngine::instance()->occ_to_cgm(M(ii));
     result_list.append_unique(dynamic_cast<OCCLoop*>(loop));
  }
  return result_list.size();
}
Exemple #15
0
void OCCSurface::get_children_virt( DLIList<TopologyBridge*>& children )
{
  TopTools_IndexedMapOfShape M;
  TopExp::MapShapes(*myTopoDSFace, TopAbs_WIRE, M);
  int ii;
  for (ii=1; ii<=M.Extent(); ii++) {
     TopologyBridge *loop = OCCQueryEngine::instance()->occ_to_cgm(M(ii));
     if(loop)
       children.append_unique(loop);
  }
}
 // Philippose - 15/01/2009
 // Returns the local mesh size of a given face
 double GetFaceMaxH(int facenr)
 {
    if((facenr> 0) && (facenr <= fmap.Extent()))
    {
       return face_maxh[facenr-1];
    }
    else
    {
       return 0.0;
    }
 }
TopoDS_Edge GetEdge(const TopoDS_Shape &shape, int iEdge)
{
    TopTools_IndexedMapOfShape edgeMap;
    TopExp::MapShapes(shape, TopAbs_EDGE, edgeMap);
    
    if (iEdge < 0 || iEdge >= edgeMap.Extent()) {
        return TopoDS_Edge();
    }
    else {
        return TopoDS::Edge(edgeMap(iEdge+1));
    }
}
Exemple #18
0
int OCCFace::numFaces()
{
    TopTools_IndexedMapOfShape anIndices;
    const TopoDS_Shape& shp = this->getShape();
    if (shp.ShapeType() == TopAbs_FACE) {
        return 1;
    } else {
        // Shell
        TopExp::MapShapes(shp, TopAbs_FACE, anIndices);
        return anIndices.Extent();
    }
}
      // Philippose - 17/01/2009
      // Returns the index of the currently selected face
      int SelectedFace()
      {
         int i;

         for(i = 1; i <= fmap.Extent(); i++)
         {
            if(face_sel_status[i-1])
            {
               return i;
            }
         }

         return 0;
      }
Exemple #20
0
void OCCBody::get_all_curves(DLIList<OCCCurve*> &curves)
{
  TopoDS_Shape *shape;
  get_TopoDS_Shape(shape);

  TopTools_IndexedMapOfShape M;
  TopExp::MapShapes(*shape, TopAbs_EDGE, M);
  int ii;
  for (ii=1; ii<=M.Extent(); ii++) {
       TopologyBridge *curve = OCCQueryEngine::instance()->occ_to_cgm(M(ii));
       OCCCurve* occ_curve = CAST_TO(curve, OCCCurve);
       if (occ_curve)
         curves.append_unique(occ_curve);
  }
}
Exemple #21
0
   // Extract the face map from the OCC geometry
   // The face map basically gives an index to each face in the geometry, 
   // which can be used to access a specific face
   DLL_HEADER Ng_Result Ng_OCC_GetFMap(Ng_OCC_Geometry * geom, 
                                       Ng_OCC_TopTools_IndexedMapOfShape * FMap)
   {
      OCCGeometry* occgeom = (OCCGeometry*)geom;
      TopTools_IndexedMapOfShape *occfmap = (TopTools_IndexedMapOfShape *)FMap;

      // Copy the face map from the geometry to the given variable
      occfmap->Assign(occgeom->fmap);

      if(occfmap->Extent())
      {
         return NG_OK;
      }
      else
      {
         return NG_ERROR;
      }
   }
//=======================================================================
//function : IsGrowthWire
//purpose  : 
//=======================================================================
Standard_Boolean IsGrowthWire(const TopoDS_Shape& theWire,
			      const TopTools_IndexedMapOfShape& theMHE)
{
  Standard_Boolean bRet;
  TopoDS_Iterator aIt;
  // 
  bRet=Standard_False;
  if (theMHE.Extent()) {
    aIt.Initialize(theWire);
    for(; aIt.More(); aIt.Next()) {
      const TopoDS_Shape& aE=aIt.Value();
      if (theMHE.Contains(aE)) {
	return !bRet;
      }
    }
  }
  return bRet;
}
    Private(ViewProviderPartExt* vp) : ui(new Ui_TaskFaceColors()), view(0), vp(vp)
    {
        obj = vp->getObject();
        doc = Gui::Application::Instance->getDocument(obj->getDocument());

        // build up map edge->face
        TopTools_IndexedMapOfShape mapOfShape;
        TopExp_Explorer xp(static_cast<Part::Feature*>(obj)->Shape.getValue(), TopAbs_FACE);
        while (xp.More()) {
            mapOfShape.Add(xp.Current());
            xp.Next();
        }

        current = vp->DiffuseColor.getValues();
        if (current.empty())
            current.push_back(vp->ShapeColor.getValue());
        perface = current;
        perface.resize(mapOfShape.Extent(), perface.front());
    }
void collectConicEdges(const TopoDS_Shell &shell, TopTools_IndexedMapOfShape &map)
{
  TopTools_IndexedMapOfShape edges;
  TopExp::MapShapes(shell, TopAbs_EDGE, edges);
  
  for (int index = 1; index <= edges.Extent(); ++index)
  {
    const TopoDS_Edge &currentEdge = TopoDS::Edge(edges.FindKey(index));
    if (currentEdge.IsNull())
      continue;
    TopLoc_Location location;
    Standard_Real first, last;
    const Handle_Geom_Curve &curve = BRep_Tool::Curve(currentEdge, location, first, last);
    if (curve.IsNull())
      continue;
    if (curve->IsKind(STANDARD_TYPE(Geom_Conic)))
      map.Add(currentEdge);
  }
}
Exemple #25
0
/**
 * @briefAdds a shape to the IGES file. All faces are named according to their face
 * traits. If there are no faces, the wires are named according to the shape name.
 * 
 * The level parameter defines the iges layer/level, which is another way of grouping faces.
 */
void CTiglExportIges::AddToIges(PNamedShape shape, IGESControl_Writer& writer, int level) const 
{
    if (!shape) {
        return;
    }
    
    std::string shapeName = shape->Name();
    std::string shapeShortName = shape->ShortName();
    Handle(Transfer_FinderProcess) FP = writer.TransferProcess();
    TopTools_IndexedMapOfShape faceMap;
    TopExp::MapShapes(shape->Shape(),   TopAbs_FACE, faceMap);
    // any faces?
    if (faceMap.Extent() > 0) {
        int ret = writer.AddShape(shape->Shape());
        if (ret > IFSelect_RetDone) {
            throw CTiglError("Error: Export to IGES file failed in CTiglExportStep. Could not translate shape " 
                             + shapeName + " to iges entity,", TIGL_ERROR);
        }
        WriteIgesNames(FP, shape, level);
    }
    else {
        // no faces, export edges as wires
        Handle(TopTools_HSequenceOfShape) Edges = new TopTools_HSequenceOfShape();
        TopExp_Explorer myEdgeExplorer (shape->Shape(), TopAbs_EDGE);
        while (myEdgeExplorer.More()) {
            Edges->Append(TopoDS::Edge(myEdgeExplorer.Current()));
            myEdgeExplorer.Next();
        }
        ShapeAnalysis_FreeBounds::ConnectEdgesToWires(Edges, 1e-7, false, Edges);
        for (int iwire = 1; iwire <= Edges->Length(); ++iwire) {
            int ret = writer.AddShape(Edges->Value(iwire));
            if (ret > IFSelect_RetDone) {
                throw CTiglError("Error: Export to IGES file failed in CTiglExportIges. Could not translate shape " 
                                 + shapeName + " to iges entity,", TIGL_ERROR);
            }
            PNamedShape theWire(new CNamedShape(Edges->Value(iwire),shapeName.c_str()));
            theWire->SetShortName(shapeShortName.c_str());
            WriteIGESShapeNames(FP, theWire, level);
            WriteIgesWireName(FP, theWire);
        }
    }
}
      // Philippose - 15/01/2009
      // Sets the maximum mesh size for a given face
      // (Note: Local mesh size limited by the global max mesh size)
      void SetFaceMaxH(int facenr, double faceh)
      {
         if((facenr> 0) && (facenr <= fmap.Extent()))
         {
	   face_maxh[facenr-1] = min(mparam.maxh,faceh);
            
            // Philippose - 14/01/2010
            // If the face maxh is greater than or equal to the 
            // current global maximum, then identify the face as 
            // not explicitly controlled by the user any more
            if(faceh >= mparam.maxh)
            {
               face_maxh_modified[facenr-1] = 0;
            }
            else
            {
               face_maxh_modified[facenr-1] = 1;
            }
         }
      }
//=======================================================================
//function : PointProperties
//purpose  :
//=======================================================================
void PointProperties(const TopoDS_Shape& aS, GProp_GProps& aGProps)
{
  Standard_Integer i, aNbS;
  Standard_Real aDensity;
  gp_Pnt aPX;
  TopTools_IndexedMapOfShape aMS;
  //
  aDensity=1.;
  //
  TopExp::MapShapes(aS, TopAbs_VERTEX, aMS);
  aNbS=aMS.Extent();
  for (i=1; i<=aNbS; ++i) {
    GEOMAlgo_GProps aGPropsX;
    //
    const TopoDS_Vertex& aVX=*((TopoDS_Vertex*)&aMS(i));
    aPX=BRep_Tool::Pnt(aVX);
    aGPropsX.SetMass(1.);
    aGPropsX.SetCG(aPX);
    aGProps.Add(aGPropsX, aDensity);
  }
}
Exemple #28
0
void OCCBody::get_all_points(DLIList<OCCPoint*> &points)
{
  TopoDS_Shape *shape;
  get_TopoDS_Shape(shape);

  TopTools_IndexedMapOfShape M;
  TopExp::MapShapes(*shape, TopAbs_VERTEX, M);
  int ii;
  for (ii=1; ii<=M.Extent(); ii++) {
       TopologyBridge *vertex = OCCQueryEngine::instance()->occ_to_cgm(M(ii));
       OCCPoint* occ_point = CAST_TO(vertex, OCCPoint);
       if (occ_point)
         points.append_unique(occ_point);
  }

  DLIList<OCCSurface*> surfaces;
  this->get_all_surfaces(surfaces);
  for(int i = 0; i < surfaces.size(); i++)
  {
    OCCSurface* occ_surf = surfaces.get_and_step();
    points += occ_surf->get_hardpoints();
  }
}
Exemple #29
0
void OCC_Connect::PrintItemCount(TopoDS_Shape const &shape) const
{
    TopTools_IndexedMapOfShape imap;
    TopExp::MapShapes(shape,TopAbs_VERTEX,imap);
    cout << "Input map contains " << imap.Extent() << " vertices\n";
    imap.Clear();
    TopExp::MapShapes(shape,TopAbs_EDGE,imap);
    cout << "Input map contains " << imap.Extent() << " edges\n";
    imap.Clear();
    TopExp::MapShapes(shape,TopAbs_FACE,imap);
    cout << "Input map contains " << imap.Extent() << " faces\n";
    imap.Clear();
    TopExp::MapShapes(shape,TopAbs_SOLID,imap);
    cout << "Input map contains " << imap.Extent() << " solids\n";
    imap.Clear();
    TopExp::MapShapes(shape,TopAbs_COMPSOLID,imap);
    cout << "Input map contains " << imap.Extent() << " compsolids\n";
    imap.Clear();
    TopExp::MapShapes(shape,TopAbs_COMPOUND,imap);
    cout << "Input map contains " << imap.Extent() << " compounds\n";
}
//================================================================
// Function : TexturesExt_Presentation::sampleKitchen
// Purpose  : kitchen with texturized items in it.
//================================================================
void TexturesExt_Presentation::sampleKitchen()
{
  TopoDS_Shape aShape;

  if (!loadShape(aShape, "Kitchen\\Room.brep"))
    return;

  gp_Trsf aTrsf;
  gp_Ax3 NewCoordSystem (gp_Pnt(-1,-1, -1),gp_Dir(0,0,1));
  gp_Ax3 CurrentCoordSystem(gp_Pnt(0,0,0),gp_Dir(0,0,1));
  aTrsf.SetDisplacement(CurrentCoordSystem, NewCoordSystem);
  aShape.Location(TopLoc_Location(aTrsf));

  moveScale(aShape);

  // draw kitchen room whithout one wall (to better see the insides)
  TopTools_IndexedMapOfShape aFaces;
  TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
  Standard_Integer nbFaces = aFaces.Extent();

  // create a wooden kitchen floor
  // the floor's face will be textured with texture from chataignier.gif
  DISP(Texturize(aFaces(5),"plancher.gif",1,1,2,1));

  // texturize other faces of the room with texture from wallpaper.gif (walls)
  DISP(Texturize(aFaces(1),"wallpaper.gif",1,1,8,6));
  DISP(Texturize(aFaces(3),"wallpaper.gif",1,1,8,6));
  DISP(Texturize(aFaces(4),"wallpaper.gif",1,1,8,6));

//  DISP(drawShape(aFaces(1), Quantity_NOC_LIGHTPINK, Standard_False));
//  DISP(drawShape(aFaces(3), Quantity_NOC_LIGHTPINK, Standard_False));
//  DISP(drawShape(aFaces(4), Quantity_NOC_LIGHTPINK, Standard_False));

  // texturize furniture items with "wooden" texture
  if (loadShape(aShape, "Kitchen\\MODERN_Table_1.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Chair_1.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Cooker_1.brep"))
  {
    moveScale(aShape);

    aFaces.Clear();
    TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
    nbFaces = aFaces.Extent();

    for (Standard_Integer i = 1; i <= nbFaces; i++)
    {
      if (i >= 59)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_STEEL, Standard_False));
      else if (i >= 29)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_ALUMINIUM, Standard_False));
      else if (i == 28)
        DISP(Texturize(aFaces(i), "cookerplate.gif"));
      else  
        DISP(Texturize(aFaces(i), "chataignier.gif"));
    }
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Cooker_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Exhaust_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_STONE, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_MVCooker_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_SILVER, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_MVCooker_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_SILVER, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Sink_1.brep"))
  {
    moveScale(aShape);

    aFaces.Clear();
    TopExp::MapShapes(aShape, TopAbs_FACE, aFaces);  
    nbFaces = aFaces.Extent();

    for (Standard_Integer i = 1; i <= nbFaces; i++)
    {
      if (i < 145)
        DISP(drawShape(aFaces(i), Graphic3d_NOM_ALUMINIUM, Standard_False));
      else if (i == 145)
        DISP(Texturize(aFaces(i), "cookerplate.gif"));
      else  
        DISP(Texturize(aFaces(i), "chataignier.gif"));
    }
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Sink_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(Texturize(aShape, "chataignier.gif"));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Refrigerator_1.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_CHROME, Standard_False));
  }
  if (loadShape(aShape, "Kitchen\\MODERN_Refrigerator_1_opened.brep"))
  {
    moveScale(aShape);
    DISP(drawShape(aShape, Graphic3d_NOM_CHROME, Standard_False));
  }

  getViewer()->Update();
}