UNSOLVED : undo/redo problem and no file produced with app->saveas(...)

I am using opencascade for the first time. And I find some difficulties with OpenCascade Application Framework.

Can you help me for the following questions:

1. I want undo this transaction but : doc->GetAvailableUndos() give me zero

//transaction
doc->NewCommand();
TDF_Label a = TDF_TagSource::NewChild(doc->Main());

x = 7;
y = 7;
z = 7;
r = 7;
h = 7;

TDataStd_Real::Set(a.FindChild(1), r);
TDataStd_Real::Set(a.FindChild(2), h);
TDataStd_Real::Set(a.FindChild (3), x);
TDataStd_Real::Set(a.FindChild(4), y);
TDataStd_Real::Set(a.FindChild(5), z);
TDataStd_Name::Set(a, Name);
doc->NewCommand();
//end transaction

coutGetAvailableUndos()

2. I created a document but I can not save-it i.e No file produced

// Creating the document
Handle(TDocStd_Document) doc ;
app->NewDocument("XmlOcaf",doc);
....
app->SaveAs(doc, "file:\\C:\Documents\exemple.caf"); // No file produced

thanks in advance.

Bearloga's picture

1. Call SetUndoLimit method before any new transaction. By default it is 0 that means undo is disabled.

2. Your path name is invalid and C string is invalid (separators are treated as escape characters by compiler. The corrected one:

app->SaveAs(doc, "C:\\Documents\\exemple.caf");

OCC-ME's picture

thanks alot; 1. is solved
but ; 2. not yet

Handle(TDocStd_Application) app = new TOcaf_Application ();

// Creating the document
Handle(TDocStd_Document) doc ;
app->NewDocument("XmlOcaf",doc);

thanks

Umar Said's picture

There is a good example in OCC source for Windows in MFC section. If you want a quick start, below is my code. Hope it will help.

DEFINE_STANDARD_HANDLE(Application,TDocStd_Application)

class Application : public TDocStd_Application
{
public:
Application();
void Formats(TColStd_SequenceOfExtendedString& Formats) ;
Standard_CString ResourcesName() ;
friend Handle_Standard_Type& Application_Type_();
};

void Application::Formats(TColStd_SequenceOfExtendedString& Formats)
{
Formats.Append(TCollection_ExtendedString ("MyCAD"));
}

Standard_CString Application::ResourcesName()
{
return Standard_CString ("Resources");
}

Handle(TDocStd_Application) myApp;
Handle(TDocStd_Document) myDoc;

myApp = new Application();
myApp->NewDocument("MyCAD", myDoc);
myDoc->SetUndoLimit(1000);

myApp->SaveAs(myDoc, theFile);

=== Resources under res folder ===
formatlist:MyCAD

MyCAD.Description: MyCAD Document Version 1.0
MyCAD.FileExtension: mcd
MyCAD.StoragePlugin: ad696000-5b34-11d1-b5ba-00a0c9064368
MyCAD.RetrievalPlugin: ad696001-5b34-11d1-b5ba-00a0c9064368
MyCADSchema: ad696002-5b34-11d1-b5ba-00a0c9064368
MyCAD.AttributeStoragePlugin: 47b0b826-d931-11d1-b5da-00a0c9064368
MyCAD.AttributeRetrievalPlugin: 47b0b827-d931-11d1-b5da-00a0c9064368

=== run.sh ===
#!/bin/bash

export CASROOT=/opt/OpenCASCADE6.2.0/ros/
export LD_LIBRARY_PATH=/opt/OpenCASCADE6.2.0/ros/lin/lib/
export CSF_PluginDefaults=res
export CSF_ResourcesDefaults=res
./Linux/bin/mycad