1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0024181: Text to BRep functionality

Introduce new class Font_BRepFont for conversion of font glyph in vector format into BRep representation.
New text2brep Draw Harness command.

bottle.tcl - draw text on the bottle side using new functionality.
ViewerTest - process Delete key in 3D-Viewer to delete selected presentations.
Font_FontMgr::FindFont - return correct font when font alias and not default aspect is requested.

bottle.tcl - use prism instead of pipe

TKViewerTest - add required FreeType dependency

verase - display the list of erase objects

TKViewerTest - add required FreeType dependency for projects generation
This commit is contained in:
isn
2013-10-10 13:35:04 +04:00
committed by bugmaster
parent c63628e845
commit b514beda8a
22 changed files with 1248 additions and 177 deletions

View File

@@ -1,3 +1,4 @@
CSF_objc
CSF_Appkit
CSF_IOKit
CSF_FREETYPE

View File

@@ -1591,126 +1591,100 @@ static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
}
//==============================================================================
//function : VErase2
//author : ege
//purpose : Erase some selected or named objects
//function : VErase
//purpose : Erase some selected or named objects
// if there is no selected or named objects, the whole viewer is erased
//Draw arg : verase2 [name1] ... [name n]
//==============================================================================
static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv)
int VErase (Draw_Interpretor& theDI,
Standard_Integer theArgNb,
const char** theArgVec)
{
if ( a3DView().IsNull() )
if (a3DView().IsNull())
{
return 1;
Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0;
Standard_Boolean ThereIsArgument= argc>1;
if(TheAISContext()->HasOpenedContext())
TheAISContext()->CloseLocalContext();
//===============================================================
// Il n'y a pas d'arguments mais des objets selectionnes(current)
// dans le viewer
//===============================================================
if (!ThereIsArgument && ThereIsCurrent) {
ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
it (GetMapOfAIS());
while ( it.More() ) {
if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
const Handle(AIS_InteractiveObject) aShape =
Handle(AIS_InteractiveObject)::DownCast(it.Key1());
if (TheAISContext()->IsCurrent(aShape))
TheAISContext()->Erase(aShape,Standard_False);
}
it.Next();
}
TheAISContext() ->UpdateCurrentViewer();
}
//===============================================================
// Il n'y a pas d'arguments et aucuns objets selectionnes
// dans le viewer:
// On erase tout le viewer
//===============================================================
if (!ThereIsArgument && !ThereIsCurrent) {
ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
while ( it.More() ) {
if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
const Handle(AIS_InteractiveObject) aShape =
Handle(AIS_InteractiveObject)::DownCast(it.Key1());
TheAISContext()->Erase(aShape,Standard_False);
} else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
const Handle(NIS_InteractiveObject) aShape =
Handle(NIS_InteractiveObject)::DownCast(it.Key1());
TheNISContext()->Erase(aShape);
}
it.Next();
TheAISContext()->CloseAllContexts (Standard_False);
const Standard_Boolean isEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "").IsEqual ("veraseall");
if (theArgNb > 1)
{
if (isEraseAll)
{
std::cerr << " Syntax error: " << theArgVec[0] << " too much arguments.\n";
return 1;
}
TheAISContext() ->UpdateCurrentViewer();
// TheNISContext()->UpdateViews();
}
//===============================================================
// Il y a des arguments
//===============================================================
if (ThereIsArgument) {
for (int i=1; i<argc ; i++) {
TCollection_AsciiString name=argv[i];
Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name);
if (IsBound) {
const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
const Handle(AIS_InteractiveObject) aShape =
Handle(AIS_InteractiveObject)::DownCast (anObj);
TheAISContext()->Erase(aShape,Standard_False);
} else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
const Handle(NIS_InteractiveObject) aShape =
Handle(NIS_InteractiveObject)::DownCast (anObj);
TheNISContext()->Erase(aShape);
// has a list of names
for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
{
TCollection_AsciiString aName = theArgVec[anArgIter];
if (!GetMapOfAIS().IsBound2 (aName))
{
continue;
}
const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
theDI << aName.ToCString() << " ";
if (!anIO.IsNull())
{
TheAISContext()->Erase (anIO, Standard_False);
}
else
{
const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj);
if (!aNisIO.IsNull())
{
TheNISContext()->Erase (aNisIO);
}
}
}
TheAISContext() ->UpdateCurrentViewer();
// TheNISContext() ->UpdateViews();
TheAISContext()->UpdateCurrentViewer();
return 0;
}
return 0;
}
//==============================================================================
//function : VEraseAll
//author : ege
//purpose : Erase all the objects displayed in the viewer
//Draw arg : veraseall
//==============================================================================
static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
// Verification des arguments
if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;}
if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;}
TheAISContext()->CloseAllContexts(Standard_False);
ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
it(GetMapOfAIS());
while ( it.More() ) {
if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
const Handle(AIS_InteractiveObject) aShape =
Handle(AIS_InteractiveObject)::DownCast(it.Key1());
TheAISContext()->Erase(aShape,Standard_False);
} else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) {
const Handle(NIS_InteractiveObject) aShape =
Handle(NIS_InteractiveObject)::DownCast(it.Key1());
TheNISContext()->Erase(aShape);
if (!isEraseAll
&& TheAISContext()->NbCurrents() > 0)
{
// remove all currently selected objects
for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
anIter.More(); anIter.Next())
{
const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
if (!anIO.IsNull()
&& TheAISContext()->IsCurrent (anIO))
{
theDI << anIter.Key2().ToCString() << " ";
TheAISContext()->Erase (anIO, Standard_False);
}
}
it.Next();
TheAISContext()->UpdateCurrentViewer();
return 0;
}
TheAISContext() ->UpdateCurrentViewer();
// TheNISContext() ->UpdateViews();
// erase entire viewer
for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
anIter.More(); anIter.Next())
{
const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
if (!anIO.IsNull())
{
TheAISContext()->Erase (anIO, Standard_False);
}
else
{
const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1());
if (!aNisIO.IsNull())
{
TheNISContext()->Erase (aNisIO);
}
}
}
TheAISContext()->UpdateCurrentViewer();
return 0;
}
//==============================================================================
//function : VDisplayAll
//author : ege
@@ -3165,7 +3139,7 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
"verase [name1] ... [name n]"
"\n\t\t: Erases selected or named objects."
"\n\t\t: If there are no selected or named objects the whole viewer is erased.",
__FILE__,VErase2,group);
__FILE__, VErase, group);
theCommands.Add("vdonly",
"vdonly [name1] ... [name n]"
@@ -3178,7 +3152,7 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
theCommands.Add("veraseall",
"Erases all objects displayed in the viewer",
__FILE__,VEraseAll,group);
__FILE__, VErase, group);
theCommands.Add("verasetype",
"verasetype <Type>"

View File

@@ -18,12 +18,6 @@
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
//===============================================
// AIS Objects Creation : Datums (axis,trihedrons,lines,planes)
//===============================================
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -38,6 +32,7 @@
#include <Draw_Appli.hxx>
#include <DBRep.hxx>
#include <Font_BRepFont.hxx>
#include <OSD_Chronometer.hxx>
#include <TCollection_AsciiString.hxx>
#include <Visual3d_View.hxx>
@@ -4677,6 +4672,86 @@ static Standard_Integer VMarkersTest (Draw_Interpretor&,
return 0;
}
//=======================================================================
//function : TextToBrep
//purpose : Tool for conversion text to occt-shapes
//=======================================================================
static int TextToBRep (Draw_Interpretor& /*theDI*/,
Standard_Integer theArgNb,
const char** theArgVec)
{
// Check arguments
if (theArgNb < 5)
{
std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
return 1;
}
Standard_Integer anArgIter = 1;
Standard_CString aResName = theArgVec[anArgIter++];
Standard_CString aText = theArgVec[anArgIter++];
Standard_CString aFontName = theArgVec[anArgIter++];
const Standard_Real aSize = Atof (theArgVec[anArgIter++]);
Font_BRepFont aFont;
Font_FontAspect aFontAspect = Font_FA_Regular;
Standard_Boolean isCompositeCurve = Standard_False;
gp_Ax3 aPenAx3 (gp::XOY());
gp_Pnt aPenLoc;
while (anArgIter < theArgNb)
{
const TCollection_AsciiString anArg (theArgVec[anArgIter++]);
if (anArg.Search ("x=") > -1)
{
aPenLoc.SetX (anArg.Token ("=", 2).RealValue());
}
else if (anArg.Search ("y=") > -1)
{
aPenLoc.SetY (anArg.Token ("=", 2).RealValue());
}
else if (anArg.Search ("z=") > -1)
{
aPenLoc.SetZ (anArg.Token ("=", 2).RealValue());
}
else if (anArg.Search ("composite=") > -1)
{
isCompositeCurve = (anArg.Token ("=", 2).IntegerValue() == 1);
}
else if (anArg.Search ("regular") > -1)
{
aFontAspect = Font_FA_Regular;
}
else if (anArg.Search ("bolditalic") > -1)
{
aFontAspect = Font_FA_BoldItalic;
}
else if (anArg.Search ("bold") > -1)
{
aFontAspect = Font_FA_Bold;
}
else if (anArg.Search ("italic") > -1)
{
aFontAspect = Font_FA_Italic;
}
else
{
std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n";
}
}
aFont.SetCompositeCurveMode (isCompositeCurve);
if (!aFont.Init (aFontName, aFontAspect, aSize))
{
std::cerr << "Font initialization error\n";
return 1;
}
aPenAx3.SetLocation (aPenLoc);
DBRep::Set (aResName, aFont.RenderText (aText, aPenAx3));
return 0;
}
//=======================================================================
//function : ObjectsCommands
//purpose :
@@ -4812,4 +4887,8 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
theCommands.Add ("vmarkerstest",
"vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n",
__FILE__, VMarkersTest, group);
theCommands.Add ("text2brep",
"text2brep: res text fontName fontSize [x=0.0 y=0.0 z=0.0 composite=1 {regular,bold,italic,bolditalic=regular}]\n",
__FILE__, TextToBRep, group);
}

