|
// UPDATE POLYLIGN DISPLAY ****************************************************************************************
void
updateDisplay()
{
// TEST 13/04/2106 -------------------------------------
// Open transaction --
acdbTransactionManagerPtr()->startTransaction();
// Update all polylign in modelspace
// Get RecordTable
AcDbBlockTableRecord *table(0);
if (acdbTransactionManagerPtr()->topTransaction()->getObject((AcDbObject *&)table, acdbHostApplicationServices()->workingDatabase()->currentSpaceId(), AcDb::kForWrite) == Acad::eOk)
{
if (table != 0)
{
AcDbBlockTableRecordIterator *it(0);
AcDbObjectId idEntite;
AcDbEntity *entite(0);
// New iterator
if (table->newIterator(it) == Acad::eOk)
{
for (it->start(); !it->done(); it->step())
{
it->getEntityId(idEntite); // Par transaction...
if ((acdbTransactionManagerPtr()->topTransaction()->getObject((AcDbObject *&)entite, idEntite, AcDb::kForWrite) == Acad::eOk))
{
if (entite != 0)
{
if (AcDbPolyline::cast(entite) != 0)
{
entite->recordGraphicsModified(true);
// Change color to see entity checked
AcCmColor couleur;
couleur.setColorIndex(60);
entite->setColor(couleur);
}
}
else
entite = 0;
}
}
delete it;
}
}
else
acedAlert(ACRX_T("Erreur de table"));
}
// Confirm Transaction --
acdbTransactionManagerPtr()->endTransaction();
// Moved outside transaction
// Update screen
AcTransactionManager *pAcTransactionManager = actrTransactionManager;
if (pAcTransactionManager)
{
pAcTransactionManager->queueForGraphicsFlush();
pAcTransactionManager->flushGraphics();
acedAlert(ACRX_T("Flush ok"));
}
acedUpdateDisplay(); // Moved outside transaction
}
// CURRENT LINE TYPE ****************************************************************************************
void
currentLine()
{
resbuf rb;
rb.restype = RTSTR;
rb.resval.rstring = ACRX_T("TypeLigneSpecial");
if (acedSetVar(_T("CELTYPE"), &rb) == RTNORM)
acedAlert(ACRX_T("Set current line to TypeLigneSpecial Ok"));
}
// LINE TYPE CREATION ****************************************************************************************
void
createLineType()
{
AcDbSymbolTable *table(0); //Table (ptr use for text & linetype)
AcDbObjectId idStyleTexte(0);
AcDbObjectId idLineType(0);
AcDbObjectId idPolylignExample(0);
// Open transaction --
acdbTransactionManagerPtr()->startTransaction();
// Create TextStyle --
AcDbTextStyleTableRecord *nouveauStyle = new AcDbTextStyleTableRecord;
nouveauStyle->setName(ACRX_T("StyleTexte")); // Name
nouveauStyle->setTextSize(1); // Size
// Enum are not in arx 2016
nouveauStyle->setFont(ACRX_T("Arial"), true, false, Charset::kDefaultCharset, Autodesk::AutoCAD::PAL::FontUtils::FontPitch::kDefault, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
// Get TextTable
if (acdbTransactionManagerPtr()->topTransaction()->getObject((AcDbObject *&)table, acdbHostApplicationServices()->workingDatabase()->textStyleTableId(), AcDb::kForWrite) == Acad::eOk)
{
if (table->add(idStyleTexte, nouveauStyle) == Acad::eOk) // Add in table
{
if (acdbTransactionManagerPtr()->addNewlyCreatedDBRObject(nouveauStyle) == Acad::eOk) // Add in transaction
{
// Ok
}
}
}
// Create LineType --
AcDbLinetypeTableRecord *nouveauTypeLigne = new AcDbLinetypeTableRecord;;
// Example line with 3 elements :
nouveauTypeLigne->setName(ACRX_T("TypeLigneSpecial"));
nouveauTypeLigne->setNumDashes(3); // Nombre de traits & vides
nouveauTypeLigne->setPatternLength(11); // Longueur de la ligne
nouveauTypeLigne->setDashLengthAt(0, 5); // 0 : Line
nouveauTypeLigne->setDashLengthAt(1, -2); // 1 : Empty
// Text
AcGeVector2d vectPosition(-1, -0.5);
// Ajout
nouveauTypeLigne->setShapeStyleAt(1, idStyleTexte);
nouveauTypeLigne->setShapeOffsetAt(1, vectPosition);
nouveauTypeLigne->setTextAt(1, ACRX_T("TEST"));
nouveauTypeLigne->setDashLengthAt(2, 4); // 2 : Line
// Add into linetype table --
if (acdbTransactionManagerPtr()->topTransaction()->getObject((AcDbObject *&)table, acdbHostApplicationServices()->workingDatabase()->linetypeTableId(), AcDb::kForWrite) == Acad::eOk)
{
if (table->add(idLineType, nouveauTypeLigne) == Acad::eOk) // Add in table
{
if (acdbTransactionManagerPtr()->addNewlyCreatedDBRObject(nouveauTypeLigne) == Acad::eOk) // Add in transaction
{
// Ok
}
}
}
// Add a example (polyline) --
AcDbPolyline *nouvellePolyligne = new AcDbPolyline(2); // (nombre de sommets)
AcGePoint2d pt0(10, 10);
AcGePoint2d pt1(70, 30);
nouvellePolyligne->addVertexAt(0, pt0);
nouvellePolyligne->addVertexAt(1, pt1);
nouvellePolyligne->setLinetype(idLineType); // LineType
AcDbBlockTableRecord *conteneur(0); // Conteneur
if (acdbTransactionManagerPtr()->topTransaction()->getObject((AcDbObject *&)conteneur, acdbHostApplicationServices()->workingDatabase()->currentSpaceId(), AcDb::kForWrite) == Acad::eOk)
{
if (conteneur->appendAcDbEntity(idPolylignExample, nouvellePolyligne) == Acad::eOk) // Ajout de l'objet dans son conteneur (r閏up de l'ID)
{
if (acdbTransactionManagerPtr()->addNewlyCreatedDBRObject(nouvellePolyligne, true) == Acad::eOk) // Ajout de l'objet avec la transaction
{
}
}
}
// Confirm Transaction --
acdbTransactionManagerPtr()->endTransaction();
// Open transaction --
acdbTransactionManagerPtr()->startTransaction();
// Modify LineType --
AcDbObject *obj(0);
AcDbLinetypeTableRecord *typeLigne(0);
if (acdbTransactionManagerPtr()->topTransaction()->getObject((AcDbObject *&)obj, idLineType, AcDb::kForWrite) == Acad::eOk) // Get linetype
{
typeLigne = AcDbLinetypeTableRecord::cast(obj); // Cast to typeline
if (typeLigne != 0)
{
typeLigne->setTextAt(1, ACRX_T("MODIF OK")); // Just modify the texte at shape 1
}
}
// Confirm Transaction --
acdbTransactionManagerPtr()->endTransaction();
}
// LINE TYPE MODIFICATION ****************************************************************************************
void
modifyLineType()
{
// Open transaction --
acdbTransactionManagerPtr()->startTransaction();
// Get the linetype table
AcDbSymbolTable *table(0); //Table (ptr use for text & linetype)
AcDbObjectId idLine(0);
if (acdbTransactionManagerPtr()->topTransaction()->getObject((AcDbObject *&)table, acdbHostApplicationServices()->workingDatabase()->linetypeTableId(), AcDb::kForRead) == Acad::eOk) // Get linetype
{
if (table->has(ACRX_T("TypeLigneSpecial")))
{
if (table->getAt(ACRX_T("TypeLigneSpecial"), idLine) == Acad::eOk)
{
acedAlert(ACRX_T("ID OK"));
// Modify LineType --
AcDbObject *obj(0);
AcDbLinetypeTableRecord *typeLigne(0);
if (acdbTransactionManagerPtr()->topTransaction()->getObject((AcDbObject *&)obj, idLine, AcDb::kForWrite) == Acad::eOk) // Get linetype
{
typeLigne = AcDbLinetypeTableRecord::cast(obj); // Cast to typeline
if (typeLigne != 0)
{
typeLigne->setTextAt(1, ACRX_T("DEUXIEME OK")); // Just modify the texte at shape 1
}
}
}
}
}
// Confirm Transaction --
acdbTransactionManagerPtr()->endTransaction();
} |
|