mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0031990: Coding, Draw Harness - Replace C-like pointers to function in Draw_SaveAndRestore class to virtual function
Save/Restore interface has been moved to Draw_Drawable3D base class. Create a singleton Draw_Params class for DRAW parameters
This commit is contained in:
@@ -37,35 +37,8 @@ extern Draw_Viewer dout;
|
||||
extern Standard_Boolean Draw_Batch;
|
||||
#endif
|
||||
|
||||
class Draw_SaveAndRestore {
|
||||
|
||||
public :
|
||||
|
||||
Standard_EXPORT Draw_SaveAndRestore
|
||||
(const char* name,
|
||||
Standard_Boolean (*test)(const Handle(Draw_Drawable3D)&),
|
||||
void (*save)(const Handle(Draw_Drawable3D)&, std::ostream&),
|
||||
Handle(Draw_Drawable3D) (*restore) (std::istream&),
|
||||
Standard_Boolean display = Standard_True);
|
||||
|
||||
|
||||
const char* Name() const {return myName;}
|
||||
Standard_Boolean Test(const Handle(Draw_Drawable3D)&d);
|
||||
void Save(const Handle(Draw_Drawable3D)& d, std::ostream& os) const;
|
||||
Handle(Draw_Drawable3D) Restore(std::istream&) const;
|
||||
Standard_Boolean Disp() const {return myDisplay;}
|
||||
Draw_SaveAndRestore* Next() {return myNext;}
|
||||
|
||||
private :
|
||||
|
||||
const char* myName;
|
||||
Standard_Boolean (*myTest)(const Handle(Draw_Drawable3D)&);
|
||||
void (*mySave)(const Handle(Draw_Drawable3D)&, std::ostream&);
|
||||
Handle(Draw_Drawable3D) (*myRestore) (std::istream&);
|
||||
Standard_Boolean myDisplay;
|
||||
Draw_SaveAndRestore* myNext;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -14,33 +14,65 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
|
||||
#include <Draw_Display.hxx>
|
||||
#include <Draw_Drawable3D.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Draw_Drawable3D,Standard_Transient)
|
||||
#include <NCollection_DataMap.hxx>
|
||||
#include <Draw_Display.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Draw_Drawable3D, Standard_Transient)
|
||||
|
||||
//! Return the map of factory functions.
|
||||
static NCollection_DataMap<Standard_CString, Draw_Drawable3D::FactoryFunction_t>& getFactoryMap()
|
||||
{
|
||||
static NCollection_DataMap<Standard_CString, Draw_Drawable3D::FactoryFunction_t> myToolMap;
|
||||
return myToolMap;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RegisterFactory
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Draw_Drawable3D::RegisterFactory (const Standard_CString theType,
|
||||
const FactoryFunction_t& theFactory)
|
||||
{
|
||||
getFactoryMap().Bind (theType, theFactory);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Restore
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(Draw_Drawable3D) Draw_Drawable3D::Restore (const Standard_CString theType,
|
||||
Standard_IStream& theStream)
|
||||
{
|
||||
FactoryFunction_t aFactory = NULL;
|
||||
if (getFactoryMap().Find (theType, aFactory))
|
||||
{
|
||||
return aFactory (theStream);
|
||||
}
|
||||
return Handle(Draw_Drawable3D)();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Draw_Drawable3D
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Draw_Drawable3D::Draw_Drawable3D() :
|
||||
myXmin(0.0),
|
||||
Draw_Drawable3D::Draw_Drawable3D()
|
||||
: myXmin(0.0),
|
||||
myXmax(0.0),
|
||||
myYmin(0.0),
|
||||
myYmax(0.0),
|
||||
myName(NULL),
|
||||
isVisible(Standard_False),
|
||||
isProtected(Standard_False),
|
||||
myName(NULL)
|
||||
isProtected(Standard_False)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : PickReject
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Draw_Drawable3D::PickReject(const Standard_Real X,
|
||||
const Standard_Real Y,
|
||||
const Standard_Real Prec) const
|
||||
@@ -48,82 +80,40 @@ Standard_Boolean Draw_Drawable3D::PickReject(const Standard_Real X,
|
||||
return ((X+Prec < myXmin) || (X-Prec > myXmax) ||
|
||||
(Y+Prec < myYmin) || (Y-Prec > myYmax));
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Copy
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(Draw_Drawable3D) Draw_Drawable3D::Copy() const
|
||||
Handle(Draw_Drawable3D) Draw_Drawable3D::Copy() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Draw_Drawable3D::Dump(Standard_OStream& S) const
|
||||
void Draw_Drawable3D::Dump (Standard_OStream& S) const
|
||||
{
|
||||
S << myXmin << " " << myXmax << "\n";
|
||||
S << myYmin << " " << myYmax << "\n";
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Save
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Draw_Drawable3D::Save (Standard_OStream& ) const
|
||||
{
|
||||
throw Standard_NotImplemented ("Draw_Drawable3D::Save() should be redefined in sub-class");
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Whatis
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Draw_Drawable3D::Whatis(Draw_Interpretor& S) const
|
||||
{
|
||||
S << "drawable 3d";
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Is3D
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Draw_Drawable3D::Is3D() const
|
||||
{
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetBounds
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Draw_Drawable3D::SetBounds(const Standard_Real xmin,
|
||||
const Standard_Real xmax,
|
||||
const Standard_Real ymin,
|
||||
const Standard_Real ymax)
|
||||
{
|
||||
myXmin = xmin;
|
||||
myXmax = xmax;
|
||||
myYmin = ymin;
|
||||
myYmax = ymax;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Bounds
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Draw_Drawable3D::Bounds(Standard_Real& xmin,
|
||||
Standard_Real& xmax,
|
||||
Standard_Real& ymin,
|
||||
Standard_Real& ymax) const
|
||||
{
|
||||
xmin = myXmin;
|
||||
xmax = myXmax;
|
||||
ymin = myYmin;
|
||||
ymax = myYmax;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -17,28 +17,46 @@
|
||||
#ifndef _Draw_Drawable3D_HeaderFile
|
||||
#define _Draw_Drawable3D_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
#include <Standard_Real.hxx>
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <Standard_CString.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <Standard_IStream.hxx>
|
||||
#include <Standard_OStream.hxx>
|
||||
#include <Draw_Interpretor.hxx>
|
||||
|
||||
class Draw_Display;
|
||||
|
||||
|
||||
class Draw_Drawable3D;
|
||||
DEFINE_STANDARD_HANDLE(Draw_Drawable3D, Standard_Transient)
|
||||
|
||||
|
||||
class Draw_Drawable3D : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Draw_Drawable3D, Standard_Transient)
|
||||
public:
|
||||
|
||||
//! Function type for restoring drawable from stream.
|
||||
typedef Handle(Draw_Drawable3D)(*FactoryFunction_t)(Standard_IStream& theStream);
|
||||
|
||||
//! Register factory for restoring drawable from stream (opposite to Draw_Drawable3D::Save()).
|
||||
//! @param theType [in] class name
|
||||
//! @param theFactory [in] factory function
|
||||
Standard_EXPORT static void RegisterFactory (const Standard_CString theType,
|
||||
const FactoryFunction_t& theFactory);
|
||||
|
||||
//! Restore drawable from stream (opposite to Draw_Drawable3D::Save()).
|
||||
//! @param theType [in] class name
|
||||
//! @param theStream [in] input stream
|
||||
//! @return restored drawable or NULL if factory is undefined for specified class
|
||||
Standard_EXPORT static Handle(Draw_Drawable3D) Restore (const Standard_CString theType,
|
||||
Standard_IStream& theStream);
|
||||
|
||||
//! @def Draw_Drawable3D_FACTORY
|
||||
//! Auxiliary macros defining Draw_Drawable3D restoration API to sub-class.
|
||||
#define Draw_Drawable3D_FACTORY \
|
||||
static void RegisterFactory() { Draw_Drawable3D::RegisterFactory (get_type_name(), &Restore); } \
|
||||
Standard_EXPORT static Handle(Draw_Drawable3D) Restore (Standard_IStream& theStream);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Standard_EXPORT virtual void DrawOn (Draw_Display& dis) const = 0;
|
||||
|
||||
//! Returns True if the pick is outside the box
|
||||
@@ -49,61 +67,63 @@ public:
|
||||
|
||||
//! For variable dump.
|
||||
Standard_EXPORT virtual void Dump (Standard_OStream& S) const;
|
||||
|
||||
//! For variable whatis command. Set as a result the
|
||||
//! type of the variable.
|
||||
|
||||
//! Save drawable into stream; default implementation raises Standard_NotImplemented exception.
|
||||
Standard_EXPORT virtual void Save (Standard_OStream& theStream) const;
|
||||
|
||||
//! For variable whatis command. Set as a result the type of the variable.
|
||||
Standard_EXPORT virtual void Whatis (Draw_Interpretor& I) const;
|
||||
|
||||
//! Is a 3D object. (Default True).
|
||||
Standard_EXPORT virtual Standard_Boolean Is3D() const;
|
||||
|
||||
Standard_EXPORT void SetBounds (const Standard_Real xmin, const Standard_Real xmax, const Standard_Real ymin, const Standard_Real ymax);
|
||||
|
||||
Standard_EXPORT void Bounds (Standard_Real& xmin, Standard_Real& xmax, Standard_Real& ymin, Standard_Real& ymax) const;
|
||||
|
||||
Standard_Boolean Visible() const;
|
||||
|
||||
void Visible (const Standard_Boolean V);
|
||||
|
||||
Standard_Boolean Protected() const;
|
||||
|
||||
void Protected (const Standard_Boolean P);
|
||||
|
||||
Standard_CString Name() const;
|
||||
|
||||
virtual void Name (const Standard_CString N);
|
||||
virtual bool Is3D() const { return true; }
|
||||
|
||||
//! Return TRUE if object can be displayed.
|
||||
virtual bool IsDisplayable() const { return true; }
|
||||
|
||||
void SetBounds (const Standard_Real theXMin, const Standard_Real theXMax,
|
||||
const Standard_Real theYMin, const Standard_Real theYMax)
|
||||
{
|
||||
myXmin = theXMin;
|
||||
myXmax = theXMax;
|
||||
myYmin = theYMin;
|
||||
myYmax = theYMax;
|
||||
}
|
||||
|
||||
void Bounds (Standard_Real& theXMin, Standard_Real& theXMax,
|
||||
Standard_Real& theYMin, Standard_Real& theYMax) const
|
||||
{
|
||||
theXMin = myXmin;
|
||||
theXMax = myXmax;
|
||||
theYMin = myYmin;
|
||||
theYMax = myYmax;
|
||||
}
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Draw_Drawable3D,Standard_Transient)
|
||||
Standard_Boolean Visible() const { return isVisible; }
|
||||
|
||||
void Visible (const Standard_Boolean V) { isVisible = V; }
|
||||
|
||||
Standard_Boolean Protected() const { return isProtected; }
|
||||
|
||||
void Protected (const Standard_Boolean P) { isProtected = P; }
|
||||
|
||||
Standard_CString Name() const { return myName; }
|
||||
|
||||
virtual void Name (const Standard_CString N) { myName = N; }
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
Standard_EXPORT Draw_Drawable3D();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Standard_Real myXmin;
|
||||
Standard_Real myXmax;
|
||||
Standard_Real myYmin;
|
||||
Standard_Real myYmax;
|
||||
Standard_CString myName;
|
||||
Standard_Boolean isVisible;
|
||||
Standard_Boolean isProtected;
|
||||
Standard_CString myName;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#include <Draw_Drawable3D.lxx>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // _Draw_Drawable3D_HeaderFile
|
||||
|
@@ -1,46 +0,0 @@
|
||||
// Created on: 1995-02-28
|
||||
// Created by: Remi LEQUETTE
|
||||
// Copyright (c) 1995-1999 Matra Datavision
|
||||
// Copyright (c) 1999-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
inline Standard_Boolean Draw_Drawable3D::Visible() const
|
||||
{
|
||||
return isVisible;
|
||||
}
|
||||
|
||||
inline void Draw_Drawable3D::Visible(const Standard_Boolean V)
|
||||
{
|
||||
isVisible = V;
|
||||
}
|
||||
|
||||
inline Standard_Boolean Draw_Drawable3D::Protected() const
|
||||
{
|
||||
return isProtected;
|
||||
}
|
||||
|
||||
inline void Draw_Drawable3D::Protected(const Standard_Boolean V)
|
||||
{
|
||||
isProtected = V;
|
||||
}
|
||||
|
||||
inline Standard_CString Draw_Drawable3D::Name() const
|
||||
{
|
||||
return myName;
|
||||
}
|
||||
|
||||
inline void Draw_Drawable3D::Name(const Standard_CString N)
|
||||
{
|
||||
myName = N;
|
||||
}
|
||||
|
@@ -14,85 +14,81 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Draw_Number.hxx>
|
||||
|
||||
#include <Draw_Display.hxx>
|
||||
#include <Draw_Drawable3D.hxx>
|
||||
#include <Draw_Number.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Draw_Number,Draw_Drawable3D)
|
||||
|
||||
//=======================================================================
|
||||
//function : Draw_Number
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Draw_Number::Draw_Number(const Standard_Real V) :
|
||||
myValue(V)
|
||||
Draw_Number::Draw_Number (const Standard_Real theV)
|
||||
: myValue (theV)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Draw_Number::Value()const
|
||||
{
|
||||
return myValue;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Draw_Number::Value(const Standard_Real V)
|
||||
{
|
||||
myValue = V;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : DrawOn
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Draw_Number::DrawOn(Draw_Display&)const
|
||||
void Draw_Number::DrawOn (Draw_Display& ) const
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Copy
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(Draw_Drawable3D) Draw_Number::Copy()const
|
||||
Handle(Draw_Drawable3D) Draw_Number::Copy() const
|
||||
{
|
||||
Handle(Draw_Number) D = new Draw_Number(myValue);
|
||||
Handle(Draw_Number) D = new Draw_Number (myValue);
|
||||
return D;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Draw_Number::Dump(Standard_OStream& S)const
|
||||
void Draw_Number::Dump (Standard_OStream& S) const
|
||||
{
|
||||
S << myValue;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Save
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Draw_Number::Save (Standard_OStream& theStream) const
|
||||
{
|
||||
std::ios::fmtflags aFlags = theStream.flags();
|
||||
theStream.setf (std::ios::scientific);
|
||||
theStream.precision (15);
|
||||
theStream.width (30);
|
||||
theStream << myValue << "\n";
|
||||
theStream.setf (aFlags);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Restore
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(Draw_Drawable3D) Draw_Number::Restore (Standard_IStream& theStream)
|
||||
{
|
||||
Standard_Real aVal = RealLast();
|
||||
theStream >> aVal;
|
||||
Handle(Draw_Number) aNumb = new Draw_Number (aVal);
|
||||
return aNumb;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Whatis
|
||||
//purpose :
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Draw_Number::Whatis(Draw_Interpretor& S)const
|
||||
void Draw_Number::Whatis (Draw_Interpretor& S) const
|
||||
{
|
||||
S << "numeric";
|
||||
}
|
||||
|
@@ -17,68 +17,45 @@
|
||||
#ifndef _Draw_Number_HeaderFile
|
||||
#define _Draw_Number_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
#include <Standard_Real.hxx>
|
||||
#include <Draw_Drawable3D.hxx>
|
||||
#include <Standard_OStream.hxx>
|
||||
#include <Draw_Interpretor.hxx>
|
||||
class Draw_Display;
|
||||
class Draw_Drawable3D;
|
||||
|
||||
|
||||
class Draw_Number;
|
||||
DEFINE_STANDARD_HANDLE(Draw_Number, Draw_Drawable3D)
|
||||
|
||||
//! To store numbers in variables.
|
||||
class Draw_Number : public Draw_Drawable3D
|
||||
{
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Draw_Number, Draw_Drawable3D)
|
||||
Draw_Drawable3D_FACTORY
|
||||
public:
|
||||
|
||||
Standard_EXPORT Draw_Number (const Standard_Real theV);
|
||||
|
||||
Standard_Real Value() const { return myValue; }
|
||||
|
||||
void Value (const Standard_Real theV) { myValue = theV; }
|
||||
|
||||
Standard_EXPORT Draw_Number(const Standard_Real V);
|
||||
|
||||
Standard_EXPORT Standard_Real Value() const;
|
||||
|
||||
Standard_EXPORT void Value (const Standard_Real V);
|
||||
|
||||
//! Does nothhing,
|
||||
Standard_EXPORT void DrawOn (Draw_Display& dis) const Standard_OVERRIDE;
|
||||
|
||||
//! Does nothing,
|
||||
Standard_EXPORT virtual void DrawOn (Draw_Display& dis) const Standard_OVERRIDE;
|
||||
|
||||
//! Returns TRUE if object can be displayed.
|
||||
virtual bool IsDisplayable() const Standard_OVERRIDE { return false; }
|
||||
|
||||
//! For variable copy.
|
||||
Standard_EXPORT virtual Handle(Draw_Drawable3D) Copy() const Standard_OVERRIDE;
|
||||
|
||||
//! For variable dump.
|
||||
Standard_EXPORT virtual void Dump (Standard_OStream& S) const Standard_OVERRIDE;
|
||||
|
||||
//! For variable whatis command. Set as a result the
|
||||
//! type of the variable.
|
||||
|
||||
//! Save drawable into stream.
|
||||
Standard_EXPORT virtual void Save (Standard_OStream& theStream) const Standard_OVERRIDE;
|
||||
|
||||
//! For variable whatis command. Set as a result the type of the variable.
|
||||
Standard_EXPORT virtual void Whatis (Draw_Interpretor& I) const Standard_OVERRIDE;
|
||||
|
||||
|
||||
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Draw_Number,Draw_Drawable3D)
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Standard_Real myValue;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // _Draw_Number_HeaderFile
|
||||
|
@@ -14,7 +14,6 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
|
||||
#include <Draw.hxx>
|
||||
#include <Draw_Appli.hxx>
|
||||
#include <Draw_Axis2D.hxx>
|
||||
@@ -23,13 +22,13 @@
|
||||
#include <Draw_Drawable3D.hxx>
|
||||
#include <Draw_Grid.hxx>
|
||||
#include <Draw_Number.hxx>
|
||||
#include <Message.hxx>
|
||||
#include <Draw_ProgressIndicator.hxx>
|
||||
#include <Draw_SequenceOfDrawable3D.hxx>
|
||||
#include <Message.hxx>
|
||||
#include <NCollection_Map.hxx>
|
||||
#include <Standard_SStream.hxx>
|
||||
#include <Standard_Stream.hxx>
|
||||
#include <Standard_NotImplemented.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
#include <ios>
|
||||
@@ -67,195 +66,119 @@ static Standard_Integer p_Y;
|
||||
static Standard_Integer p_b;
|
||||
static const char* p_Name = "";
|
||||
|
||||
|
||||
static Draw_SaveAndRestore* Draw_First = NULL;
|
||||
|
||||
//=======================================================================
|
||||
//function : Draw_SaveAndRestore
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Draw_SaveAndRestore::Draw_SaveAndRestore
|
||||
(const char* name,
|
||||
Standard_Boolean (*test)(const Handle(Draw_Drawable3D)&),
|
||||
void (*save)(const Handle(Draw_Drawable3D)&, std::ostream&),
|
||||
Handle(Draw_Drawable3D) (*restore) (std::istream&),
|
||||
Standard_Boolean display) :
|
||||
myName(name),
|
||||
myTest(test),
|
||||
mySave(save),
|
||||
myRestore(restore),
|
||||
myDisplay(display),
|
||||
myNext(Draw_First)
|
||||
{
|
||||
Draw_First = this;
|
||||
}
|
||||
|
||||
Standard_Boolean Draw_SaveAndRestore::Test(const Handle(Draw_Drawable3D)&d)
|
||||
{return (*myTest) (d);}
|
||||
|
||||
void Draw_SaveAndRestore::Save(const Handle(Draw_Drawable3D)& d,
|
||||
std::ostream& os) const
|
||||
{ (*mySave) (d,os);}
|
||||
|
||||
Handle(Draw_Drawable3D) Draw_SaveAndRestore::Restore(std::istream& is) const
|
||||
{return (*myRestore) (is);}
|
||||
|
||||
//=======================================================================
|
||||
// numeric save and restore
|
||||
//=======================================================================
|
||||
|
||||
static Standard_Boolean numtest(const Handle(Draw_Drawable3D)& d)
|
||||
{
|
||||
return d->IsInstance(STANDARD_TYPE(Draw_Number));
|
||||
}
|
||||
|
||||
static void numsave (const Handle(Draw_Drawable3D)& theDrawable,
|
||||
std::ostream& theStream)
|
||||
{
|
||||
Handle(Draw_Number) aNum = Handle(Draw_Number)::DownCast (theDrawable);
|
||||
std::ios::fmtflags aFlags = theStream.flags();
|
||||
theStream.setf (std::ios::scientific);
|
||||
theStream.precision (15);
|
||||
theStream.width (30);
|
||||
theStream << aNum->Value() << "\n";
|
||||
theStream.setf (aFlags);
|
||||
}
|
||||
|
||||
static Handle(Draw_Drawable3D) numrestore (std::istream& is)
|
||||
{
|
||||
Standard_Real val;
|
||||
is >> val;
|
||||
Handle(Draw_Number) N = new Draw_Number(val);
|
||||
return N;
|
||||
}
|
||||
|
||||
|
||||
static Draw_SaveAndRestore numsr("Draw_Number",
|
||||
numtest,numsave,numrestore,
|
||||
Standard_False);
|
||||
|
||||
//=======================================================================
|
||||
// save
|
||||
//=======================================================================
|
||||
|
||||
static Standard_Integer save(Draw_Interpretor& di, Standard_Integer n, const char** a)
|
||||
static Standard_Integer save (Draw_Interpretor& theDI,
|
||||
Standard_Integer theNbArgs,
|
||||
const char** theArgVec)
|
||||
{
|
||||
if (n < 3)
|
||||
if (theNbArgs != 3)
|
||||
{
|
||||
di << "Syntax error: wrong number of arguments!\n";
|
||||
di.PrintHelp(a[0]);
|
||||
theDI << "Syntax error: wrong number of arguments!\n";
|
||||
theDI.PrintHelp (theArgVec[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* name = a[2];
|
||||
std::ofstream os;
|
||||
os.precision(15);
|
||||
OSD_OpenStream(os, name, std::ios::out);
|
||||
if (!os.is_open() || !os.good())
|
||||
Handle(Draw_Drawable3D) aDrawable = Draw::Get (theArgVec[1]);
|
||||
if (aDrawable.IsNull())
|
||||
{
|
||||
di << "Cannot open file for writing "<<name;
|
||||
theDI << "Syntax error: '" << theArgVec[1] << "' is not a drawable";
|
||||
return 1;
|
||||
}
|
||||
|
||||
Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
|
||||
if (!D.IsNull()) {
|
||||
// find a tool
|
||||
Draw_SaveAndRestore* tool = Draw_First;
|
||||
Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 );
|
||||
|
||||
while (tool) {
|
||||
if (tool->Test(D)) break;
|
||||
tool = tool->Next();
|
||||
}
|
||||
if (tool) {
|
||||
os << tool->Name() << "\n";
|
||||
Draw::SetProgressBar(progress);
|
||||
tool->Save(D,os);
|
||||
os << "\n";
|
||||
}
|
||||
else {
|
||||
di << "No method for saving " << a[1];
|
||||
return 1;
|
||||
}
|
||||
Draw::SetProgressBar( 0 );
|
||||
const char* aName = theArgVec[2];
|
||||
std::ofstream aStream;
|
||||
aStream.precision (15);
|
||||
OSD_OpenStream (aStream, aName, std::ios::out);
|
||||
if (!aStream.is_open() || !aStream.good())
|
||||
{
|
||||
theDI << "Error: cannot open file for writing " << aName;
|
||||
return 1;
|
||||
}
|
||||
|
||||
os << "0\n\n";
|
||||
|
||||
Standard_Boolean res = Standard_False;
|
||||
try
|
||||
{
|
||||
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
|
||||
Standard_CString aToolTypeName = aDrawable->DynamicType()->Name();
|
||||
aStream << aToolTypeName << "\n";
|
||||
Draw::SetProgressBar (aProgress);
|
||||
aDrawable->Save (aStream);
|
||||
}
|
||||
catch (const Standard_NotImplemented& )
|
||||
{
|
||||
theDI << "Error: no method for saving " << theArgVec[1];
|
||||
return 1;
|
||||
}
|
||||
aStream << "\n";
|
||||
aStream << "0\n\n";
|
||||
Draw::SetProgressBar (Handle(Draw_ProgressIndicator)());
|
||||
|
||||
errno = 0;
|
||||
|
||||
res = os.good() && !errno;
|
||||
if( !res )
|
||||
const Standard_Boolean aRes = aStream.good() && !errno;
|
||||
if (!aRes)
|
||||
{
|
||||
di<<"File has not been written";
|
||||
theDI << "Error: file has not been written";
|
||||
return 1;
|
||||
}
|
||||
|
||||
di << a[1];
|
||||
theDI << theArgVec[1];
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// read
|
||||
//=======================================================================
|
||||
|
||||
static Standard_Integer restore(Draw_Interpretor& di, Standard_Integer n, const char** a)
|
||||
static Standard_Integer restore (Draw_Interpretor& theDI,
|
||||
Standard_Integer theNbArgs,
|
||||
const char** theArgVec)
|
||||
{
|
||||
|
||||
if (n <= 2) return 1;
|
||||
|
||||
const char* fname = a[1];
|
||||
const char* name = a[2];
|
||||
|
||||
std::filebuf fic;
|
||||
std::istream in(&fic);
|
||||
OSD_OpenStream (fic, fname, std::ios::in);
|
||||
if (!fic.is_open()) {
|
||||
di << "Cannot open file for reading : "<<fname;
|
||||
if (theNbArgs != 3)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* aFileName = theArgVec[1];
|
||||
const char* aVarName = theArgVec[2];
|
||||
|
||||
char typ[255];
|
||||
in >> typ;
|
||||
if (!in.fail()) {
|
||||
// search a tool
|
||||
Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 );
|
||||
Draw::SetProgressBar(progress);
|
||||
std::filebuf aFileBuf;
|
||||
std::istream aStream (&aFileBuf);
|
||||
OSD_OpenStream (aFileBuf, aFileName, std::ios::in);
|
||||
if (!aFileBuf.is_open())
|
||||
{
|
||||
theDI << "Error: cannot open file for reading: '" << aFileName << "'";
|
||||
return 1;
|
||||
}
|
||||
|
||||
Draw_SaveAndRestore* tool = Draw_First;
|
||||
Draw_SaveAndRestore* aDBRepTool = NULL;
|
||||
while (tool) {
|
||||
const char* toolName = tool->Name();
|
||||
if (!strcmp(typ,toolName)) break;
|
||||
if (!strcmp("DBRep_DrawableShape",toolName))
|
||||
aDBRepTool = tool;
|
||||
tool = tool->Next();
|
||||
}
|
||||
char aType[255] = {};
|
||||
aStream >> aType;
|
||||
if (aStream.fail())
|
||||
{
|
||||
theDI << "Error: cannot read file: '" << aFileName << "'";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!tool)
|
||||
{
|
||||
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
|
||||
Draw::SetProgressBar (aProgress);
|
||||
Handle(Draw_Drawable3D) aDrawable = Draw_Drawable3D::Restore (aType, aStream);
|
||||
if (aDrawable.IsNull())
|
||||
{
|
||||
//assume that this file stores a DBRep_DrawableShape variable
|
||||
tool = aDBRepTool;
|
||||
in.seekg(0, std::ios::beg);
|
||||
// assume that this file stores a DBRep_DrawableShape variable
|
||||
aStream.seekg (0, std::ios::beg);
|
||||
aDrawable = Draw_Drawable3D::Restore ("DBRep_DrawableShape", aStream);
|
||||
}
|
||||
|
||||
if (tool)
|
||||
if (aDrawable.IsNull())
|
||||
{
|
||||
Handle(Draw_Drawable3D) D = tool->Restore(in);
|
||||
Draw::Set(name,D,tool->Disp() && autodisp);
|
||||
}
|
||||
|
||||
else {
|
||||
di << "Cannot restore a " << typ;
|
||||
theDI << "Error: cannot restore a " << aType;
|
||||
return 1;
|
||||
}
|
||||
Draw::SetProgressBar( 0 );
|
||||
|
||||
Draw::Set (aVarName, aDrawable, aDrawable->IsDisplayable() && autodisp);
|
||||
Draw::SetProgressBar (Handle(Draw_ProgressIndicator)());
|
||||
}
|
||||
|
||||
di << name;
|
||||
|
||||
theDI << aVarName;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1239,8 +1162,10 @@ void Draw::VariableCommands(Draw_Interpretor& theCommandsArg)
|
||||
Draw_BeforeCommand = &before;
|
||||
Draw_AfterCommand = &after;
|
||||
|
||||
// set up some variables
|
||||
// Register save/restore tools
|
||||
Draw_Number::RegisterFactory();
|
||||
|
||||
// set up some variables
|
||||
const char* n;
|
||||
Handle(Draw_Axis3D) theAxes3d = new Draw_Axis3D(gp_Pnt(0,0,0),Draw_bleu,20);
|
||||
n = "axes";
|
||||
|
@@ -27,7 +27,6 @@ Draw_Drawable2D.cxx
|
||||
Draw_Drawable2D.hxx
|
||||
Draw_Drawable3D.cxx
|
||||
Draw_Drawable3D.hxx
|
||||
Draw_Drawable3D.lxx
|
||||
Draw_Failure.hxx
|
||||
Draw_GraphicCommands.cxx
|
||||
Draw_Grid.cxx
|
||||
|
Reference in New Issue
Block a user