>>可是圆心处没有标注
可能是你画歪了,哈哈。
好了,不开玩笑,我想可能是你API调用的顺序错了。
请试试下面的code, 我胡乱调了一下,就出来了。 :)
>>结果是没有投影
怕是你没有给正确的CATILinkableObject,
你用的是
CATILinkableObject_var spLink=pDocument;
piNewView->SetDoc(spLink);
这样得到的CATILinkableObject是不对的。
必须这样得到:
CATFrmEditor *pCurrFrmEditor = GetEditor();
CATPathElement oUIActPathElem = pCurrFrmEditor->GetUIActiveObject();
CATBaseUnknown* pCurrElemBase = oUIActPathElem.CurrentElement();
CATILinkableObject_var spLink(pCurrElemBase);
好了,试试我调过的code吧,在我这里是都出来了:
//Have to use this way to get the right CATILinkableObject
CATFrmEditor *pCurrFrmEditor = GetEditor();
CATPathElement oUIActPathElem = pCurrFrmEditor->GetUIActiveObject();
CATBaseUnknown* pCurrElemBase = oUIActPathElem.CurrentElement();
CATILinkableObject_var spLink(pCurrElemBase);
//
CATIEditor *poEditor=NULL;
CATSession *piSession=CATSession::GetPtrSession();
CATIIniInteractiveSession *piInteractiveSession=NULL;
HRESULT hr=piSession->QueryInterface(IID_CATIIniInteractiveSession,(void **)[$piInteractiveSession)]
hr=piInteractiveSession->New("Drawing", [$poEditor)]
CATFrmEditor* _editor2=poEditor->GetEditor();
CATDocument* pDoc =_editor2->GetDocument();
CATIDrawing *piDrawing = NULL;
CATIDftDocumentServices *piDftDocServices = NULL;
if (SUCCEEDED(pDoc->QueryInterface(IID_CATIDftDocumentServices, (void **)&piDftDocServices)))
{
piDftDocServices->GetDrawing(IID_CATIDrawing, (void **)[$piDrawing)]
piDftDocServices->Release();
}
// Gets the drawing container
CATISpecObject_var spDrawingSpec = piDrawing;
CATIContainer_var spDrawingCont = spDrawingSpec->GetFeatContainer();
// The drawing factory is implemented ont the drawing container
CATIDrwFactory_var spDrwFact = spDrawingCont;
// We do create a view with Make Up
CATIDftViewMakeUp *piNewViewMU = NULL;
spDrwFact->CreateViewWithMakeUp(IID_CATIDftViewMakeUp, (void **)[$piNewViewMU)]
// Get the view from the MakeUp
CATIView *piNewView = NULL;
piNewViewMU->GetView([$piNewView)]
// The view has to be typed: FrontView for Interactive view.
// CATILinkableObject_var spLink=pDocument;
//pDocument?三?的CATPart的指?,非空。
if(NULL_var==spLink)
{
cout << "spLink is NULL!" << endl;
}
piNewView->SetDoc(spLink);
piNewView->SetViewType(FrontView);
// spDrwFact->CreateProjectionCallout();
//spPlane?Part文件中的一个已知平面。
//CATPlane_var spPla=spPlane;
//CATMathPlane mathPlane;
CATMathPoint pt1(0,0,0), pt2(1,0,0), pt3(0,0,1);
CATMathPlane mathPlane(pt1,pt2,pt3);
/*
if(NULL_var!=spPla)
{
AfxMessageBox(L"NULL_var!=spPla");
spPla->GetAxis(mathPlane);
}
*/
CATIGenerSpec_var spGener(piNewView); //=piNewView->GetGenerSpec();
if(NULL_var!=spGener)
{
//AfxMessageBox(L"NULL_var!=spGener");
spGener->SetProjPlane(mathPlane);
} else{
cout << "spGener is NULL!" << endl;
}
CATISheet_var spSheet=piDrawing->GetCurrentSheet();
CATISheet *piNewSheet = spSheet; //Why???
piNewSheet->AddRef(); //So Addref is needed
piNewViewMU->SetPosition(100.0,50.0);
// Let's add the view to the sheet
piNewSheet->AddView(piNewViewMU);
piNewSheet->SetCurrentView(piNewView);
CATI2DWFFactory_var spGeomFactory(piNewView);
// Creation of a circle:
double center[2];
center[0]=100.0;
center[1]=150.0;
double radius = 50.0;
CATISpecObject_var Cercle = spGeomFactory->CreateCircle(center,radius);
CATIDrwAnnotationFactory_var spDrwAnnoFact=piNewView;
if(NULL_var!=spDrwAnnoFact)
{
//AfxMessageBox(L"NULL_var!=spDrwAnnoFact ");
CATUnicodeString textString("oint");
int titleLength = textString.GetLengthInChar();
CATIDescendants_var spDesc = piNewView;
CATListValCATISpecObject_var List;
spDesc->GetDirectChildren ("CATI2DCircle",List);
double center[2];
double rad;
CATI2DCircle_var my2DCir(List[1]);
my2DCir->GetCircleData(center,[$rad)]
CATIDrwText_var spText = spDrwAnnoFact->CreateDrwText(center[0],center[1],textString);
// Modify the properties
CATIDrwTextProperties_var spTextProp = spText;
// Modification of under part of the properties of the text
spText->SetParameterOnSubString(CATDrwUnderline, 1, titleLength, 1);
// Modification of the properties of the text as a whole
spTextProp->SetFontSize(12.5);
spTextProp->SetBold(TRUE);
spTextProp->SetFontColor(123,0,255,100);
// Refresh the text visualization
spTextProp->Refresh();
}
piNewView->Update(NULL_var);
// Memory cleaning
piDrawing->Release();
piNewSheet->Release();
piNewViewMU->Release();
piNewView->Release();
piInteractiveSession->Save(NULL); |