Product : Engine, Version : 5.1.1.1039, ArticleID : 41024186

HowTo : Create a Polyface with a hole

Article41024186
TypeHowTo
ProductEngine
Version5.1.1.1039
Date Added1/11/2006
Submitted byTONY SHAW
Keywords

Subject

Create a Polyface with a hole

Summary

How can I Create a Polyface with a hole

Solution

The idea is to make a polyhatch from the curves so we can have a hole and after call the GetPolyface method to get the polyface object.
Then we save the Curve vertexes in the extended data of polyface .

    
 COlePointArray ptoutside;
 COlePointArray ptinside;
 CvdPolyhatch phatch;
 CvdFigure ploutside;
 CvdFigure plinside;

 //use the following if the curves already exist in the drawing
 //select first the outside polyline which already must exist in the drawing and then the second(inside) one.
 /*
 COlePoint pt;
 m_vdraw.Prompt(_T("Select outside Figure:"));
 ploutside = m_vdraw.GetUtility().GetEntity(&pt);
 

 m_vdraw.Prompt(_T("Select inside Figure:"));
 plinside = m_vdraw.GetUtility().GetEntity(&pt);
 */
 //else we dynamicaly create the outside and inside curves

 ploutside = (CvdFigure)m_vdraw.GetActiveDocument().GetEntities().AddCircle(COlePoint(0,0,0),10.0);
 plinside = (CvdFigure)m_vdraw.GetActiveDocument().GetEntities().AddCircle(COlePoint(0,0,0),5.0);
 
 long curveresolution = 128;
 
 
 ptoutside = ploutside.GetSamplePoints(curveresolution,0);
 if(ptoutside[ptoutside.GetSize()-1].Compare(ptoutside[0],1.0e-08) == false){
  ptoutside.Add(COlePoint(ptoutside[0]));
 }
 ptinside = plinside.GetSamplePoints(curveresolution,0);
 if(ptinside[ptoutside.GetSize()-1].Compare(ptinside[0],1.0e-08) == false){
  ptinside.Add(COlePoint(ptinside[0]));
 }

 //create a polyhatch to reproduce the hole
 phatch = m_vdraw.GetActiveDocument().GetActiveLayOut().GetEntities().AddPolyHatch();
 //add the sample points as polypath in the polyhatch of selected polylines
 phatch.AddPolyPath(0,ptoutside);
 phatch.AddPolyPath(0,ptinside);
 phatch.SetFillMode(1);
 
 //create a polyface from a polyhatch object
 CvdPolyface pface = phatch.GetPolyFace(curveresolution);
 m_vdraw.GetActiveDocument().GetActiveLayOut().GetEntities().AddItem(pface);
 phatch.Erase();//erase the polyhatch object
 
 //add the polyline vertexes in Extended data of the polyface object
 CvdXProperties xproperties =  pface.GetXProperties();
 xproperties.AddXProperty("NUMPOLYLINES",1070,COleInt(2));
 xproperties.AddXProperty("NUMPOINTS1",1070,COleInt(ptoutside.GetSize()));
 xproperties.AddXProperty("NUMPOINTS2",1070,COleInt(ptinside.GetSize()));
 int i;
 for( i = 0 ; i < ptoutside.GetSize(); i++)
 {
  xproperties.AddXProperty("VERTEX1",1011,ptoutside[i]);
 }
 for( i = 0 ; i < ptinside.GetSize(); i++)
 {
  xproperties.AddXProperty("VERTEX2",1011,ptinside[i]);
 }

 //redraw the polyface object
 pface.Update();
 pface.Invalidate();

 

 //shading the polyface object to see the result on the screen
 m_vdraw.GetCommandAction().View3D(COleVariant("VISW"));
 m_vdraw.GetCommandAction().View3D(COleVariant("SHADEON"));
 
 AfxMessageBox("Testing polyface with holes and xproperties");
 //getting the polylines from the extended data of polyface object
 CvdPolyline pl1;
 CvdPolyline pl2;
 CvdXProperty xprop;
 COlePointArray pts1;
 COlePointArray pts2;
 COlePoint ppt;
 xproperties =  pface.GetXProperties();
 xprop = xproperties.GetStart();
 while(xprop.m_lpDispatch != NULL){
  if(xprop.GetName() == "NUMPOLYLINES"){
  }else if(xprop.GetName() == "NUMPOINTS1"){
   pl1 = (CvdPolyline)m_vdraw.GetActiveDocument().GetEntities().AddPolyLine(pts1);
  }else if(xprop.GetName() == "NUMPOINTS2"){
   pl2 = (CvdPolyline)m_vdraw.GetActiveDocument().GetEntities().AddPolyLine(pts2);
  }else if(xprop.GetName() == "VERTEX1"){
   ppt = xprop.GetValue();
   pts1.Add(ppt);
  }else if(xprop.GetName() == "VERTEX2"){
   ppt = xprop.GetValue();
   pts2.Add(ppt);
  }
  xprop = xproperties.GetNext();
 }
 pl1.SetVertexList(pts1);
 pl2.SetVertexList(pts2);
 pl1.GetPenColor().SetColorIndex(5);
 pl2.GetPenColor().SetColorIndex(2);

 //erase all the other objects exept the polylines which used to produce the polyface
 pface.Erase();
 ploutside.Erase();
 plinside.Erase();

 //redraw the entire window
 m_vdraw.Redraw();