View File

@@ -18,9 +18,6 @@
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
// Robert Boehne 30 May 2000 : Dec Osf
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
@@ -104,18 +101,24 @@
#include <tk.h>
#endif
//==============================================================================
// Auxiliary definitions
static const char THE_KEY_DELETE = 127;
//==============================================================================
// VIEWER GLOBAL VARIABLES
//==============================================================================
Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
extern const Handle(NIS_InteractiveContext)& TheNISContext();
extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
extern int VErase (Draw_Interpretor& theDI,
Standard_Integer theArgNb,
const char** theArgVec);
#if defined(_WIN32)
static Handle(WNT_Window)& VT_GetWindow() {
static Handle(WNT_Window) WNTWin;
@@ -1255,28 +1258,33 @@ void VT_ProcessKeyPress (const char* buf_ret)
const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
// Letter in alphabetic order
if ( !strcasecmp(buf_ret, "A") ) {
if (!strcasecmp (buf_ret, "A"))
{
// AXO
aView->SetProj(V3d_XposYnegZpos);
}
else if ( !strcasecmp(buf_ret, "D") ) {
else if (!strcasecmp (buf_ret, "D"))
{
// Reset
aView->Reset();
}
else if ( !strcasecmp(buf_ret, "F") ) {
else if (!strcasecmp (buf_ret, "F"))
{
// FitAll
if (aNisView.IsNull())
aView->FitAll();
else
aNisView->FitAll3d();
}
else if ( !strcasecmp(buf_ret, "H") ) {
else if (!strcasecmp (buf_ret, "H"))
{
// HLR
cout << "HLR" << endl;
aView->SetComputedMode (!aView->ComputedMode());
MyHLRIsOn = aView->ComputedMode();
}
else if ( !strcasecmp(buf_ret, "P") ) {
else if (!strcasecmp (buf_ret, "P"))
{
// Type of HLR
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
@@ -1318,9 +1326,9 @@ void VT_ProcessKeyPress (const char* buf_ret)
aContext->UpdateCurrentViewer();
}
else if ( !strcasecmp(buf_ret, "S") ) {
// SHADING
cout << "passage en mode 1 (shading pour les shapes)" << endl;
else if (!strcasecmp (buf_ret, "S"))
{
std::cout << "setup Shaded display mode" << std::endl;
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 ||
@@ -1338,9 +1346,10 @@ void VT_ProcessKeyPress (const char* buf_ret)
Ctx->UpdateCurrentViewer();
}
}
else if ( !strcasecmp(buf_ret, "U") ) {
else if (!strcasecmp (buf_ret, "U"))
{
// Unset display mode
cout<<"passage au mode par defaut"<<endl;
std::cout << "reset display mode to defaults" << std::endl;
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 ||
@@ -1359,26 +1368,29 @@ void VT_ProcessKeyPress (const char* buf_ret)
}
}
else if ( !strcasecmp(buf_ret, "T") ) {
else if (!strcasecmp (buf_ret, "T"))
{
// Top
aView->SetProj(V3d_Zpos);
}
else if ( !strcasecmp(buf_ret, "B") ) {
else if (!strcasecmp (buf_ret, "B"))
{
// Bottom
aView->SetProj(V3d_Zneg);
}
else if ( !strcasecmp(buf_ret, "L") ) {
else if (!strcasecmp (buf_ret, "L"))
{
// Left
aView->SetProj(V3d_Xneg);
}
else if ( !strcasecmp(buf_ret, "R") ) {
else if (!strcasecmp (buf_ret, "R"))
{
// Right
aView->SetProj(V3d_Xpos);
}
else if ( !strcasecmp(buf_ret, "W") ) {
// WIREFRAME
cout << "passage en mode 0 (filaire pour les shapes)" << endl;
else if (!strcasecmp (buf_ret, "W"))
{
std::cout << "setup WireFrame display mode" << std::endl;
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 ||
Ctx->NbSelected()==0)
@@ -1395,9 +1407,9 @@ void VT_ProcessKeyPress (const char* buf_ret)
Ctx->UpdateCurrentViewer();
}
}
else if ( !strcasecmp(buf_ret, "Z") ) {
else if (!strcasecmp (buf_ret, "Z"))
{
// ZCLIP
if ( ZClipIsOn ) {
cout << "ZClipping OFF" << endl;
ZClipIsOn = 0;
@@ -1413,16 +1425,27 @@ void VT_ProcessKeyPress (const char* buf_ret)
aView->Redraw();
}
}
else if ( !strcasecmp(buf_ret, ",") ) {
else if (!strcasecmp (buf_ret, ","))
{
ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
}
else if ( !strcasecmp(buf_ret, ".") ) {
else if (!strcasecmp (buf_ret, "."))
{
ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
}
// Number
else{
else if (*buf_ret == THE_KEY_DELETE)
{
Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
if (!aCtx.IsNull()
&& aCtx->NbCurrents() > 0
&& aCtx->NbSelected() > 0)
{
Draw_Interprete ("verase");
}
}
else
{
// Number
Standard_Integer Num = Draw::Atoi(buf_ret);
if(Num>=0 && Num<=7)
ViewerTest::StandardModeActivation(Num);
@@ -1760,6 +1783,7 @@ static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
di << "W : Wireframe" << "\n";
di << "H : HidelLineRemoval" << "\n";
di << "U : Unset display mode" << "\n";
di << "Delete : Remove selection from viewer" << "\n";
di << "========================="<<"\n";
di << "Selection mode "<<"\n";
@@ -1910,6 +1934,10 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
char c[2];
c[0] = (char) wParam;
c[1] = '\0';
if (wParam == VK_DELETE)
{
c[0] = THE_KEY_DELETE;
}
VT_ProcessKeyPress (c);
}
break;