Save, Open

Hello I'm having problems when I save a document as cbf OCAF ie BinOcaf. What happens is this keep the document close the software I open it and I can work on the document and even I can resave but when I try to reopen does not open me and returned me the method to open in PCDM_ReaderStatus is the 15 is a missing driver, have identified that the problem is given by a display driver that we use to display color differently lines and faces, what we did was a wrapper class and modify TPrsStd_NamedShapeDriver the update of this class. and if we add the driver gives me the behavior of my problem but if I take it all works well.

Here's the code.

wrapper

#include
#include

namespace cad
{
class ObjectNode;

class NamedShapeDriver : public TPrsStd_Driver
{
public:
NamedShapeDriver();

/**
* @brief Build the interactive object if it is null or update it.
* @details
* @return True If informations was found and the object was updated.
* @param label Is the constraint label.
* @param object Is the interactive object.
*/
Standard_Boolean Update(const TDF_Label& label,
Handle_AIS_InteractiveObject& object);

DEFINE_STANDARD_RTTI(NamedShapeDriver)

virtual ~NamedShapeDriver();

private:
void configureAttributes(Handle_AIS_InteractiveObject& object, ObjectNode node);
};
DEFINE_STANDARD_HANDLE(NamedShapeDriver, TPrsStd_Driver)
}

#endif /* NAMED_SHAPE_DRIVER_H_ */

Adding to the table display driver

void MainWindow::initializeDrivers()
{
Handle_NamedShapeDriver driverNS = new NamedShapeDriver();
TPrsStd_DriverTable::Get()->AddDriver(TNaming_NamedShape::GetID(), driverNS);
}

method open

PCDM_ReaderStatus Application::open(string path, Document* document)
{
int undoLimit = document->document->GetUndoLimit();

PCDM_ReaderStatus status = Open(path.c_str(), document->document);

document->document->SetUndoLimit(undoLimit);

return status;
}

Benjamin Bihler's picture

Hi,

I wonder whether you mix two things. If you introduce new attributes, you have to create your own presentation drivers to be able to display them. But to store them in a binary file, you would also have to create a BinMDF_ADriver. Might it be that you have not created these binary translation drivers yet?

Benjamin

Adrián Peña Peñate's picture

Hello.
We do not create any new attribute, just do wrapper TPrsStd_NamedShapeDriver, and reimplement the method update by changing the properties of the attributes that are already created, which not clear is whether we are creating While the wrapper of the kind mentioned, if we are agragando well, and now we're adding to the list of drivers TPrsStd_DriverTable presentation, and we are initializing a mainwindows.

This is the code update.

NamedShapeDriver::NamedShapeDriver()
{

}

Standard_Boolean NamedShapeDriver::Update(const TDF_Label& label,
Handle_AIS_InteractiveObject& object)
{
ObjectNode node = DocumentNodeFactory::createObjectNode(label);

if(!node.isValid())
return false;

if(node.shape().IsNull())
return false;

TopoDS_Shape shape = node.shape();

Handle_AIS_Shape aisShape;

if(object.IsNull())
{
aisShape = new AIS_Shape(shape);
}
else
{
aisShape = Handle_AIS_Shape::DownCast(object);

if(aisShape.IsNull())
{
aisShape = new AIS_Shape(shape);
}
else
{
TopoDS_Shape oldShape = aisShape->Shape();

if(oldShape != shape)
{
aisShape->ResetLocation();

aisShape->Set(shape);
aisShape->UpdateSelection();
aisShape->SetToUpdate();
}
}

aisShape->SetInfiniteState(shape.Infinite());
}

object = aisShape;

configureAttributes(object, node);

return true;
}

