|
[code]//------------------------------------------------------------------------------
void Debug::Test()
//------------------------------------------------------------------------------
{
pErrorManager->InfoToLogFile(_T("\nTesting ... show area"));
Acad::ErrorStatus es = Acad::eOk;
AreaUnit AreaUnit;
AreaValue AreaVal;
UnitSettings* pUnitSettings = pApp->GetUnitSettings();
if (pUnitSettings != NULL)
{
pUnitSettings->GetUserUnit(&AreaUnit);
}
int mode = -1;
int stat;
int opt;
acedInitGet(RSG_NONULL, 0);
stat = acedGetInt(_T("\nSelect Show Area Option:\n 1) Show only\n 2) Show and label\n 3) Show and create\n 4) Show, label and create\nOption: "), &opt);
switch (stat)
{
case RTNORM:
{
switch (opt)
{
case 1: // Show only
case 2: // Show and label
case 3: // Show and create
case 4: // Show label and create
{
mode = opt;
} break;
default:
pApp->DisplayMessage(IDS_BAD_USER_TOOL);
break;
}
} break;
case RTKWORD:
case RTCAN:
{
return; // user cancelled
}
default:
{
pApp->DisplayMessage(IDS_BAD_USER_TOOL);
} break;
}
if (mode != -1)
{
AcCmColor colnew;
AcDb::LineWeight lwnew;
resbuf bufcolstart, buflwstart, bufhighlightcolor;
AcGePoint3d startpt;
acedInitGet(NULL, NULL);
AcArray<int> viewports;
AcGiTransientManager* pTransientManager = acgiGetTransientManager();
while (acedGetPoint(NULL, _T("\nSelect point in area: "), (double*)(&startpt)) == RTNORM)
{
CString sArea = _T("");
AcDbCurve* pCurve = NULL;
bool b;
// Only if we aren't adding the shape
if (mode == 1 || mode == 2)
{
b = pTransientManager->eraseTransients(kAcGiHighlight, 0, viewports);
acedUpdateDisplay();
}
AcDbVoidPtrArray Boundaries;
bool detectIslands = Adesk::kTrue;
es = acedTraceBoundary(startpt, detectIslands, Boundaries);
if (es == Acad::eOk)
{
double dAreaTotal = 0.0L, dMaxArea = 0.0L, dArea = 0.0L;
int nMaxIndx = -1;
// Subtract the islands
for (int i = 0; i < Boundaries.length(); i++)
{
// Only show transients if we aren't adding the shape
AcDbEntity* pEnt = NULL;
if (mode == 1 || mode == 2)
{
pEnt = static_cast<AcDbEntity *>(Boundaries[i]);
b = pTransientManager->addTransient(pEnt, kAcGiHighlight, 0, viewports);
acedUpdateDisplay();
}
// Get the area
AcBr::ErrorStatus bs = AcBr::eOk;
pCurve = static_cast<AcDbCurve *>(Boundaries[i]);
if (pCurve->isKindOf(AcDbRegion::desc()))
{
AcDbRegion* pRegion = static_cast<AcDbRegion *>(Boundaries[i]);
AcBrBrep* pBrep = new AcBrBrep();
if (AcBr::eOk == pBrep->set(*pRegion))
{
bs = pBrep->getSurfaceArea(dArea);
}
delete pBrep;
}
else
{
es = pCurve->getArea(dArea);
}
dAreaTotal += dArea;
if (dArea > dMaxArea)
{
dMaxArea = dArea;
nMaxIndx = i;
}
if (pEnt != NULL)
{
pEnt->close();
}
}
dArea = dMaxArea - (dAreaTotal - dMaxArea);
AreaUnit CurAreaUnit;
AcDb::UnitsValue ac_units = acdbCurDwg()->insunits();
if (ac_units == AcDb::kUnitsMeters)
{
CurAreaUnit.Construct(SQ_METRES);
}
else if (ac_units == AcDb::kUnitsFeet)
{
CurAreaUnit.Construct(SQ_FEET);
}
AreaVal.Construct(dArea, CurAreaUnit);
sArea.Format(_T(" %.3f %s (%.3f %s)"), AreaVal.GetConvertedValue(AreaUnit), AreaUnit.GetShortUnitString(),
AreaVal.GetConvertedValue(CurAreaUnit), CurAreaUnit.GetShortUnitString());
acutPrintf(sArea);
}
LONG lHandle;
CADManager.StartTransaction(__FUNCTION__);
// Add text label - but make sure to use the right boundary
if (mode == 2 || mode == 4)
{
LengthValue Height;
AngleValue Orient; Orient.Construct(0.0L, SYSTEM_ANGLE_UNITS);
AcGePoint3d pt;
AcGePoint2d extLo, extHi;
if (CurveInfo(pCurve, pt, extLo, extHi) == Acad::eOk)
{
Height.Construct((extHi.y - extLo.y) * 0.025, SYSTEM_LENGTH_UNITS);
}
else
{
AcDbExtents ex;
es = pCurve->getGeomExtents(ex);
pt.x = (ex.maxPoint().x + ex.minPoint().x) / 2.0L;
pt.y = (ex.maxPoint().y + ex.minPoint().y) / 2.0L;
Height.Construct((ex.maxPoint().y - ex.minPoint().y) * 0.025, SYSTEM_LENGTH_UNITS);
}
CADManager.AddText(lHandle, CADManager.ConvertPoint(pt), sArea, _T("Arial"), Height, Orient, CADManager::MIDDLE_CENTRE_JUSTIFY);
}
// Add a shape that defines the area
if (mode == 3 || mode == 4)
{
pCurve->setDatabaseDefaults();
AcDbObjectId lineId = AcDbObjectId::kNull;
pApp->GetTableRecord()->appendAcDbEntity(lineId, pCurve);
es = acdbTransactionManager->addNewlyCreatedDBRObject(pCurve);
CADManager.UpdateEntity(lineId);
}
CADManager.EndTransaction(__FUNCTION__);
acedInitGet(NULL, NULL);
}
// Transients should only be present if we aren't adding the shape
if (mode == 1 || mode == 2)
{
bool b = pTransientManager->eraseTransients(kAcGiHighlight, 0, viewports);
acedUpdateDisplay();
}
}
}
//------------------------------------------------------------------------------
Acad::ErrorStatus Debug::CurveInfo(AcDbCurve* pCurve, AcGePoint3d &ptCentroid, AcGePoint2d& extLow, AcGePoint2d& extHigh)
//------------------------------------------------------------------------------
{
Acad::ErrorStatus es = Acad::eOk;
AcDbVoidPtrArray lines1;
AcDbVoidPtrArray regions1;
AcDbRegion* pRegion;
if (pCurve->isKindOf(AcDbRegion::desc()))
{
pRegion = AcDbRegion::cast(pCurve);
}
else
{
lines1.append(pCurve);
es = AcDbRegion::createFromCurves(lines1, regions1);
if (regions1.isEmpty())
{
return es;
}
pRegion = AcDbRegion::cast((AcRxObject*)regions1[0]);
}
AcGePoint3d origin;
AcGeVector3d xAxis, yAxis;
AcGePlane plane;
pRegion->getPlane(plane);
plane.getCoordSystem(origin, xAxis, yAxis);
origin = AcGePoint3d(0.0, 0.0, origin.z);
xAxis = AcGeVector3d::kXAxis, yAxis = AcGeVector3d::kYAxis;
AcGePoint2d ptCen;
AcGePoint2d extentsLow, extentsHigh;
AcGeVector2d prinAxes[2];
double area, perimeter, momInertia[2], prodInertia, prinMoments[2], radiiGyration[2];
es = pRegion->getAreaProp(origin, xAxis, yAxis, perimeter, area, ptCen, momInertia, prodInertia, prinMoments, prinAxes, radiiGyration, extentsLow, extentsHigh);
if (Acad::eOk == es)
{
ptCentroid = AcGePoint3d(ptCen.x, ptCen.y, origin.z);
extLow = extentsLow;
extHigh = extentsHigh;
}
delete pRegion; pRegion = 0;
return es;
}[/code] |
|