Hello Roman,
thank you again. Unfortunately your last post didn't help. I checked everything again and again and again, but it won't work.
There aren't too many possible sources for the problem, though. The TDocStd_Document is valid. I created it after your blog, and everything works fine with that. The initialization of the V3d_Viewer, the AIS_InteractiveContext and the V3d_View are known to work in the simple non-OCAF way, as it is implemented in OCAF's qt-sample. So, I think this part also is correct.
I import data using the STEPCAFControl_Reader to the TDocStd_Document and call my UpdateView() function, which basically is what you posted in your last post above.
Here is step by step what I'm doing.
=====================================
// 1st: Create V3d_Viewer as in Qt-Sample from OCC
myViewer = new V3d_Viewer(defaultdevice,theName,theDomain,theViewSize,theViewProj,Standard_True,Standard_True);
// create collector the same way
// 2nd: Create AIS_InteractiveContext as in Qt-Sample, but with explicit collector
myContext = new AIS_InteractiveContext(myViewer, myCollector);
// 3rd: Create V3d_View as in Qt-Sample
myView = myContext->CurrentViewer()->CreateView();
Handle(Xw_Window) theXWindow = new Xw_Window(Handle(Graphic3d_GraphicDevice)::DownCast(theContext->CurrentViewer()->Device()), (int)
hi,(int)lo,Xw_WQ_SAMEQUALITY,Quantity_NOC_BLACK);
myView->SetWindow(theXWindow);
// using the above with standard AIS works fine
// 4th: Initialize TDocument and load STEP-File using STEPCAFControl_Reader
//TDocStd_Document loaded and verified, Document created as XmlXCAF as described in your OCC-Blog
//5th: update the view
void MyProgram::UpdateView()
{
Handle(AIS_InteractiveContext) theContext = myDoc->GetContext();
Handle(TDocStd_Document) theTDoc = myDoc->GetTDoc();
//mark: Init Visualization Drivers; without this part view doesn't show anything
Handle(XCAFPrs_Driver) aPrsDriver = new XCAFPrs_Driver();
TPrsStd_DriverTable::Get();
TPrsStd_DriverTable::Get()->InitStandardDrivers();
TPrsStd_DriverTable::Get()->AddDriver(XCAFPrs_Driver::GetID(), aPrsDriver);
Handle(TPrsStd_AISViewer) aTViewer;
TDF_Label rootLabel = theTDoc->GetData()->Root();
if (!TPrsStd_AISViewer::Find (rootLabel, theContext)) // test if viewer is added to TDoc
{
Handle(V3d_Viewer) aViewer = myViewer->GetViewer();
aTViewer = TPrsStd_AISViewer::New(rootLabel, aViewer);
}
//Update Visualization
Handle(XCAFDoc_ShapeTool) sTool = XCAFDoc_DocumentTool::ShapeTool(theTDoc->Main());
TDF_LabelSequence freeShapes;
sTool->GetFreeShapes(freeShapes);
for(Standard_Integer i=1; i<=freeShapes.Length(); i++)
{
TDF_Label curL = freeShapes.Value(i);
Handle(TPrsStd_AISPresentation) aPrs;
if (!curL.FindAttribute(TPrsStd_AISPresentation::GetID(), aPrs) )
{
aPrs = TPrsStd_AISPresentation::Set (curL, XCAFPrs_Driver::GetID());
aPrs->SetMaterial(Graphic3d_NOM_PLASTIC);
}
aPrs->SetMode (1);
aPrs->Display (Standard_False);
}
theContext->UpdateCurrentViewer();
//
AIS_ListOfInteractive ioList;
theContext->DisplayedObjects(ioList);
cout << "number of displayed objects : " << ioList.Extent() << endl;
}
Now, the problem is, that the above code does not create any AIS_InteractiveObjects in the V3d_Viewer. AIS_InteractiveContext::DisplayedObjects(AIS_ListOfInteractive& ...); returns an empty list of interactive objects.
Also, without the marked section (beginning with //mark) the view stays empty.
I could add the Interactive Objects manually to the Context, but that is followed by other problems and is not what I intent to do.
As I understand the marked section shouldn't be neccessary in the first place, since I never saw it anywhere except in one post in this forum. But if I leave it out nothing is displayed. Well, not that it is any good to see objects I can't interact with.
If you don't find any fundamental mistakes, I will give up on this for now and load the interactive objects manually to the context.
Best regards,
Author