String GetSelectedExtent() { ads_name selection; int returnValue = acedSSGet(_T("I"), NULL, NULL, NULL, selection); if (returnValue == RTCAN) return 0; if (returnValue != RTNORM) { return L""; } if (acedSSSetFirst(selection, NULL) != RTNORM) { acedSSFree(selection); return L""; } ads_name element; acedSSName(selection, 0, element); acedSSFree(selection); AcDbObjectId idEntity; if (acdbGetObjectId(idEntity, element) != Acad::eOk) { acedSSFree(element); return L""; } AcDbEntity * entity; if ((acdbGetObjectId(idEntity, element) != Acad::eOk) || (acdbOpenObject(entity, idEntity, AcDb::kForRead) != Acad::eOk)) { acedSSFree(element); return L""; } acedSSFree(element); if (!entity->isKindOf(AcDbPolyline::desc())) return L""; AcDbPolyline * poly = static_cast<AcDbPolyline*>(entity); if (!poly->isClosed()) return 0; String extent = L"POLYGON(("; AcGePoint2d start; AcGePoint2d current; for (int i = 0; i < poly->numVerts(); i++) { poly->getPointAt(i, current); if (i > 0) { extent += L", "; } else { start = current; } extent += Round(current.x, 0) + L" " + Round(current.y, 0); } if (!start.isEqualTo(current)) { extent += L", " + Round(start.x, 0) + L" " + Round(start.y, 0); } extent += L"))"; poly->close(); return extent; }
AcGePoint3dArray Additional_Class::Get_PolyLinePointArray( AcDbObjectId PolyLineId ) { AcGePoint3dArray LineCorner_List; AcDbIntArray Osnap_List, GeomID_List; AcDbEntity *pEnt_Temp = NULL; Acad::ErrorStatus es = acdbOpenAcDbEntity(pEnt_Temp, PolyLineId, AcDb::kForRead); if (es != Acad::eOk) { acutPrintf(_T("\nOPEN ENTITY ERROR ")); return LineCorner_List; } if (!pEnt_Temp->isKindOf(AcDbPolyline::desc())) { acutPrintf(_T("\nENETITY IS NOT POLYLINE")); return LineCorner_List; } AcDbPolyline *pPolyLine = AcDbPolyline::cast(pEnt_Temp); if (pPolyLine->getGripPoints(LineCorner_List, Osnap_List, GeomID_List) != Acad::eOk) { acutPrintf(_T("\nGET GRIP POINT ERROR!")); pPolyLine->close(); return LineCorner_List; } pPolyLine->close(); return LineCorner_List; }
AcDbObjectId CCalculation::ConvexHull(AcGePoint2dArray Points) { AcDbPolyline *CHull = new AcDbPolyline(); AcGePoint2dArray SortPoints = CCalculation::SortByLexi(Points); CHull->addVertexAt(); AcDbObjectId Convexhull = CCreateEnt::PostToModelSpace(CHull); return Convexhull; }
void Additional_Class::Get_PolyLineType( AcDbObjectId PolyLineId,LINEINFO &LineInfo_List ) { double PI=3.1415926535897932384626433832795; AcDbEntity *pEnt_Temp = NULL; Acad::ErrorStatus es = acdbOpenAcDbEntity(pEnt_Temp, PolyLineId, AcDb::kForRead); if (es != Acad::eOk) { acutPrintf(_T("\nOPEN POLYLINE ERROR")); return; } if (!pEnt_Temp->isKindOf(AcDbPolyline::desc())) { acutPrintf(_T("\nENTITY NOT POLYLINE")); return; } AcDbPolyline *pPolyLine = AcDbPolyline::cast(pEnt_Temp); int num = pPolyLine->numVerts(); LineInfo_List.push_back(""); for (int index=0; index<num; index++) { if (pPolyLine->segType(index) == AcDbPolyline::kLine) { CString tempStr_Line; tempStr_Line = "直线段"; LineInfo_List.push_back(tempStr_Line); } else if (pPolyLine->segType(index) == AcDbPolyline::kArc) { AcGeCircArc2d tempArc; pPolyLine->getArcSegAt(index,tempArc); double StartAngle = tempArc.startAng(); double EndAngle = tempArc.endAng(); double Angle = abs(EndAngle-StartAngle); Angle = (180/PI)*Angle; double Radius = tempArc.radius(); CString tempStr_Angle,tempStr_Radius,sita,du,banjing; sita = "θ="; du = "°"; banjing = "R="; tempStr_Angle.Format(_T("%.1f"),Angle); tempStr_Angle = sita+tempStr_Angle+du; tempStr_Radius.Format(_T("%.1f"),Radius); tempStr_Radius = banjing + tempStr_Radius; tempStr_Radius = tempStr_Angle+" "+tempStr_Radius; LineInfo_List.push_back(tempStr_Radius); } } }
CCadEntity * CCadEntityFactory::GetCadEntity(AcDbEntity * entity) { CCadEntity * cadEntity = 0; if (entity->isKindOf(AcDbPoint::desc()) || entity->isKindOf(AcDbText::desc()) || entity->isKindOf(AcDbMText::desc()) || entity->isKindOf(AcDbBlockReference::desc())) { cadEntity = new CCadPoint(entity); } else if (entity->isKindOf(AcDbLine::desc()) || entity->isKindOf(AcDbArc::desc()) || entity->isKindOf(AcDbSpline::desc())) { cadEntity = new CCadLine(entity); } else if (entity->isKindOf(AcDbEllipse::desc()) || entity->isKindOf(AcDbCircle::desc())) { cadEntity = new CCadPolygon(entity); } else if (entity->isKindOf(AcDb2dPolyline::desc())) { AcDb2dPolyline * e = AcDb2dPolyline::cast(entity); if (e->isClosed()) cadEntity = new CCadPolygon(entity); else cadEntity = new CCadLine(entity); } else if (entity->isKindOf(AcDbPolyline::desc())) { AcDbPolyline * e = AcDbPolyline::cast(entity); if (e->isClosed()) cadEntity = new CCadPolygon(entity); else cadEntity = new CCadLine(entity); } resbuf * data = entity->xData(APPNAME); if (data != NULL) cadEntity->SetData(CFeatureData(data->rbnext->resval.rstring)); acutRelRb(data); return cadEntity; }
void Additional_Class::Get_PolyLine_Point( AcDbObjectId PolyLineId,AcGePoint3dArray &PointArray ) { AcDbEntity *pEnt_Temp = NULL; Acad::ErrorStatus es = acdbOpenAcDbEntity(pEnt_Temp, PolyLineId, AcDb::kForRead); if (es != Acad::eOk) { acutPrintf(_T("\nOPEN POLYLINE ERROR")); return; } if (!pEnt_Temp->isKindOf(AcDbPolyline::desc())) { acutPrintf(_T("\nENTITY IS NOT POLYLINE")); return; } AcDbPolyline *pPolyLine = AcDbPolyline::cast(pEnt_Temp); int num = pPolyLine->numVerts(); AcGePoint3d Start_temp_PT,End_temp_PT; for (int index=0; index<num; index++) { if (pPolyLine->segType(index) == AcDbPolyline::kLine) { AcGeLineSeg3d tempLine; pPolyLine->getLineSegAt(index,tempLine); Start_temp_PT = tempLine.startPoint(); End_temp_PT = tempLine.endPoint(); PointArray.append(Start_temp_PT); PointArray.append(End_temp_PT); } else if (pPolyLine->segType(index) == AcDbPolyline::kArc) { AcGeCircArc2d tempArc; pPolyLine->getArcSegAt(index,tempArc); Start_temp_PT.set(tempArc.startPoint().x,tempArc.startPoint().y,0); End_temp_PT.set(tempArc.endPoint().x,tempArc.endPoint().y,0); PointArray.append(Start_temp_PT); PointArray.append(End_temp_PT); } } pEnt_Temp->close(); AcGeIntArray IndexArray; for (int i=1; i<PointArray.length();i++) { if (PointArray[i] == PointArray[i-1]) { IndexArray.append(i); PointArray.remove(PointArray[i]); } } }
void Additional_Class::Get_PolyLine_Length( AcDbObjectId PolyLineId, AcGeDoubleArray &LengthArray ) { double PI=3.1415926535897932384626433832795; AcDbEntity *pEnt_Temp = NULL; Acad::ErrorStatus es = acdbOpenAcDbEntity(pEnt_Temp, PolyLineId, AcDb::kForRead); if (es != Acad::eOk) { acutPrintf(_T("\nOPEN POLYLINE ERROR")); return; } if (!pEnt_Temp->isKindOf(AcDbPolyline::desc())) { acutPrintf(_T("\nENTITY NOT POLYLINE")); return; } AcDbPolyline *pPolyLine = AcDbPolyline::cast(pEnt_Temp); int num = pPolyLine->numVerts(); for (int index=0; index<num; index++) { if (pPolyLine->segType(index) == AcDbPolyline::kLine) { AcGeLineSeg3d tempLine; pPolyLine->getLineSegAt(index,tempLine); double LineLength = tempLine.length(); LengthArray.append(LineLength); } else if (pPolyLine->segType(index) == AcDbPolyline::kArc) { AcGeCircArc2d tempArc; pPolyLine->getArcSegAt(index,tempArc); double StartAngle = tempArc.startAng(); double EndAngle = tempArc.endAng(); double Angle = EndAngle-StartAngle; //Angle = (180/PI)*Angle; double Radius = tempArc.radius(); double ArcLength = Radius*Angle; LengthArray.append(ArcLength); } } LengthArray.insertAt(0,0); }
void AcDbDoubleClickEditPline::startEdit(AcDbEntity *pEnt, AcGePoint3d clickpt) { // Implement the startEdit notification handler to catch when // a user double-clicks a 'POLYLINE' entity // Get the Current Document AcApDocument *pDoc=acDocManager->curDocument(); AcDbPolyline *pLine; // Cast the AcDbEntity pointer to AcDbPolyline if(pEnt->isKindOf(AcDbPolyline::desc()) == Adesk::kTrue) pLine=AcDbPolyline::cast(pEnt); else { acutPrintf("Error: Invalid AcDbPolyline Object"); return; } acDocManager->lockDocument(pDoc,AcAp::kWrite); // Upgrade to write if(pLine->upgradeOpen()!=Acad::eOk) { acutPrintf("Error: Could Not open AcDbPolyline Object"); return; } // iterate through all the vertices to find which // segment was clicked on, and place a vertex there. for(unsigned int c=0;c<pLine->numVerts()-1;c++) { AcGePoint3d pt1,pt2; pLine->getPointAt(c,pt1); pLine->getPointAt(c+1,pt2); AcGeVector3d lineVec(pt2-pt1),clickVec(clickpt-pt1), clickVec2(pt2-clickpt); double ang=lineVec.angleTo(clickVec); // This is the filter... // .05 (5% of lineVec length) is an arbitrary length... if((sin(ang)*clickVec.length()<.05*lineVec.length()) && clickVec.length()<lineVec.length() && clickVec2.length()<lineVec.length()) { // Add the point Here! ads_point outPt; acdbWcs2Ecs(asDblArray(clickpt),outPt,asDblArray(pLine->normal()),Adesk::kFalse); pLine->addVertexAt(c+1,asPnt2d(outPt)); break; } } pLine->close(); acDocManager->unlockDocument(pDoc); // invoking acedSSSetFirst(NULL,NULL) here will clear the // pickfirst selection, if desired (not With pline though). //acedSSSetFirst(NULL,NULL); // Update the graphics... pLine->draw(); actrTransactionManager->flushGraphics(); acedUpdateDisplay(); }
bool Additional_Class::Get_LayerLW( CString LayerName, double &Length, double &Width ) { AcDbLayerTable *pLayerTbl = NULL; acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl,AcDb::kForRead); if (!pLayerTbl->has(LayerName)) { //acutPrintf("\n木有%s层!", LayerName); //SetError("THERE ISN`T"+LayerName+"LATYER!", "Get_LayerLW"); pLayerTbl->close(); return false; } AcDbObjectId layerId; pLayerTbl->getAt(LayerName, layerId); pLayerTbl->close(); AcDbBlockTable *pBlkTbl = NULL; ////获得当前数据库块表 acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite); ////获得模型空间块表记录 AcDbBlockTableRecord *pBlkTblRcd = NULL; pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead); pBlkTbl->close(); ////创建块表记录遍历器 AcDbBlockTableRecordIterator *pltr; pBlkTblRcd->newIterator(pltr); AcDbEntity *pEnt; //AcDbEntityPointer pEnt_Ptr; ////AcDbObjectPointer<AcDbPolyline> pPolyLine_Ptr; AcDbPolyline *pPolyLine = NULL; AcDbObjectIdArray PolyLineID_List; for (pltr->start(); !pltr->done(); pltr->step()) { pltr->getEntity(pEnt, AcDb::kForRead); // //pEnt_Ptr.acquire(pEnt); if (pEnt->layerId()==layerId) { if (pEnt->isKindOf(AcDbPolyline::desc())) { pPolyLine = AcDbPolyline::cast(pEnt); if (pPolyLine != NULL) { if (PolyLineIfRectangle(pPolyLine)==true) { PolyLineID_List.append(pPolyLine->objectId()); } } } } } if (PolyLineID_List.length() >1) { acutPrintf(_T("Bom Error 1002\n"));// 有很多矩形 delete pltr; pEnt->close(); pPolyLine->close(); pBlkTblRcd->close(); return false; } ////pPolyLine.open(PolyLineID_List[0], AcDb::kForRead); acdbOpenAcDbEntity(pEnt,PolyLineID_List[0], AcDb::kForRead); //error! pPolyLine = AcDbPolyline::cast(pEnt); Get_RectangleLW(pPolyLine, Length, Width); pBlkTblRcd->close(); pPolyLine->close(); pEnt->close(); delete pltr; return true; }
void Additional_Class::Get_ArcMiddle( AcDbObjectId PolyLineId, AcGePoint3dArray &Middle_List,AcGePoint3dArray &CenterListInput, LINEINFO &ArcInfoRList, LINEINFO &ArcInfoAList ) { double PI=3.1415926535897932384626433832795; AcDbEntity *pEnt_Temp = NULL; Acad::ErrorStatus es = acdbOpenAcDbEntity(pEnt_Temp, PolyLineId, AcDb::kForRead); if (es != Acad::eOk) { acutPrintf(_T("\nOPEN ENTITY ERROR")); return; } if (!pEnt_Temp->isKindOf(AcDbPolyline::desc())) { acutPrintf(_T("\nENTITY NOT POLYLINE")); return; } AcDbPolyline *pPolyLine = AcDbPolyline::cast(pEnt_Temp); int num = pPolyLine->numVerts(); AcGePoint3d Start_temp_PT,End_temp_PT; AcGePoint3dArray Center_List; for (int index=0; index<num; index++) { if (pPolyLine->segType(index) == AcDbPolyline::kArc) { AcGeCircArc2d tempArc; pPolyLine->getArcSegAt(index,tempArc); AcGePoint2d CenterPoint; CenterPoint = tempArc.center(); AcGePoint3d CenterPoint3d; CenterPoint3d.set(CenterPoint.x, CenterPoint.y, 0); Center_List.append(CenterPoint3d); AcGePoint3d Start_temp_PT, End_temp_PT; Start_temp_PT.set(tempArc.startPoint().x,tempArc.startPoint().y,0); End_temp_PT.set(tempArc.endPoint().x,tempArc.endPoint().y,0); AcGeVector3d tempVec; tempVec = End_temp_PT - Start_temp_PT; double tempVec_Len = tempVec.length(); tempVec.normalize(); tempVec = tempVec*(tempVec_Len/2); AcGeVector3d CenterVec; CenterVec = Start_temp_PT - CenterPoint3d; CenterVec = CenterVec + tempVec; AcGeLine2d CenterLine2d; AcGePoint3d Middle_Pt_OnLine; Middle_Pt_OnLine = CenterPoint3d+CenterVec; AcGePoint2d middle2d; middle2d.set(Middle_Pt_OnLine.x, Middle_Pt_OnLine.y); CenterLine2d.set(CenterPoint, middle2d); int s; AcGePoint2d MiddlePT, pt2; tempArc.intersectWith(CenterLine2d, s, MiddlePT, pt2); AcGePoint3d MiddlePoint; MiddlePoint.set(MiddlePT.x,MiddlePT.y,0); Middle_List.append(MiddlePoint); double StartAngle = tempArc.startAng(); double EndAngle = tempArc.endAng(); double Angle = EndAngle-StartAngle; Angle = (180/PI)*Angle; double Radius = tempArc.radius(); CString tempStr_Angle,tempStr_Radius,sita,du,banjing; sita = "θ="; du = "°"; banjing = "R="; tempStr_Angle.Format(_T("%.1f"),Angle); tempStr_Angle = sita+tempStr_Angle+du; tempStr_Radius.Format(_T("%.1f"),Radius); tempStr_Radius = banjing + tempStr_Radius; ArcInfoRList.push_back(tempStr_Radius); ArcInfoAList.push_back(tempStr_Angle); } } CenterListInput = Center_List; }
//----------------------------------------------------------------------------- // This function is called to update the entity based on the // input values // Adesk::Boolean AsdkRectangleJig::update() { AcGePoint2d adjustedPoint; AcGePoint3d tmpPoint; // Used by MAKEUCSCOORD macro. // We'll use the AcGeLine::intersectWith() function to infer the // remaining points. // AcGeLine3d lineX, lineY; lineX.set(m_TopLeftCorner, m_vecUnitX); lineY.set(m_BottomRightCorner, m_vecUnitY); // Top right corner is intersection of lineX and lineY. // lineX.intersectWith(lineY, m_TopRightCorner); lineX.set(m_BottomRightCorner, m_vecUnitX); lineY.set(m_TopLeftCorner, m_vecUnitY); // Bottom left corner is intersection of lineX and lineY. // lineX.intersectWith(lineY, m_BottomLeftCorner); AcGeVector3d tmpXVec, tmpYVec; // Check to see if we have flipped around the X or Y axis. // bool bXFlip = m_vecUnitX.dotProduct(m_TopLeftCorner - m_TopRightCorner) >0; bool bYFlip = m_vecUnitY.dotProduct(m_TopLeftCorner - m_BottomLeftCorner)<0; // If the rectangle is dragged into the first or third quadrant, // we need to reverse the sign of the bulge as well as reverse // the x and y direction vectors. // tmpXVec = bXFlip ? -1 * m_vecUnitX : m_vecUnitX; tmpYVec = bYFlip ? -1 * m_vecUnitY : m_vecUnitY; // Now update the polyline with the latest setting // if (plineInfo.m_cornerTreatment) { // We are going to fillet of chamfer this polyline rectangle. As such, // the constructor has added the extra points at the corners to allow // for there placement and bulge values to be updated on the fly. // If, during the dragging, the rectangle is still too small to show the // given radius or chamfer edges, the we will put the extra points in the // corners and set the bulges to 0.0, so the rectangle retains its // square corners until the user stretches the rectangle to a size large // enough to have the corner treatment displayed. // // Use temporaries to see if we're too small to show fillet/chamfer, so // we don't need to convert back to world. // AcGePoint2d point_TL, point_TR, point_BL; MAKEUCSCOORD(point_TL, m_TopLeftCorner); MAKEUCSCOORD(point_TR, m_TopRightCorner); MAKEUCSCOORD(point_BL, m_BottomLeftCorner); bool tooSmall = (point_TL.distanceTo(point_TR) < plineInfo.m_first + plineInfo.m_second) || (point_TL.distanceTo(point_BL) < plineInfo.m_first + plineInfo.m_second); if (tooSmall) { // Still to small to show the corner treatment. // m_pLWPoly->setBulgeAt(0, 0.0); MAKEUCSCOORD(adjustedPoint, m_TopLeftCorner); m_pLWPoly->setPointAt(0, adjustedPoint); m_pLWPoly->setPointAt(1, adjustedPoint); m_pLWPoly->setBulgeAt(2, 0.0); MAKEUCSCOORD(adjustedPoint, m_TopRightCorner); m_pLWPoly->setPointAt(2, adjustedPoint); m_pLWPoly->setPointAt(3, adjustedPoint); m_pLWPoly->setBulgeAt(4, 0.0); MAKEUCSCOORD(adjustedPoint, m_BottomRightCorner); m_pLWPoly->setPointAt(4, adjustedPoint); m_pLWPoly->setPointAt(5, adjustedPoint); m_pLWPoly->setBulgeAt(6, 0.0); MAKEUCSCOORD(adjustedPoint, m_BottomLeftCorner); m_pLWPoly->setPointAt(6, adjustedPoint); m_pLWPoly->setPointAt(7, adjustedPoint); } else { double tmpBulge; tmpBulge = ((!bXFlip && !bYFlip) || (bXFlip && bYFlip)) ? plineInfo.m_bulge : -plineInfo.m_bulge; // Now we will set adjustedPoint to the intersection of the rectangle // sides with the place where the new end points will be. // m_pLWPoly->setBulgeAt(0, tmpBulge); MAKEUCSCOORD(adjustedPoint, m_TopLeftCorner + (-plineInfo.m_first * tmpYVec)); m_pLWPoly->setPointAt(0, adjustedPoint); MAKEUCSCOORD(adjustedPoint, m_TopLeftCorner + plineInfo.m_second * tmpXVec); m_pLWPoly->setPointAt(1, adjustedPoint); m_pLWPoly->setBulgeAt(2, tmpBulge); MAKEUCSCOORD(adjustedPoint, m_TopRightCorner + (-plineInfo.m_first * tmpXVec)); m_pLWPoly->setPointAt(2, adjustedPoint); MAKEUCSCOORD(adjustedPoint, m_TopRightCorner + (-plineInfo.m_second * tmpYVec)); m_pLWPoly->setPointAt(3, adjustedPoint); m_pLWPoly->setBulgeAt(4, tmpBulge); MAKEUCSCOORD(adjustedPoint, m_BottomRightCorner + plineInfo.m_first * tmpYVec); m_pLWPoly->setPointAt(4, adjustedPoint); MAKEUCSCOORD(adjustedPoint, m_BottomRightCorner + (-plineInfo.m_second * tmpXVec)); m_pLWPoly->setPointAt(5, adjustedPoint); m_pLWPoly->setBulgeAt(6, tmpBulge); MAKEUCSCOORD(adjustedPoint, m_BottomLeftCorner + plineInfo.m_first * tmpXVec); m_pLWPoly->setPointAt(6, adjustedPoint); MAKEUCSCOORD(adjustedPoint, m_BottomLeftCorner + plineInfo.m_second * tmpYVec); m_pLWPoly->setPointAt(7, AcGePoint2d(adjustedPoint[X], adjustedPoint[Y])); } } else { // If this polyline is not having its corners treated, ie chamfered, or // filleted then simply update the corners. Since we knew this ahead of // time, the constructor did not add any extra verticies at the corners. // MAKEUCSCOORD(adjustedPoint, m_TopLeftCorner); m_pLWPoly->setPointAt(0, adjustedPoint); MAKEUCSCOORD(adjustedPoint, m_TopRightCorner); m_pLWPoly->setPointAt(1, adjustedPoint); MAKEUCSCOORD(adjustedPoint, m_BottomRightCorner); m_pLWPoly->setPointAt(2, adjustedPoint); MAKEUCSCOORD(adjustedPoint, m_BottomLeftCorner); m_pLWPoly->setPointAt(3, adjustedPoint); } return Adesk::kTrue; }
virtual Acad::ErrorStatus getOsnapInfo( AcDbEntity* pickedObject, Adesk::GsMarker gsSelectionMark, const AcGePoint3d& pickPoint, const AcGePoint3d& lastPoint, const AcGeMatrix3d& viewXform, AcArray<AcGePoint3d>& snapPoints, AcArray<int>& geomIdsForPts, AcArray<AcGeCurve3d*>& snapCurves, AcArray<int>& geomIdsForLines) { // Specialised implementation for AcDbPolylines: // Parametrisation of AcDbPolylines is different: each whole numbered paramater appears // at a vertex, so we cannot simply divide by three to get the correct parameter. // Protocol Extension insures that the following assertion is always // true, but check in non-prod versions just to be safe. assert( pickedObject->isKindOf( AcDbPolyline::desc() )); // but in production, a hard cast is fastest AcDbPolyline *pPline = (AcDbPolyline*)pickedObject; Acad::ErrorStatus es; if ( bSnapToSegments ) { // Snap to a third of each of the segments unsigned int numSegs = pPline->numVerts() - 1; AcGeLineSeg3d segLn; AcGeCircArc3d segArc; double startParam, endParam, newParam, dist; AcGePoint3d pt; for ( unsigned int idx = 0; idx < numSegs; idx++ ) { switch( pPline->segType( idx )) { case AcDbPolyline::kLine: es=pPline->getLineSegAt( idx, segLn ); startParam = segLn.paramOf( segLn.startPoint() ); endParam = segLn.paramOf( segLn.endPoint() ); snapPoints.append(segLn.evalPoint( startParam + ((endParam - startParam) / 3 ))); snapPoints.append(segLn.evalPoint( startParam + ((endParam - startParam) * 2 / 3 ))); break; case AcDbPolyline::kArc: es=pPline->getArcSegAt( idx, segArc ); startParam = segArc.paramOf( segArc.startPoint() ); endParam = segArc.paramOf( segArc.endPoint() ); dist = segArc.length( startParam, endParam ); newParam = segArc.paramAtLength( startParam, dist / 3 ); snapPoints.append( segArc.evalPoint( newParam )); newParam = segArc.paramAtLength( startParam, dist * 2 / 3 ); snapPoints.append( segArc.evalPoint( newParam )); break; default: break; } } } else { double endParam; AcGePoint3d pt; double dist; es=pPline->getEndParam( endParam ); es=pPline->getDistAtParam( endParam, dist ); es=pPline->getPointAtDist( dist / 3, pt ); assert(Acad::eOk==es); snapPoints.append( pt ); es=pPline->getPointAtDist( dist * 2 / 3, pt ); assert(Acad::eOk==es); snapPoints.append( pt ); if ( pPline->isClosed() ) { es=pPline->getStartPoint( pt ); snapPoints.append( pt ); } } return Acad::eOk; }
void extractVertexCoords(const AcDbObjectId& objID, std::map<std::wstring, AcGePoint3d>& m_3dPoints) { AcDbEntity* pEnt = nullptr; acdbOpenObject(pEnt, objID, AcDb::kForRead); /*****Pline****/ if (pEnt->isA() == AcDbPolyline::desc()) { AcDbPolyline* pLine = static_cast<AcDbPolyline*>(pEnt); pEnt->close(); acdbOpenObject(pLine, objID, AcDb::kForRead); AcGePoint3d vertex; for (LONGLONG i = 0; i < pLine->numVerts(); i++) { pLine->getPointAt(i, vertex); std::wstring w_nrPunct = std::to_wstring(i + 1); m_3dPoints.insert(std::pair<std::wstring, AcGePoint3d>(w_nrPunct, vertex)); } pLine->close(); } /******P2dLine****/ else if (pEnt->isA() == AcDb2dPolyline::desc()) { AcGePoint3d point; AcDbObjectId vertexID; AcDb3dPolylineVertex* pVertex = nullptr; AcDb2dPolyline* p2dline = static_cast<AcDb2dPolyline*>(pEnt); pEnt->close(); acdbOpenObject(p2dline, objID, AcDb::kForRead); AcDbObjectIterator* pIterator = p2dline->vertexIterator(); for (pIterator->start(); !pIterator->done(); pIterator->step()) { LONGLONG contor = 1; vertexID = pIterator->objectId(); acdbOpenObject(pVertex, vertexID, AcDb::kForRead); point = pVertex->position(); std::wstring w_nrPunct = std::to_wstring(contor); contor++; m_3dPoints.insert(std::pair<std::wstring, AcGePoint3d>(w_nrPunct, point)); pVertex->close(); } delete pIterator; p2dline->close(); } /***********P3dLine**************/ else if (pEnt->isA() == AcDb3dPolyline::desc()) { AcGePoint3d point; AcDbObjectId vertexID; AcDb3dPolylineVertex* pVertex = nullptr; AcDb3dPolyline* p3dline = static_cast<AcDb3dPolyline*>(pEnt); pEnt->close(); acdbOpenObject(p3dline, objID, AcDb::kForRead); AcDbObjectIterator* pIterator = p3dline->vertexIterator(); for (pIterator->start(); !pIterator->done(); pIterator->step()) { LONGLONG contor = 1; vertexID = pIterator->objectId(); acdbOpenObject(pVertex, vertexID, AcDb::kForRead); point = pVertex->position(); std::wstring w_nrPunct = std::to_wstring(contor); m_3dPoints.insert(std::pair<std::wstring, AcGePoint3d>(w_nrPunct, point)); pVertex->close(); } delete pIterator; p3dline->close(); } else { pEnt->close(); acutPrintf(_T("\nObiectul selectat nu este o polilinie")); } }
AcDbObjectId Additional_Class::Draw_Rectangle( AcGePoint2d stPt, double length, double height ) { AcDbPolyline *pPolyline = new AcDbPolyline(4); AcGePoint2d stPt1, stPt2, stPt3, stPt4; stPt1 = stPt; pPolyline->addVertexAt(0, stPt1, 0, 0, 0); stPt2.x = stPt.x +length; stPt2.y = stPt.y; pPolyline->addVertexAt(1, stPt2, 0, 0, 0); stPt3.x = stPt2.x; stPt3.y = stPt2.y + height; pPolyline->addVertexAt(2, stPt3, 0, 0, 0); stPt4.x = stPt3.x - length; stPt4.y = stPt3.y; pPolyline->addVertexAt(3, stPt4, 0, 0, 0); pPolyline->setClosed(Adesk::kTrue); AcDbBlockTable *pBlockTable = NULL; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); //this->Open_BlockTable(pBlockTable, NREADMODE); AcDbBlockTableRecord *pBlockTableRecord = NULL; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); //acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); //this->Open_ModelTableRecord(pBlockTableRecord, pBlockTable, NWRITEMODE); AcDbObjectId TempLineID; pBlockTableRecord->appendAcDbEntity(TempLineID, pPolyline); pPolyline->close(); pBlockTable->close(); pBlockTableRecord->close(); return TempLineID; }