// 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
#include <Draw_Appli.hxx>
#include <DBRep.hxx>
+#include <Font_BRepFont.hxx>
#include <OSD_Chronometer.hxx>
#include <TCollection_AsciiString.hxx>
#include <Visual3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
-#include <V3d_Plane.hxx>
#include <V3d.hxx>
#include <AIS_Shape.hxx>
#include <Prs3d_PointAspect.hxx>
#include <Image_AlienPixMap.hxx>
+#include <TColStd_HArray1OfAsciiString.hxx>
#ifdef HAVE_STRINGS_H
#include <strings.h>
Standard_Real aHeight;
Standard_Boolean aZoomable;
Quantity_Color aColor;
- Standard_CString aFont;
+ TCollection_AsciiString aFont;
Font_FontAspect aFontAspect;
Graphic3d_HorizontalTextAlignment aHJustification;
Graphic3d_VerticalTextAlignment aVJustification;
Handle_Prs3d_TextAspect asp = myDrawer->TextAspect();
- asp->SetFont(aFont);
+ asp->SetFont(aFont.ToCString());
asp->SetColor(aColor);
asp->SetHeight(aHeight); // I am changing the myHeight value
return 0;
}
-//===============================================================================================
-//function : VClipPlane
-//purpose :
-//===============================================================================================
-static int VClipPlane (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
-{
- Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
- Handle(V3d_View) aView = ViewerTest::CurrentView();
- Standard_Real coeffA, coeffB, coeffC, coeffD;
- if (aViewer.IsNull() || aView.IsNull())
- {
- std::cout << "Viewer not initialized!\n";
- return 1;
- }
-
- // count an active planes count
- Standard_Integer aNewPlaneId = 1;
- Standard_Integer anActivePlanes = 0;
- for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aNewPlaneId)
- {
- Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
- if (aView->IsActivePlane (aPlaneV3d))
- {
- ++anActivePlanes;
- }
- }
-
- if (argc == 1)
- {
- // just show info about existing planes
- Standard_Integer aPlaneId = 1;
- std::cout << "Active planes: " << anActivePlanes << " from maximal " << aView->View()->PlaneLimit() << "\n";
- for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
- {
- Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
- aPlaneV3d->Plane (coeffA, coeffB, coeffC, coeffD);
- gp_Pln aPlane (coeffA, coeffB, coeffC, coeffD);
- const gp_Pnt& aLoc = aPlane.Location();
- const gp_Dir& aNor = aPlane.Axis().Direction();
- Standard_Boolean isActive = aView->IsActivePlane (aPlaneV3d);
- std::cout << "Plane #" << aPlaneId
- << " " << aLoc.X() << " " << aLoc.Y() << " " << aLoc.Z()
- << " " << aNor.X() << " " << aNor.Y() << " " << aNor.Z()
- << (isActive ? " on" : " off")
- << (aPlaneV3d->IsDisplayed() ? ", displayed" : ", hidden")
- << "\n";
- }
- if (aPlaneId == 1)
- {
- std::cout << "No defined clipping planes\n";
- }
- return 0;
- }
- else if (argc == 2 || argc == 3)
- {
- Standard_Integer aPlaneIdToOff = (argc == 3) ? Draw::Atoi (argv[1]) : 1;
- Standard_Boolean toIterateAll = (argc == 2);
- TCollection_AsciiString isOnOffStr ((argc == 3) ? argv[2] : argv[1]);
- isOnOffStr.LowerCase();
- Standard_Integer aPlaneId = 1;
- for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->NextDefinedPlanes(), ++aPlaneId)
- {
- if (aPlaneIdToOff == aPlaneId || toIterateAll)
- {
- Handle(V3d_Plane) aPlaneV3d = aViewer->DefinedPlane();
- if (isOnOffStr.Search ("off") >= 0)
- {
- aView->SetPlaneOff (aPlaneV3d);
- std::cout << "Clipping plane #" << aPlaneId << " was disabled\n";
- }
- else if (isOnOffStr.Search ("on") >= 0)
- {
- // avoid z-fighting glitches
- aPlaneV3d->Erase();
- if (!aView->IsActivePlane (aPlaneV3d))
- {
- if (anActivePlanes < aView->View()->PlaneLimit())
- {
- aView->SetPlaneOn (aPlaneV3d);
- std::cout << "Clipping plane #" << aPlaneId << " was enabled\n";
- }
- else
- {
- std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
- << "You should disable or remove some existing plane to activate this one\n";
- }
- }
- else
- {
- std::cout << "Clipping plane #" << aPlaneId << " was already enabled\n";
- }
- }
- else if (isOnOffStr.Search ("del") >= 0 || isOnOffStr.Search ("rem") >= 0)
- {
- aPlaneV3d->Erase(); // not performed on destructor!!!
- aView->SetPlaneOff (aPlaneV3d);
- aViewer->DelPlane (aPlaneV3d);
- std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
- if (toIterateAll)
- {
- for (aViewer->InitDefinedPlanes(); aViewer->MoreDefinedPlanes(); aViewer->InitDefinedPlanes(), ++aPlaneId)
- {
- aPlaneV3d = aViewer->DefinedPlane();
- aPlaneV3d->Erase(); // not performed on destructor!!!
- aView->SetPlaneOff (aPlaneV3d);
- aViewer->DelPlane (aPlaneV3d);
- std::cout << "Clipping plane #" << aPlaneId << " was removed\n";
- }
- break;
- }
- else
- {
- break;
- }
- }
- else if (isOnOffStr.Search ("disp") >= 0 || isOnOffStr.Search ("show") >= 0)
- {
- // avoid z-fighting glitches
- aView->SetPlaneOff (aPlaneV3d);
- aPlaneV3d->Display (aView);
- std::cout << "Clipping plane #" << aPlaneId << " was shown and disabled\n";
- }
- else if (isOnOffStr.Search ("hide") >= 0)
- {
- aPlaneV3d->Erase();
- std::cout << "Clipping plane #" << aPlaneId << " was hidden\n";
- }
- else
- {
- std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
- return 1;
- }
- }
- }
- if (aPlaneIdToOff >= aPlaneId && !toIterateAll)
- {
- std::cout << "Clipping plane with id " << aPlaneIdToOff << " not found!\n";
- return 1;
- }
- aView->Update();
- return 0;
- }
- else if (argc != 7)
- {
- std::cout << "Usage: " << argv[0] << " [x y z dx dy dz] [planeId {on/off/del/display/hide}]\n";
- return 1;
- }
-
- Standard_Real aLocX = Draw::Atof (argv[1]);
- Standard_Real aLocY = Draw::Atof (argv[2]);
- Standard_Real aLocZ = Draw::Atof (argv[3]);
- Standard_Real aNormDX = Draw::Atof (argv[4]);
- Standard_Real aNormDY = Draw::Atof (argv[5]);
- Standard_Real aNormDZ = Draw::Atof (argv[6]);
-
- Handle(V3d_Plane) aPlaneV3d = new V3d_Plane();
- gp_Pln aPlane (gp_Pnt (aLocX, aLocY, aLocZ), gp_Dir (aNormDX, aNormDY, aNormDZ));
- aPlane.Coefficients (coeffA, coeffB, coeffC, coeffD);
- aPlaneV3d->SetPlane(coeffA, coeffB, coeffC, coeffD);
-
- aViewer->AddPlane (aPlaneV3d); // add to defined planes list
- std::cout << "Added clipping plane #" << aNewPlaneId << "\n";
- if (anActivePlanes < aView->View()->PlaneLimit())
- {
- aView->SetPlaneOn (aPlaneV3d); // add to enabled planes list
- aView->Update();
- }
- else
- {
- std::cout << "Maximal active planes limit exceeded (" << anActivePlanes << ")\n"
- << "You should disable or remove some existing plane to activate the new one\n";
- }
- return 0;
-}
-
//=============================================================================
//function : VComputeHLR
//purpose :
public:
- MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives) theArray,
+ MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription,
Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
{
- myArray = theArray;
+ myArrayDescription = theArrayDescription;
myMarkerAspect = theMarkerAspect;
}
void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
const Standard_Integer /*theMode*/);
+ bool CheckInputCommand (const TCollection_AsciiString theCommand,
+ const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
+ Standard_Integer &theArgIndex,
+ Standard_Integer theArgCount,
+ Standard_Integer theMaxArgs);
+
protected:
- Handle(Graphic3d_ArrayOfPrimitives) myArray;
+ Handle(TColStd_HArray1OfAsciiString) myArrayDescription;
Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
};
const Handle(Prs3d_Presentation)& aPresentation,
const Standard_Integer /*aMode*/)
{
- aPresentation->Clear();
- if (!myMarkerAspect.IsNull())
- {
- Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
- }
- Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (myArray);
-}
-void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
- const Standard_Integer /*theMode*/)
-{
- Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
-
- for (Standard_Integer anIter = 1; anIter <= myArray->VertexNumber(); anIter++)
- {
-
- Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, myArray->Vertice (anIter));
- theSelection->Add (aSensetivePoint);
- }
-}
-
-static bool CheckInputCommand (const TCollection_AsciiString theCommand,
- const char **theArgStr, int &theArgIndex,
- int theArgCount, int theMaxArgs)
-{
- // check if there is more elements than expected
- if (theArgIndex >= theMaxArgs)
- return false;
-
- TCollection_AsciiString aStrCommand(theArgStr[theArgIndex]);
- aStrCommand.LowerCase();
- if (aStrCommand.Search(theCommand) != 1 ||
- theArgIndex + (theArgCount - 1) >= theMaxArgs)
- return false;
-
- // go to the first data element
- theArgIndex++;
-
- // check data if it can be converted to numeric
- for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
- {
- aStrCommand = theArgStr[theArgIndex];
- if (!aStrCommand.IsRealValue())
- return false;
- }
-
- return true;
-}
-
-//=============================================================================
-//function : VDrawPArray
-//purpose : Draws primitives array from list of vertexes, bounds, edges
-//=============================================================================
-
-static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
-{
- Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
- if (aContextAIS.IsNull())
- {
- di << "Call vinit before!\n";
- return 1;
- }
- else if (argc < 3)
- {
- di << "Use: " << argv[0] << " Name TypeOfArray"
- << " [vertex] ... [bounds] ... [edges]\n"
- << " TypeOfArray={ points | segments | polylines | triangles |\n"
- << " trianglefans | trianglestrips | quads |\n"
- << " quadstrips | polygons }\n"
- << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
- << " [texel={ 't' tx ty }] } \n"
- << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
- << " edges={ 'e' vertex_id [hidden_edge={'h'}] }\n";
- return 1;
- }
-
- // read the arguments
- Standard_Integer aArgIndex = 1;
- TCollection_AsciiString aName (argv[aArgIndex++]);
- TCollection_AsciiString anArrayType (argv[aArgIndex++]);
- const Standard_Integer anArgsFrom = aArgIndex;
-
- // parse number of verticies, bounds, edges
+ // Parsing array description
Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
Standard_Boolean hasVColors, hasBColors, hasNormals, hasInfos, hasTexels;
hasVColors = hasNormals = hasBColors = hasInfos = hasTexels = Standard_False;
+ Standard_Integer anArgIndex = 0;
+ Standard_Integer anArgsCount = myArrayDescription->Length();
+ TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++);
+
TCollection_AsciiString aCommand;
- while (aArgIndex < argc)
+ while (anArgIndex < anArgsCount)
{
- aCommand = argv[aArgIndex];
+ aCommand = myArrayDescription->Value (anArgIndex);
aCommand.LowerCase();
- if (!aCommand.IsAscii())
- {
- di << "Unexpected argument: #" << aArgIndex - 1 << " , "
- << "should be an array element: 'v', 'b', 'e' \n";
- break;
- }
// vertex command
- if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
+ if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
{
// vertex has a normal or normal with color or texel
- if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
+ if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
hasNormals = Standard_True;
// vertex has a color
- if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
+ if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
hasVColors = Standard_True;
// vertex has a texel
- if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
+ if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
hasTexels = Standard_True;
aVertexNum++;
}
// bound command
- else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
+ else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
{
// bound has color
- if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
+ if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
hasBColors = Standard_True;
aBoundNum++;
}
// edge command
- else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
+ else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
{
// edge has a hide flag
- if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
+ if (CheckInputCommand ("h", myArrayDescription, anArgIndex, 0, anArgsCount))
hasInfos = Standard_True;
aEdgeNum++;
}
// unknown command
else
- aArgIndex++;
- }
-
- if (aVertexNum == 0)
- {
- di << "You should pass any verticies in the list of array elements\n";
- return 1;
+ anArgIndex++;
}
- // create an array of primitives by types
Handle(Graphic3d_ArrayOfPrimitives) anArray;
- Handle(Graphic3d_AspectMarker3d) anAspPoints;
if (anArrayType == "points")
{
anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
- anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
}
else if (anArrayType == "segments")
anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
hasNormals, hasVColors, hasBColors,
hasTexels, hasInfos);
- else
- {
- di << "Unexpected type of primitiives array\n";
- return 1;
- }
- // parse an array of primitives
- aArgIndex = anArgsFrom;
- while (aArgIndex < argc)
+ anArgIndex = 1;
+ while (anArgIndex < anArgsCount)
{
- aCommand = argv[aArgIndex];
+ aCommand = myArrayDescription->Value (anArgIndex);
aCommand.LowerCase();
if (!aCommand.IsAscii())
break;
// vertex command
- if (CheckInputCommand ("v", argv, aArgIndex, 3, argc))
+ if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount))
{
- anArray->AddVertex (Draw::Atof (argv[aArgIndex - 3]),
- Draw::Atof (argv[aArgIndex - 2]),
- Draw::Atof (argv[aArgIndex - 1]));
+ anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(),
+ myArrayDescription->Value (anArgIndex - 2).RealValue(),
+ myArrayDescription->Value (anArgIndex - 1).RealValue());
// vertex has a normal or normal with color or texel
- if (CheckInputCommand ("n", argv, aArgIndex, 3, argc))
+ if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
anArray->SetVertexNormal (anArray->VertexNumber (),
- Draw::Atof (argv[aArgIndex - 3]),
- Draw::Atof (argv[aArgIndex - 2]),
- Draw::Atof (argv[aArgIndex - 1]));
+ myArrayDescription->Value (anArgIndex - 3).RealValue(),
+ myArrayDescription->Value (anArgIndex - 2).RealValue(),
+ myArrayDescription->Value (anArgIndex - 1).RealValue());
- if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
+ if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
anArray->SetVertexColor (anArray->VertexNumber (),
- Draw::Atof (argv[aArgIndex - 3]),
- Draw::Atof (argv[aArgIndex - 2]),
- Draw::Atof (argv[aArgIndex - 1]));
+ myArrayDescription->Value (anArgIndex - 3).RealValue(),
+ myArrayDescription->Value (anArgIndex - 2).RealValue(),
+ myArrayDescription->Value (anArgIndex - 1).RealValue());
- if (CheckInputCommand ("t", argv, aArgIndex, 2, argc))
+ if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
anArray->SetVertexTexel (anArray->VertexNumber (),
- Draw::Atof (argv[aArgIndex - 2]),
- Draw::Atof (argv[aArgIndex - 1]));
+ myArrayDescription->Value (anArgIndex - 2).RealValue(),
+ myArrayDescription->Value (anArgIndex - 1).RealValue());
}
// bounds command
- else if (CheckInputCommand ("b", argv, aArgIndex, 1, argc))
+ else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount))
{
- Standard_Integer aVertCount = Draw::Atoi (argv[aArgIndex - 1]);
+ Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
- if (CheckInputCommand ("c", argv, aArgIndex, 3, argc))
+ if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
anArray->AddBound (aVertCount,
- Draw::Atof (argv[aArgIndex - 3]),
- Draw::Atof (argv[aArgIndex - 2]),
- Draw::Atof (argv[aArgIndex - 1]));
+ myArrayDescription->Value (anArgIndex - 3).RealValue(),
+ myArrayDescription->Value (anArgIndex - 2).RealValue(),
+ myArrayDescription->Value (anArgIndex - 1).RealValue());
else
anArray->AddBound (aVertCount);
}
// edge command
- else if (CheckInputCommand ("e", argv, aArgIndex, 1, argc))
+ else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount))
{
- Standard_Integer aVertIndex = Draw::Atoi (argv[aArgIndex - 1]);
+ Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue();
// edge has/hasn't hide flag
- if (CheckInputCommand ("h", argv, aArgIndex, 0, argc))
+ if (CheckInputCommand ("h", myArrayDescription, anArgIndex, 0, anArgsCount))
anArray->AddEdge (aVertIndex, Standard_False);
else
anArray->AddEdge (aVertIndex, Standard_True);
}
// unknown command
else
- aArgIndex++;
+ anArgIndex++;
+ }
+
+ aPresentation->Clear();
+ if (!myMarkerAspect.IsNull())
+ {
+ Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
+ }
+ Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
+}
+
+void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+ const Standard_Integer /*theMode*/)
+{
+ Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
+
+ Standard_Integer anArgIndex = 1;
+ while (anArgIndex < myArrayDescription->Length())
+ {
+ if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length()))
+ {
+ gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(),
+ myArrayDescription->Value (anArgIndex - 2).RealValue(),
+ myArrayDescription->Value (anArgIndex - 1).RealValue());
+ Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
+ theSelection->Add (aSensetivePoint);
+ }
+ else
+ {
+ anArgIndex++;
+ }
+ }
+}
+
+bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand,
+ const Handle(TColStd_HArray1OfAsciiString) theArgsArray,
+ Standard_Integer &theArgIndex,
+ Standard_Integer theArgCount,
+ Standard_Integer theMaxArgs)
+{
+ // check if there is more elements than expected
+ if (theArgIndex >= theMaxArgs)
+ return false;
+
+ TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex);
+ aStrCommand.LowerCase();
+ if (aStrCommand.Search(theCommand) != 1 ||
+ theArgIndex + (theArgCount - 1) >= theMaxArgs)
+ return false;
+
+ // go to the first data element
+ theArgIndex++;
+
+ // check data if it can be converted to numeric
+ for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++)
+ {
+ aStrCommand = theArgsArray->Value (theArgIndex);
+ if (!aStrCommand.IsRealValue())
+ return false;
+ }
+
+ return true;
+}
+
+//=============================================================================
+//function : VDrawPArray
+//purpose : Draws primitives array from list of vertexes, bounds, edges
+//=============================================================================
+
+static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+ Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
+ if (aContextAIS.IsNull())
+ {
+ di << "Call vinit before!\n";
+ return 1;
+ }
+ else if (argc < 3)
+ {
+ di << "Use: " << argv[0] << " Name TypeOfArray"
+ << " [vertex] ... [bounds] ... [edges]\n"
+ << " TypeOfArray={ points | segments | polylines | triangles |\n"
+ << " trianglefans | trianglestrips | quads |\n"
+ << " quadstrips | polygons }\n"
+ << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
+ << " [texel={ 't' tx ty }] } \n"
+ << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n"
+ << " edges={ 'e' vertex_id [hidden_edge={'h'}] }\n";
+ return 1;
+ }
+
+ // read the arguments
+ Standard_Integer aArgIndex = 1;
+ TCollection_AsciiString aName (argv[aArgIndex++]);
+ TCollection_AsciiString anArrayType (argv[aArgIndex++]);
+
+ Standard_Boolean hasVertex = Standard_False;
+
+ Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2);
+ anArgsArray->SetValue (0, anArrayType);
+
+ if (anArrayType != "points" &&
+ anArrayType != "segments" &&
+ anArrayType != "polylines" &&
+ anArrayType != "triangles" &&
+ anArrayType != "trianglefans" &&
+ anArrayType != "trianglestrips" &&
+ anArrayType != "quads" &&
+ anArrayType != "quadstrips" &&
+ anArrayType != "polygons")
+ {
+ di << "Unexpected type of primitives array\n";
+ return 1;
+ }
+
+ TCollection_AsciiString aCommand;
+ for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++)
+ {
+ aCommand = argv[anArgIndex];
+ aCommand.LowerCase();
+ if (!aCommand.IsAscii())
+ {
+ di << "Unexpected argument: #" << aArgIndex - 1 << " , "
+ << "should be an array element: 'v', 'b', 'e' \n";
+ break;
+ }
+
+ if (aCommand == "v")
+ {
+ hasVertex = Standard_True;
+ }
+
+ anArgsArray->SetValue (anArgIndex - 2, aCommand);
+ }
+
+ if (!hasVertex)
+ {
+ di << "You should pass any verticies in the list of array elements\n";
+ return 1;
+ }
+
+ Handle(Graphic3d_AspectMarker3d) anAspPoints;
+ if (anArrayType == "points")
+ {
+ anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f);
}
// create primitives array object
- Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArray, anAspPoints);
+ Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints);
// register the object in map
VDisplayAISObject (aName, aPObject);
return 0;
}
+// This class is used for testing markers.
+DEFINE_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
+class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject
+{
+
+public:
+
+ ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint,
+ const Standard_Integer& thePointsOnSide,
+ Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL)
+ {
+ myStartPoint = theStartPoint;
+ myPointsOnSide = thePointsOnSide;
+ myMarkerAspect = theMarkerAspect;
+ }
+
+ DEFINE_STANDARD_RTTI(MyPArrayObject);
+
+private:
+
+ void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
+ const Handle(Prs3d_Presentation)& aPresentation,
+ const Standard_Integer aMode);
+
+ void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+ const Standard_Integer /*theMode*/);
+
+protected:
+
+ gp_XYZ myStartPoint;
+ Standard_Integer myPointsOnSide;
+ Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
+};
+
+IMPLEMENT_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
+IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_MarkersArrayObject, AIS_InteractiveObject)
+
+void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
+ const Handle(Prs3d_Presentation)& aPresentation,
+ const Standard_Integer /*aMode*/)
+{
+ Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1);
+ if (myPointsOnSide == 1)
+ {
+ anArray->AddVertex (myStartPoint);
+ }
+ else
+ {
+ for (Standard_Real i = 1; i <= myPointsOnSide; i++)
+ {
+ for (Standard_Real j = 1; j <= myPointsOnSide; j++)
+ {
+ for (Standard_Real k = 1; k <= myPointsOnSide; k++)
+ {
+ anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
+ anArray->SetVertexColor (anArray->VertexNumber(),
+ i / myPointsOnSide,
+ j / myPointsOnSide,
+ k / myPointsOnSide);
+ }
+ }
+ }
+ }
+
+ aPresentation->Clear();
+ if (!myMarkerAspect.IsNull())
+ {
+ Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect);
+ }
+ Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray);
+}
+
+void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+ const Standard_Integer /*theMode*/)
+{
+ Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this);
+
+ if (myPointsOnSide == 1)
+ {
+ gp_Pnt aPoint (myStartPoint);
+ Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
+ theSelection->Add (aSensetivePoint);
+ }
+ else
+ {
+ for (Standard_Real i = 1; i <= myPointsOnSide; i++)
+ {
+ for (Standard_Real j = 1; j <= myPointsOnSide; j++)
+ {
+ for (Standard_Real k = 1; k <= myPointsOnSide; k++)
+ {
+ gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k);
+ Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint);
+ theSelection->Add (aSensetivePoint);
+ }
+ }
+ }
+ }
+}
//=======================================================================
//function : VMarkersTest
//purpose : Draws an array of markers for testing purposes.
//=======================================================================
-static Standard_Integer VMarkersTest (Draw_Interpretor& theDI,
+static Standard_Integer VMarkersTest (Draw_Interpretor&,
Standard_Integer theArgNb,
const char** theArgVec)
{
anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale);
}
- Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (aPointsOnSide, 3), aPointsOnSide != 1);
- if (aPointsOnSide == 1)
+ Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect);
+ VDisplayAISObject (aName, aMarkersArray);
+
+ 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)
{
- anArray->AddVertex (aPnt);
+ std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n";
+ return 1;
}
- else
+
+ 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)
{
- for (Standard_Real i = 1; i <= aPointsOnSide; i++)
+ const TCollection_AsciiString anArg (theArgVec[anArgIter++]);
+ if (anArg.Search ("x=") > -1)
{
- for (Standard_Real j = 1; j <= aPointsOnSide; j++)
- {
- for (Standard_Real k = 1; k <= aPointsOnSide; k++)
- {
- anArray->AddVertex (aPnt.X() + i, aPnt.Y() + j, aPnt.Z() + k);
- anArray->SetVertexColor (anArray->VertexNumber(),
- i / aPointsOnSide,
- j / aPointsOnSide,
- k / aPointsOnSide);
- }
- }
+ 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";
}
}
- Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArray, anAspect);
- VDisplayAISObject (aName, aPObject);
+ 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;
}
"vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n",
__FILE__,VDrawSphere,group);
- theCommands.Add("vclipplane",
- "vclipplane : vclipplane [x y z dx dy dz] [planeId {on/off/del/display/hide}]",
- __FILE__,VClipPlane,group);
-
theCommands.Add ("vsetlocation",
"vsetlocation : name x y z; set new location for an interactive object",
__FILE__, VSetLocation, group);
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);
}