ObjectARX, AutoCAD. Среда программирования библиотеки C++



         

Перегрузка deepClone () Функция - часть 3


// Step 1: Create the clone.

//

AsdkPoly *pClone = (AsdkPoly*)isA()->create();

if (pClone != NULL)

pClonedObject = pClone; // Set the return value.

else

return Acad::eOutOfMemory;

// Step 2: Append the clone to its new owner. In this

// example, the original object is derived from AcDbEntity,

// so the owner is expected to be an AcDbBlockTableRecord,

// unless an ownership relationship is set up with another

// object. In that case, it is important to establish a

// connection to that owner. This sample shows a generic

// method using setOwnerId().

//

AcDbBlockTableRecord *pBTR =

AcDbBlockTableRecord::cast(pOwner);

if (pBTR != NULL) {

pBTR->appendAcDbEntity(pClone);

} else {

if (isPrimary)

return Acad::eInvalidOwnerObject;

// Some form of this code is only necessary if

// anyone has set up an ownership for the object

// other than with an AcDbBlockTableRecord.

//

pOwner->database()->addAcDbObject(pClone);

pClone->setOwnerId(pOwner->objectId());

}

// Step 3: Now contents are copied to the clone. This is done

// using an AcDbDeepCloneFiler. This filer keeps a list of all

// AcDbHardOwnershipIds and AcDbSoftOwnershipIds contained in

// the object and its derived classes. This list is then used

// to know what additional, "owned" objects need to be cloned

// below.

//

AcDbDeepCloneFiler filer;

dwgOut(&filer);

// Step 4: Rewind the filer and read the data into the clone.

//

filer.seek(0L, AcDb::kSeekFromStart);

pClone->dwgIn(&filer);

// Step 5: This must be called for all newly created objects

// in deepClone(). It is turned off by endDeepClone()

// after it has translated the references to their

// new values.

//

pClone->setAcDbObjectIdsInFlux();

// Step 6: Add the new information to the ID map. We can use

// the ID pair started above.

//

idPair.setValue(pClonedObject->objectId());

idPair.setIsCloned(Adesk::kTrue);

idMap.assign(idPair);

// Step 7: Using the filer list created above, find and clone




Содержание  Назад  Вперед