Acad::ErrorStatus PDSphere::subExplode(AcDbVoidPtrArray& entitySet) const #else Acad::ErrorStatus PDSphere::explode(AcDbVoidPtrArray& entitySet) const #endif { assertReadEnabled(); AcDb3dSolid *pBody; pBody = new AcDb3dSolid; if(pBody->createSphere(m_dRadius) != Acad::eOk) { delete pBody; return Acad::eNotApplicable; } AcGeMatrix3d mat; mat.setTranslation(m_ptCenter.asVector()); pBody->transformBy(mat); pBody->setPropertiesFrom(this); entitySet.append(pBody); return Acad::eOk; }
void asdktest6 () { int nPoints =8 ; int nTriangles =12 ; int nIndices =3 * nTriangles ; double p [] ={ 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1 } ; int i [] ={ 0, 1, 5, 0, 5, 4, 1, 6, 5, 1, 2, 6, 4, 5, 6, 4, 6, 7, 7, 0, 4, 7, 3, 0, 2, 0, 3, 2, 1, 0, 7, 6, 3, 6, 2, 3 } ; AcGeIntArray indices (nIndices) ; indices.setLogicalLength (nIndices) ; indices.setPhysicalLength (nIndices) ; memcpy (indices.asArrayPtr (), i, nIndices * sizeof (int)) ; AcGePoint3dArray gePts (nPoints) ; gePts.setLogicalLength (nPoints) ; gePts.setPhysicalLength (nPoints) ; memcpy (gePts.asArrayPtr (), p, nPoints * sizeof (AcGePoint3d)) ; void *acisBody =createBodyFromTriangles (gePts, indices) ; AcDb3dSolid *b =new AcDb3dSolid ; b->setASMBody(acisBody); AcDbObjectId id ; postToDatabase (NULL, b, id) ; }
// [9/5/2007 suzhiyong] Acad::ErrorStatus PDSphere::explodeTo3DSolid(AcDb3dSolid* &p3dSolid) const { assertReadEnabled(); AcDb3dSolid *pBody; pBody = new AcDb3dSolid; if(pBody->createSphere(m_dRadius) != Acad::eOk) { delete pBody; return Acad::eNotApplicable; } AcGeMatrix3d mat; mat.setTranslation(m_ptCenter.asVector()); pBody->transformBy(mat); pBody->setPropertiesFrom(this); p3dSolid = pBody; return Acad::eOk; }
void drawCylinder() { // 创建特定参数的圆柱体(实际上最后一个参数决定了实体是一个圆锥体还是圆柱) AcDb3dSolid *pSolid = new AcDb3dSolid(); pSolid->createFrustum(30, 10, 10, 10); // 将圆锥体添加到模型空间 PostToModelSpace(pSolid); //创建切面 AcGePlane plane; plane.set(AcGePoint3d(8,0,0),AcGeVector3d(1,0,0)); //得到实体与切面相切的截面 AcDbRegion *pSelectionRegion = NULL; pSolid->getSection(plane, pSelectionRegion); //将其移动到YZ平面 moveToBottom(pSelectionRegion); //将截面加入到模型空间 PostToModelSpace(pSelectionRegion); }
void hilitSolid() { Adesk::Boolean interrupted = Adesk::kFalse; ads_printf("\nSelect a solid"); Acad::ErrorStatus es = Acad::eOk; AcDb3dSolid *solid = NULL; AcDbEntity *ent = NULL; AcDbObjectId solidId; ads_name ename, sset; for (;;) { switch (ads_ssget(NULL, NULL, NULL, NULL, sset)) { case RTNORM: { struct resbuf *rb; if (ads_ssnamex(&rb, sset, 0) != RTNORM) { ads_ssfree(sset); return; } int sel_method; ads_name subname; short marker; AcGePoint3d pickpnt; AcGeVector3d pickvec; if (!extractEntityInfo(rb, sel_method, ename, subname, marker, pickpnt, pickvec)) { ads_ssfree(sset); return; } AOK(acdbGetObjectId(solidId, ename)); AOK(acdbOpenAcDbEntity(ent, solidId, AcDb::kForRead)); assert(ent != NULL); solid = AcDb3dSolid::cast(ent); if (solid == NULL) { ads_printf("\nNot a solid."); AOK(ent->close()); ads_ssfree(sset); continue; } int numPaths; AcDbFullSubentPath* subentPaths; AcGeMatrix3d xform; es = solid->getSubentPathsAtGsMarker( AcDb::kEdgeSubentType, marker, pickpnt, xform, numPaths, subentPaths); // For objects with no edges (such as a sphere) the code to // highlight an edge is meaningless and must be skipped. // if (numPaths > 0) { // Highlight and unhighlight the selected edge of the solid. // ads_printf("\nHighlighting the selected edge."); es = solid->highlight(subentPaths[0]); pressEnterToContinue(); es = solid->unhighlight(subentPaths[0]); } else ads_printf("\nNo edges to highlight."); delete []subentPaths; // Highlight and unhighlight the faces corresponding to the // first edge of the solid. // es = solid->getSubentPathsAtGsMarker( AcDb::kFaceSubentType, marker, pickpnt, xform, numPaths, subentPaths); for (int i = 0; i < numPaths; i++) { ads_printf("\nHighlighting face %d of %d", i + 1, numPaths); es = solid->highlight(subentPaths[i]); pressEnterToContinue(); es = solid->unhighlight(subentPaths[i]); } delete []subentPaths; ads_ssfree(sset); // Highlight the entire solid, then unhighlight it. // ads_printf("\nHighlighting the entire solid"); es = solid->highlight(); pressEnterToContinue(); es = solid->unhighlight(); } break; case RTNONE: case RTCAN: return; default: continue; } ads_ssfree(sset); break; } AOK(ent->close()); return; }
// [9/5/2007 suzhiyong] Acad::ErrorStatus PDEcone::explodeTo3DSolid(AcDb3dSolid* &p3dSolid) const { assertReadEnabled(); #ifdef _OBJECTARX2004_ Acad::ErrorStatus es = Acad::eOk; int i = 0; AcGeVector3d faceVect = getFaceVect(); AcDbCurve *pCurve = NULL; AcDbVoidPtrArray curveSegments; double pathLen = m_ptStart.distanceTo(m_ptEnd); AcGePoint3d sp, ep; double d1, d2; if(m_dDiameter1 >= m_dDiameter2) { sp = m_ptStart; ep = m_ptEnd; d1 = m_dDiameter1; d2 = m_dDiameter2; } else { sp = m_ptEnd; ep = m_ptStart; d1 = m_dDiameter2; d2 = m_dDiameter1; } //extrudeAlongPath函数在由较大region拉成较小region时容易产生自交问题,所以 //炸开时选择由小的region拉成大的region AcDbLine *pLine = new AcDbLine(ep, sp); pLine->setPropertiesFrom(this); pCurve = pLine; if(pCurve != NULL) { if((es = addToDb(pCurve)) == Acad::eOk) { AcDbObjectId id; id = pCurve->objectId(); pCurve->close(); if((es = acdbOpenObject((AcDbCurve*&)pCurve, id, AcDb::kForRead)) != Acad::eOk) return Acad::eNotApplicable; } else { if(pCurve != NULL) delete pCurve; return Acad::eNotApplicable; } } AcDbCircle sCir(ep, faceVect, d2 / 2.0); curveSegments.append(&sCir); AcDbVoidPtrArray regions; es = AcDbRegion::createFromCurves(curveSegments, regions); if(es == Acad::eOk && !regions.isEmpty()) { AcDb3dSolid *pBody; pBody = new AcDb3dSolid; ////求taper Angle //AcGeVector3d vec1 = (m_ptStart-m_ptEnd);//.normal(); ////m_dDiameter1和m_dDiameter2的大小问题 //AcGeVector3d perpVec = faceVect.perpVector()*((m_dDiameter1/2-m_dDiameter2/2)); //AcGePoint3d point2(m_ptStart.x+perpVec.x, m_ptStart.y+perpVec.y, m_ptStart.z+perpVec.z); //AcGeVector3d vec2 = (point2 - m_ptEnd);//.normal(); ////taperAngle为负时表示放大region,反之为缩小 //double angle = -1*vec1.angleTo(vec2); ////angle没有到达最大值时仍然有问题,建议不使用extrudeAlongPath函数 //taperAngle是指两个圆心连线垂直于圆面时的角度,大于0时表示缩小,小于0时表示放大 es = pBody->extrudeAlongPath((AcDbRegion*)(regions[0]), pCurve,//angle); -1*atan((d1 / 2.0 - d2 / 2.0) / pathLen)); if(es != Acad::eOk) { if(pCurve != NULL) { pCurve->upgradeOpen(); pCurve->erase(); pCurve->close(); } delete pBody; for(i = 0; i < regions.length(); i++) delete (AcRxObject*)regions[i]; return Acad::eNotApplicable; } pBody->setPropertiesFrom(this); p3dSolid = pBody; } else { if(pCurve != NULL) { pCurve->upgradeOpen(); pCurve->erase(); pCurve->close(); } for(i = 0; i < regions.length(); i++) delete (AcRxObject*)regions[i]; return Acad::eNotApplicable; } if(pCurve != NULL) { pCurve->upgradeOpen(); pCurve->erase(); pCurve->close(); } for(i = 0; i < regions.length(); i++) delete (AcRxObject*)regions[i]; return Acad::eOk; #else return Acad::eNotApplicable; #endif }
static Acad::ErrorStatus thickenPoly(AsdkPoly* poly,AcDbEntity*& ent, AcGePoint2d& savedCenter,AcGePoint2d& savedStartPoint, int& savedNumSides,AcGeVector3d& savedNormal,char* savedName, double& savedElevation) { Acad::ErrorStatus es = Acad::eOk; int i; AcDbVoidPtrArray lines; AcDbVoidPtrArray regions; // Explode to a set of lines // if ((es = poly->explode(lines)) != Acad::eOk) { for (i = 0; i < lines.length(); i++) { delete (AcRxObject*)lines[i]; } for (i = 0; i < regions.length(); i++) { delete (AcRxObject*)regions[i]; } return es; } // Create a region from the set of lines. // if ((es = AcDbRegion::createFromCurves(lines, regions)) != Acad::eOk) { for (i = 0; i < lines.length(); i++) { delete (AcRxObject*)lines[i]; } for (i = 0; i < regions.length(); i++) { delete (AcRxObject*)regions[i]; } return es; } assert(regions.length() == 1); AcDbRegion* region = AcDbRegion::cast((AcRxObject*)regions[0]); assert(region != NULL); // Extrude the region to create a solid. // double height; if ((es = poly->getDistAtParam(6.28318530717958647692, height)) != Acad::eOk) { for (i = 0; i < lines.length(); i++) { delete (AcRxObject*)lines[i]; } for (i = 0; i < regions.length(); i++) { delete (AcRxObject*)regions[i]; } return es; } height *= 0.25; AcDb3dSolid* solid = new AcDb3dSolid; assert(solid != NULL); if ((es = solid->extrude(region, height, 0.0)) != Acad::eOk) { delete solid; for (i = 0; i < lines.length(); i++) { delete (AcRxObject*)lines[i]; } for (i = 0; i < regions.length(); i++) { delete (AcRxObject*)regions[i]; } return es; } // Save up the data to flatten the solid. // savedCenter = poly->center(); savedStartPoint = poly->startPoint(); savedNumSides = poly->numSides(); savedNormal = poly->normal(); savedElevation = poly->elevation(); // Copy the poly name // strcpy(savedName, poly->name()); // Now we have a solid. Change the entity to be this solid if ((es = solid->setPropertiesFrom(poly)) != Acad::eOk) { delete solid; for (i = 0; i < lines.length(); i++) { delete (AcRxObject*)lines[i]; } for (i = 0; i < regions.length(); i++) { delete (AcRxObject*)regions[i]; } return es; } ent = poly; if ((es = ent->upgradeOpen()) != Acad::eOk) { delete solid; for (i = 0; i < lines.length(); i++) { delete (AcRxObject*)lines[i]; } for (i = 0; i < regions.length(); i++) { delete (AcRxObject*)regions[i]; } return es; } es = replaceEntity(ent, solid); if ((es != Acad::eOk) && (es != Acad::eObjectToBeDeleted)) { ent->downgradeOpen(); delete solid; for (i = 0; i < lines.length(); i++) { delete (AcRxObject*)lines[i]; } for (i = 0; i < regions.length(); i++) { delete (AcRxObject*)regions[i]; } return es; } es = ent->downgradeOpen(); for (i = 0; i < lines.length(); i++) { delete (AcRxObject*)lines[i]; } for (i = 0; i < regions.length(); i++) { delete (AcRxObject*)regions[i]; } return es; }
void polyeditCommand() { Adesk::Boolean interrupted = Adesk::kFalse; Adesk::Boolean done; Acad::ErrorStatus es = Acad::eOk; AcDbFullSubentPath nullSub; AcGePoint2d savedCenter; AcGePoint2d savedStartPoint; int savedNumSides; AcGeVector3d savedNormal; char savedName[133]; double savedElevation; // Select an AsdkPoly entity. AsdkPoly *poly = NULL; AcDb3dSolid *solid = NULL; AcDbObjectId objId; ads_name ename; ads_point ptres; AcDbEntity* ent; ads_name ss ; if ( acedSSGet ("_I", NULL, NULL, NULL, ss) == RTNORM ) { long n ; acedSSLength (ss, &n) ; switch ( n ) { case 0: //----- Not possible, but ? break ; case 1: acedSSName (ss, 0, ename) ; AOK(acdbGetObjectId(objId, ename)); AOK(acdbOpenAcDbEntity(ent, objId, AcDb::kForRead)); assert(ent != NULL); poly = AsdkPoly::cast(ent); if (poly == NULL) { acutPrintf("\nNot a polygon."); AOK(ent->close()); } break ; default: //----- If more than one entity selected, fallback in standard selection mode break ; } acedSSFree (ss) ; } while ( poly == NULL ) { switch (acedEntSel("\nSelect a poly: ", ename, ptres)) { case RTNORM: AOK(acdbGetObjectId(objId, ename)); AOK(acdbOpenAcDbEntity(ent, objId, AcDb::kForRead)); assert(ent != NULL); poly = AsdkPoly::cast(ent); if (poly == NULL) { acutPrintf("\nNot a polygon."); AOK(ent->close()); continue; } break; case RTNONE: case RTCAN: return; default: continue; } break; } // Now we have a polygon. Start editing it. char option[256]; done = Adesk::kFalse; interrupted = Adesk::kFalse; while (!done && !interrupted) { AOK(getEditOption(option,interrupted)); if (strcmp(option, "Grow") == 0) { if (!ent->isKindOf(AsdkPoly::desc())) { acutPrintf("\nNot Applicable"); continue; } AOK(growPoly(poly)); } else if (strcmp(option, "Shrink") == 0) { if (!ent->isKindOf(AsdkPoly::desc())) { acutPrintf("\nNot Applicable"); continue; } AOK(shrinkPoly(poly)); } else if (strcmp(option, "More") == 0) { if (!ent->isKindOf(AsdkPoly::desc())) { acutPrintf("\nNot Applicable"); continue; } AOK(morePoly(poly)); } else if (strcmp(option, "Less") == 0) { if (!ent->isKindOf(AsdkPoly::desc())) { acutPrintf("\nNot Applicable"); continue; } AOK(lessPoly(poly)); } else if (strcmp(option, "Thicken") == 0) { if (!ent->isKindOf(AsdkPoly::desc())) { acutPrintf("\nNot Applicable"); continue; } AOK(thickenPoly(poly, ent, savedCenter,savedStartPoint, savedNumSides,savedNormal,savedName,savedElevation)); solid = AcDb3dSolid::cast(ent); assert(solid != NULL); poly = NULL; solid->draw(); } else if (strcmp(option, "Flatten") == 0) { if (!ent->isKindOf(AcDb3dSolid::desc())) { acutPrintf("\nNot Applicable"); continue; } AOK(flattenPoly(solid,ent,savedCenter,savedStartPoint, savedNumSides,savedNormal,savedName,savedElevation)); poly = AsdkPoly::cast(ent); assert(poly != NULL); solid = NULL; } else if (strcmp(option, "Name") == 0) { if (!ent->isKindOf(AsdkPoly::desc())) { acutPrintf("\nNot Applicable"); continue; } Acad::ErrorStatus es; if ((es = namePoly(poly)) != Acad::eOk) { acutPrintf("\nError setting Poly's name. Error: %s", acadErrorStatusText(es)); done = Adesk::kTrue; continue; } if ((es = stylePoly(poly)) != Acad::eOk) { acutPrintf("\nError setting Poly's text style. Error: %s", acadErrorStatusText(es)); done = Adesk::kTrue; continue; } } else if (strcmp(option, "EXit") == 0) { done = Adesk::kTrue; } else { done = Adesk::kTrue; } } // Close the entity corresponding to the open for read right // after selection. AOK(ent->close()); }
static Acad::ErrorStatus makeSubentPath(const AcDbObject* pObj, const AcDbObjectIdArray& objIdList, const AcDb::SubentType& subType, const short& marker, const AcGePoint3d& pickpnt, AcDbFullSubentPath& subPath) { Acad::ErrorStatus acadReturnValue = Acad::eOk; AcGeMatrix3d xform(AcGeMatrix3d::kIdentity); int numIds = 0L; AcDbFullSubentPath* subentIds = NULL; // Check to see if entity is a supported solid, surface, region or body AcDb3dSolid* pSolid = NULL; AcDbSurface* pSurface = NULL; AcDbRegion* pRegion = NULL; AcDbBody* pBody = NULL; if ((pSolid = AcDb3dSolid::cast(pObj)) != NULL) { if (subType != AcDb::kNullSubentType) { acadReturnValue = pSolid->getSubentPathsAtGsMarker( subType, marker, pickpnt, xform, numIds, subentIds); if (subentIds == NULL) acadReturnValue = Acad::ePointNotOnEntity; if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n getSubentPathsAtGsMarker failed\n")); errorReport((AcBr::ErrorStatus)acadReturnValue); return acadReturnValue; } } objIds2SubPath(objIdList, subType, subentIds, subPath); } else if ((pSurface = AcDbSurface::cast(pObj)) != NULL) { if (subType != AcDb::kNullSubentType) { acadReturnValue = pSurface->getSubentPathsAtGsMarker( subType, marker, pickpnt, xform, numIds, subentIds); if (subentIds == NULL) acadReturnValue = Acad::ePointNotOnEntity; if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n getSubentPathsAtGsMarker failed\n")); errorReport((AcBr::ErrorStatus)acadReturnValue); return acadReturnValue; } } objIds2SubPath(objIdList, subType, subentIds, subPath); } else if ((pRegion = AcDbRegion::cast(pObj)) != NULL) { if (subType != AcDb::kNullSubentType) { acadReturnValue = pRegion->getSubentPathsAtGsMarker( subType, marker, pickpnt, xform, numIds, subentIds); if (subentIds == NULL) acadReturnValue = Acad::ePointNotOnEntity; if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n getSubentPathsAtGsMarker failed\n")); errorReport((AcBr::ErrorStatus)acadReturnValue); return acadReturnValue; } } objIds2SubPath(objIdList, subType, subentIds, subPath); } else if ((pBody = AcDbBody::cast(pObj)) != NULL) { if (subType != AcDb::kNullSubentType) { acadReturnValue = pBody->getSubentPathsAtGsMarker( subType, marker, pickpnt, xform, numIds, subentIds); if (subentIds == NULL) acadReturnValue = Acad::ePointNotOnEntity; if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n getSubentPathsAtGsMarker failed\n")); errorReport((AcBr::ErrorStatus)acadReturnValue); return acadReturnValue; } } objIds2SubPath(objIdList, subType, subentIds, subPath); } else { acutPrintf(ACRX_T("\n Selected object not a brep object\n")); return Acad::eWrongObjectType; } return acadReturnValue; }