void NamedShapeDriver::configureAttributes(Handle_AIS_InteractiveObject& object, ObjectNode node)
{
if(object.IsNull())
return;

Handle_AIS_Shape aisShape = Handle_AIS_Shape::DownCast(object);

TopoDS_Shape shape = aisShape->Shape();

if(node.type() == DRAWING_OBJECT_NODE_TYPE)
{
cout << "Start" << endl;

object->SetColor(Quantity_NOC_GRAY);

object->SetMaterial(Graphic3d_NOM_CHROME);
object->SetDisplayMode(AIS_WireFrame);
}
else if(shape.ShapeType() == TopAbs_VERTEX)
{
Handle_AIS_Drawer drawer = object->Attributes();
Handle_Prs3d_PointAspect pointAspect;

if(((EntityNode&)node).getEntityClassification() == CONSTRUCTION_ENTITY)
{
pointAspect = new Prs3d_PointAspect(Aspect_TOM_STAR, Quantity_NOC_YELLOW, 2.5);
}
else if(((EntityNode&)node).getEntityClassification() == PROJECTED_ENTITY)
{
pointAspect = new Prs3d_PointAspect(Aspect_TOM_POINT, Quantity_NOC_YELLOW, 3.5);
}
else if(((EntityNode&)node).getEntityClassification() == SKETCH_ENTITY)
{
pointAspect = new Prs3d_PointAspect(Aspect_TOM_POINT, node.color(), 3.5);
}

if(((PointNode&) node).isCtrlPntOfBspline())
{
pointAspect = new Prs3d_PointAspect(Aspect_TOM_POINT, node.color(), 7);
}

drawer->SetPointAspect(pointAspect);
object->SetAttributes(drawer);
}
else if(shape.ShapeType() == TopAbs_EDGE)
{
Handle_AIS_Drawer drawer = object->Attributes();
Handle_Prs3d_LineAspect lineAspect;

if(((EntityNode&)node).getEntityClassification() == CONSTRUCTION_ENTITY)
{
lineAspect = new Prs3d_LineAspect(Quantity_NOC_YELLOW, Aspect_TOL_DOT, 1.5);
}
else if(((EntityNode&)node).getEntityClassification() == PROJECTED_ENTITY)
{
lineAspect = new Prs3d_LineAspect(Quantity_NOC_YELLOW, Aspect_TOL_SOLID, 3.5);
}
else if(((EntityNode&)node).getEntityClassification() == SKETCH_ENTITY)
{
lineAspect = new Prs3d_LineAspect(node.color(), Aspect_TOL_SOLID, 2.5);
}

drawer->SetWireAspect(lineAspect);
drawer->SetFreeBoundaryAspect(lineAspect);
drawer->SetUnFreeBoundaryAspect(lineAspect);
drawer->SetHiddenLineAspect(lineAspect);
object->SetAttributes(drawer);
}
else if(shape.ShapeType() == TopAbs_FACE)
{
Handle_AIS_Drawer drawer = object->Attributes();
Handle_Prs3d_ShadingAspect shadingAspect = drawer->ShadingAspect();

shadingAspect->SetColor(Quantity_NOC_GRAY1, Aspect_TOFM_BOTH_SIDE);

object->SetAttributes(drawer);

FaceNode faceNode = (FaceNode&) node;

if(faceNode.displayMode() == WIREFRAME_DISPLAY_MODE)
{
object->SetDisplayMode(AIS_WireFrame);
}
else
{
object->SetDisplayMode(AIS_Shaded);
}
}
else
{
Quantity_NameOfColor color = Quantity_NOC_GRAY;
Graphic3d_NameOfMaterial material = Graphic3d_NOM_CHROME;

object->SetColor(color);
object->SetMaterial(material);

if(node.type() == SOLID_NODE_TYPE)
{
SolidNode solidNode = (SolidNode&) node;

if(solidNode.isVisible())
{
if(solidNode.displayMode() == WIREFRAME_DISPLAY_MODE)
{
object->SetDisplayMode(AIS_WireFrame);
}
else
{
object->SetDisplayMode(AIS_Shaded);
}
}
}
}
}

NamedShapeDriver::~NamedShapeDriver()
{
}