mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0027764: Visualization - add functionality for animation of 3D camera and interactive objects
Added classes AIS_Animation, AIS_AnimationCamera, AIS_AnimationObjectLocatio. Draw Harness command vanimation has been modified to manage animation timeline. Command vfit has been extended with option -noupdate. Formatting of vviewparams command output has been improved. Functionality of commands vlocreset, vlocmove, vloctranslate, vlocrotate, vlocmirror, vlocscale has been merged into vlocation/vsetlocation. vlocation now can print the current local transformation of the object. v3d/ivtk test group does not call vfit anymore. Fixed misprint in test cases bugs/vis/bug24623_3 and bug25532.
This commit is contained in:
@@ -303,7 +303,7 @@ Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theNa
|
||||
Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
|
||||
if (!anOldObj.IsNull())
|
||||
{
|
||||
aCtx->Remove (anOldObj, Standard_True);
|
||||
aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
|
||||
}
|
||||
aMap.UnBind2 (theName);
|
||||
}
|
||||
@@ -3973,125 +3973,6 @@ static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//==================================================================================
|
||||
// Function : VAnimation
|
||||
//==================================================================================
|
||||
static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
|
||||
if (argc != 5) {
|
||||
di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
Standard_Real thread = 4;
|
||||
Standard_Real angleA=0;
|
||||
Standard_Real angleB;
|
||||
Standard_Real X;
|
||||
gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
|
||||
|
||||
BRep_Builder B;
|
||||
TopoDS_Shape CrankArm;
|
||||
TopoDS_Shape CylinderHead;
|
||||
TopoDS_Shape Propeller;
|
||||
TopoDS_Shape EngineBlock;
|
||||
|
||||
//BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
|
||||
//BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
|
||||
//BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
|
||||
//BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
|
||||
BRepTools::Read(CrankArm,argv[1],B);
|
||||
BRepTools::Read(CylinderHead,argv[2],B);
|
||||
BRepTools::Read(Propeller,argv[3],B);
|
||||
BRepTools::Read(EngineBlock,argv[4],B);
|
||||
|
||||
if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure.\n";}
|
||||
|
||||
|
||||
OSD_Timer myTimer;
|
||||
myTimer.Start();
|
||||
|
||||
Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
|
||||
Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
|
||||
Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
|
||||
Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
|
||||
|
||||
GetMapOfAIS().Bind(myAisCylinderHead,"a");
|
||||
GetMapOfAIS().Bind(myAisEngineBlock,"b");
|
||||
GetMapOfAIS().Bind(myAisCrankArm,"c");
|
||||
GetMapOfAIS().Bind(myAisPropeller,"d");
|
||||
|
||||
myAisCylinderHead->SetMutable (Standard_True);
|
||||
myAisEngineBlock ->SetMutable (Standard_True);
|
||||
myAisCrankArm ->SetMutable (Standard_True);
|
||||
myAisPropeller ->SetMutable (Standard_True);
|
||||
|
||||
TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
|
||||
TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
|
||||
TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
|
||||
|
||||
TheAISContext()->Display (myAisCylinderHead, Standard_False);
|
||||
TheAISContext()->Display (myAisEngineBlock, Standard_False);
|
||||
TheAISContext()->Display (myAisCrankArm, Standard_False);
|
||||
TheAISContext()->Display (myAisPropeller, Standard_False);
|
||||
|
||||
TheAISContext()->Deactivate(myAisCylinderHead);
|
||||
TheAISContext()->Deactivate(myAisEngineBlock );
|
||||
TheAISContext()->Deactivate(myAisCrankArm );
|
||||
TheAISContext()->Deactivate(myAisPropeller );
|
||||
|
||||
// Boucle de mouvement
|
||||
for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
|
||||
|
||||
angleA = thread*myAngle*M_PI/180;
|
||||
X = Sin(angleA)*3/8;
|
||||
angleB = atan(X / Sqrt(-X * X + 1));
|
||||
Standard_Real decal(25*0.6);
|
||||
|
||||
|
||||
//Build a transformation on the display
|
||||
gp_Trsf aPropellerTrsf;
|
||||
aPropellerTrsf.SetRotation(Ax1,angleA);
|
||||
TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
|
||||
|
||||
gp_Ax3 base(gp_Pnt(3*decal*(1-Cos(angleA)),-3*decal*Sin(angleA),0),gp_Vec(0,0,1),gp_Vec(1,0,0));
|
||||
gp_Trsf aCrankArmTrsf;
|
||||
aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
|
||||
TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
|
||||
|
||||
TheAISContext()->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
|
||||
TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
|
||||
|
||||
myAisCrankArm ->ResetTransformation();
|
||||
myAisPropeller->ResetTransformation();
|
||||
|
||||
myAisCrankArm -> Set(myNewCrankArm );
|
||||
myAisPropeller -> Set(myNewPropeller);
|
||||
|
||||
TheAISContext()->Activate(myAisCylinderHead,0);
|
||||
TheAISContext()->Activate(myAisEngineBlock,0 );
|
||||
TheAISContext()->Activate(myAisCrankArm ,0 );
|
||||
TheAISContext()->Activate(myAisPropeller ,0 );
|
||||
|
||||
myTimer.Stop();
|
||||
myTimer.Show();
|
||||
myTimer.Start();
|
||||
|
||||
TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
|
||||
TheAISContext()->Redisplay(myAisPropeller,Standard_False);
|
||||
|
||||
TheAISContext()->UpdateCurrentViewer();
|
||||
a3DView()->Redraw();
|
||||
|
||||
myTimer.Stop();
|
||||
myTimer.Show();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
//function : VShading
|
||||
//purpose : Sharpen or roughten the quality of the shading
|
||||
@@ -5763,10 +5644,6 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
|
||||
"\n\t\t: Tests the animation of an object along a predefined trajectory.",
|
||||
__FILE__,VPerf,group);
|
||||
|
||||
theCommands.Add("vanimation",
|
||||
"vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
|
||||
__FILE__,VAnimation,group);
|
||||
|
||||
theCommands.Add("vsetshading",
|
||||
"vsetshading : vsetshading name Quality(default=0.0008) "
|
||||
"\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
|
||||
|
@@ -70,8 +70,9 @@ Standard_Boolean ViewerTest_AutoUpdater::parseRedrawMode (const TCollection_Asci
|
||||
//=======================================================================
|
||||
void ViewerTest_AutoUpdater::Invalidate()
|
||||
{
|
||||
myContext.Nullify();
|
||||
if (myWasAutoUpdate)
|
||||
myToUpdate = ViewerTest_AutoUpdater::RedrawMode_Suppressed;
|
||||
if (myWasAutoUpdate
|
||||
&& !myView.IsNull())
|
||||
{
|
||||
myView->SetImmediateUpdate (myWasAutoUpdate);
|
||||
}
|
||||
@@ -83,16 +84,34 @@ void ViewerTest_AutoUpdater::Invalidate()
|
||||
//=======================================================================
|
||||
void ViewerTest_AutoUpdater::Update()
|
||||
{
|
||||
if (myContext.IsNull())
|
||||
if (!myView.IsNull())
|
||||
{
|
||||
return;
|
||||
myView->SetImmediateUpdate (myWasAutoUpdate);
|
||||
}
|
||||
|
||||
// update the screen and redraw the view
|
||||
myView->SetImmediateUpdate (myWasAutoUpdate);
|
||||
if ((myWasAutoUpdate && myToUpdate != ViewerTest_AutoUpdater::RedrawMode_Suppressed)
|
||||
|| myToUpdate == ViewerTest_AutoUpdater::RedrawMode_Forced)
|
||||
switch (myToUpdate)
|
||||
{
|
||||
myContext->UpdateCurrentViewer();
|
||||
case ViewerTest_AutoUpdater::RedrawMode_Suppressed:
|
||||
{
|
||||
return;
|
||||
}
|
||||
case ViewerTest_AutoUpdater::RedrawMode_Auto:
|
||||
{
|
||||
if (!myWasAutoUpdate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
case ViewerTest_AutoUpdater::RedrawMode_Forced:
|
||||
{
|
||||
if (!myContext.IsNull())
|
||||
{
|
||||
myContext->UpdateCurrentViewer();
|
||||
}
|
||||
else if (!myView.IsNull())
|
||||
{
|
||||
myView->Redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -78,6 +78,7 @@
|
||||
#include <AIS_Trihedron.hxx>
|
||||
#include <AIS_Axis.hxx>
|
||||
#include <gp_Trsf.hxx>
|
||||
#include <gp_Quaternion.hxx>
|
||||
#include <TopLoc_Location.hxx>
|
||||
|
||||
#include <HLRAlgo_Projector.hxx>
|
||||
@@ -2491,12 +2492,15 @@ static int VDrawText (Draw_Interpretor& theDI,
|
||||
Handle(AIS_TextLabel) aTextPrs;
|
||||
ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
|
||||
|
||||
Standard_Boolean isNewPrs = Standard_False;
|
||||
if (GetMapOfAIS().IsBound2 (aName))
|
||||
{
|
||||
aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
|
||||
aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
|
||||
}
|
||||
else
|
||||
|
||||
if (aTextPrs.IsNull())
|
||||
{
|
||||
isNewPrs = Standard_True;
|
||||
aTextPrs = new AIS_TextLabel();
|
||||
aTextPrs->SetFont ("Courier");
|
||||
}
|
||||
@@ -2851,7 +2855,15 @@ static int VDrawText (Draw_Interpretor& theDI,
|
||||
{
|
||||
aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)());
|
||||
}
|
||||
ViewerTest::Display (aName, aTextPrs, Standard_False);
|
||||
|
||||
if (isNewPrs)
|
||||
{
|
||||
ViewerTest::Display (aName, aTextPrs, Standard_False);
|
||||
}
|
||||
else
|
||||
{
|
||||
aContext->Redisplay (aTextPrs, Standard_False, Standard_True);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3699,12 +3711,47 @@ static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char*
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
//! Auxiliary function for parsing translation vector - either 2D or 3D.
|
||||
static Standard_Integer parseTranslationVec (Standard_Integer theArgNb,
|
||||
const char** theArgVec,
|
||||
gp_Vec& theVec)
|
||||
{
|
||||
if (theArgNb < 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TCollection_AsciiString anX (theArgVec[0]);
|
||||
TCollection_AsciiString anY (theArgVec[1]);
|
||||
if (!anX.IsRealValue()
|
||||
|| !anY.IsRealValue())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
theVec.SetX (anX.RealValue());
|
||||
theVec.SetY (anY.RealValue());
|
||||
if (theArgNb >= 3)
|
||||
{
|
||||
TCollection_AsciiString anZ (theArgVec[2]);
|
||||
if (anZ.IsRealValue())
|
||||
{
|
||||
theVec.SetZ (anZ.RealValue());
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : VSetLocation
|
||||
//purpose : Change location of AIS interactive object
|
||||
//=======================================================================
|
||||
|
||||
static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
|
||||
static Standard_Integer VSetLocation (Draw_Interpretor& theDI,
|
||||
Standard_Integer theArgNb,
|
||||
const char** theArgVec)
|
||||
{
|
||||
@@ -3716,36 +3763,301 @@ static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
|
||||
return 1;
|
||||
}
|
||||
|
||||
TCollection_AsciiString aName;
|
||||
gp_Vec aLocVec;
|
||||
Standard_Boolean isSetLoc = Standard_False;
|
||||
|
||||
Standard_Integer anArgIter = 1;
|
||||
for (; anArgIter < theArgNb; ++anArgIter)
|
||||
Standard_Boolean toPrintInfo = Standard_True;
|
||||
Handle(AIS_InteractiveObject) anObj;
|
||||
TCollection_AsciiString aCmdName (theArgVec[0]);
|
||||
aCmdName.LowerCase();
|
||||
for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
|
||||
{
|
||||
Standard_CString anArg = theArgVec[anArgIter];
|
||||
if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
|
||||
TCollection_AsciiString anArg = theArgVec[anArgIter];
|
||||
anArg.LowerCase();
|
||||
if (anUpdateTool.parseRedrawMode (anArg))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (aName.IsEmpty())
|
||||
else if (anObj.IsNull())
|
||||
{
|
||||
aName = anArg;
|
||||
}
|
||||
else if (!isSetLoc)
|
||||
{
|
||||
isSetLoc = Standard_True;
|
||||
if (anArgIter + 1 >= theArgNb)
|
||||
const TCollection_AsciiString aName (theArgVec[anArgIter]);
|
||||
const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
|
||||
if (aMap.IsBound2 (aName))
|
||||
{
|
||||
std::cout << "Error: syntax error at '" << anArg << "'\n";
|
||||
anObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
|
||||
}
|
||||
if (anObj.IsNull())
|
||||
{
|
||||
std::cout << "Error: object '" << aName << "' is not displayed!\n";
|
||||
return 1;
|
||||
}
|
||||
aLocVec.SetX (Draw::Atof (theArgVec[anArgIter++]));
|
||||
aLocVec.SetY (Draw::Atof (theArgVec[anArgIter]));
|
||||
if (anArgIter + 1 < theArgNb)
|
||||
}
|
||||
else if (anArg == "-reset")
|
||||
{
|
||||
toPrintInfo = Standard_False;
|
||||
aContext->SetLocation (anObj, gp_Trsf());
|
||||
}
|
||||
else if (anArg == "-copyfrom"
|
||||
|| anArg == "-copy")
|
||||
{
|
||||
if (anArgIter + 1 >= theArgNb)
|
||||
{
|
||||
aLocVec.SetZ (Draw::Atof (theArgVec[++anArgIter]));
|
||||
std::cout << "Syntax error at '" << anArg << "'\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]);
|
||||
const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
|
||||
Handle(AIS_InteractiveObject) anObj2;
|
||||
if (aMap.IsBound2 (aName2))
|
||||
{
|
||||
anObj2 = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName2));
|
||||
}
|
||||
if (anObj2.IsNull())
|
||||
{
|
||||
std::cout << "Error: object '" << aName2 << "' is not displayed!\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
++anArgIter;
|
||||
aContext->SetLocation (anObj, anObj2->LocalTransformation());
|
||||
}
|
||||
else if (anArg == "-rotate")
|
||||
{
|
||||
toPrintInfo = Standard_False;
|
||||
if (anArgIter + 7 >= theArgNb)
|
||||
{
|
||||
std::cout << "Syntax error at '" << anArg << "'\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
gp_Trsf aTrsf;
|
||||
aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]),
|
||||
Draw::Atof (theArgVec[anArgIter + 2]),
|
||||
Draw::Atof (theArgVec[anArgIter + 3])),
|
||||
gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]),
|
||||
Draw::Atof (theArgVec[anArgIter + 5]),
|
||||
Draw::Atof (theArgVec[anArgIter + 6]))),
|
||||
Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0));
|
||||
anArgIter += 7;
|
||||
|
||||
aTrsf = anObj->LocalTransformation() * aTrsf;
|
||||
aContext->SetLocation (anObj, aTrsf);
|
||||
}
|
||||
else if (anArg == "-translate")
|
||||
{
|
||||
toPrintInfo = Standard_False;
|
||||
gp_Vec aLocVec;
|
||||
Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
|
||||
anArgIter += aNbParsed;
|
||||
if (aNbParsed == 0)
|
||||
{
|
||||
std::cout << "Syntax error at '" << anArg << "'\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
gp_Trsf aTrsf;
|
||||
aTrsf.SetTranslationPart (aLocVec);
|
||||
aTrsf = anObj->LocalTransformation() * aTrsf;
|
||||
aContext->SetLocation (anObj, aTrsf);
|
||||
}
|
||||
else if (anArg == "-scale"
|
||||
|| anArg == "-setscale")
|
||||
{
|
||||
toPrintInfo = Standard_False;
|
||||
gp_XYZ aScaleLoc;
|
||||
Standard_Real aScale = 1.0;
|
||||
Standard_Boolean toPrintScale = Standard_True;
|
||||
Standard_Boolean hasScaleLoc = Standard_False;
|
||||
if (anArgIter + 4 < theArgNb)
|
||||
{
|
||||
TCollection_AsciiString aScaleArgs[4] =
|
||||
{
|
||||
TCollection_AsciiString (theArgVec[anArgIter + 1]),
|
||||
TCollection_AsciiString (theArgVec[anArgIter + 2]),
|
||||
TCollection_AsciiString (theArgVec[anArgIter + 3]),
|
||||
TCollection_AsciiString (theArgVec[anArgIter + 4])
|
||||
};
|
||||
Standard_Integer aScaleArgIter = 0;
|
||||
for (; aScaleArgIter < 4; ++aScaleArgIter)
|
||||
{
|
||||
if (!aScaleArgs[aScaleArgIter].IsRealValue())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (aScaleArgIter == 4)
|
||||
{
|
||||
aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue());
|
||||
aScale = aScaleArgs[3].RealValue();
|
||||
anArgIter += 4;
|
||||
toPrintScale = Standard_False;
|
||||
hasScaleLoc = Standard_True;
|
||||
}
|
||||
else if (aScaleArgIter >= 1)
|
||||
{
|
||||
aScale = aScaleArgs[0].RealValue();
|
||||
++anArgIter;
|
||||
toPrintScale = Standard_False;
|
||||
}
|
||||
}
|
||||
else if (anArgIter + 1 < theArgNb)
|
||||
{
|
||||
TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]);
|
||||
if (aScaleArg.IsRealValue())
|
||||
{
|
||||
aScale = aScaleArg.RealValue();
|
||||
++anArgIter;
|
||||
toPrintScale = Standard_False;
|
||||
}
|
||||
}
|
||||
|
||||
if (toPrintScale)
|
||||
{
|
||||
if (anArg == "-setscale")
|
||||
{
|
||||
std::cout << "Syntax error at '" << anArg << "'\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
char aText[1024];
|
||||
Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor());
|
||||
theDI << aText;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (anArg == "-setscale")
|
||||
{
|
||||
gp_Trsf aTrsf = anObj->LocalTransformation();
|
||||
if (hasScaleLoc)
|
||||
{
|
||||
aTrsf.SetScale (aScaleLoc, aScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
aTrsf.SetScaleFactor (aScale);
|
||||
}
|
||||
aContext->SetLocation (anObj, aTrsf);
|
||||
}
|
||||
else
|
||||
{
|
||||
gp_Trsf aTrsf;
|
||||
if (hasScaleLoc)
|
||||
{
|
||||
aTrsf.SetScale (aScaleLoc, aScale);
|
||||
aTrsf = anObj->LocalTransformation() * aTrsf;
|
||||
}
|
||||
else
|
||||
{
|
||||
aTrsf = anObj->LocalTransformation();
|
||||
aTrsf.SetScaleFactor (aTrsf.ScaleFactor() * aScale);
|
||||
}
|
||||
aContext->SetLocation (anObj, aTrsf);
|
||||
}
|
||||
}
|
||||
else if (anArg == "-mirror")
|
||||
{
|
||||
toPrintInfo = Standard_False;
|
||||
if (anArgIter + 6 >= theArgNb)
|
||||
{
|
||||
std::cout << "Syntax error at '" << anArg << "'\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
gp_Trsf aTrsf;
|
||||
aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
|
||||
Draw::Atof(theArgVec[theArgNb - 5]),
|
||||
Draw::Atof(theArgVec[theArgNb - 4])),
|
||||
gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
|
||||
Draw::Atof(theArgVec[theArgNb - 2]),
|
||||
Draw::Atof(theArgVec[theArgNb - 1]))));
|
||||
anArgIter += 6;
|
||||
aTrsf = anObj->LocalTransformation() * aTrsf;
|
||||
aContext->SetLocation (anObj, aTrsf);
|
||||
}
|
||||
else if (anArg == "-setrotation"
|
||||
|| anArg == "-rotation")
|
||||
{
|
||||
toPrintInfo = Standard_False;
|
||||
if (anArgIter + 4 < theArgNb)
|
||||
{
|
||||
TCollection_AsciiString aQuatArgs[4] =
|
||||
{
|
||||
TCollection_AsciiString (theArgVec[anArgIter + 1]),
|
||||
TCollection_AsciiString (theArgVec[anArgIter + 2]),
|
||||
TCollection_AsciiString (theArgVec[anArgIter + 3]),
|
||||
TCollection_AsciiString (theArgVec[anArgIter + 4])
|
||||
};
|
||||
Standard_Integer aQuatArgIter = 0;
|
||||
for (; aQuatArgIter < 4; ++aQuatArgIter)
|
||||
{
|
||||
if (!aQuatArgs[aQuatArgIter].IsRealValue())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (aQuatArgIter == 4)
|
||||
{
|
||||
anArgIter += 4;
|
||||
const gp_Quaternion aQuat (aQuatArgs[0].RealValue(),
|
||||
aQuatArgs[1].RealValue(),
|
||||
aQuatArgs[2].RealValue(),
|
||||
aQuatArgs[3].RealValue());
|
||||
gp_Trsf aTrsf = anObj->LocalTransformation();
|
||||
aTrsf.SetRotation (aQuat);
|
||||
aContext->SetLocation (anObj, aTrsf);
|
||||
continue;
|
||||
}
|
||||
else if (anArg == "-setrotation")
|
||||
{
|
||||
std::cout << "Syntax error at '" << anArg << "'\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
char aText[1024];
|
||||
const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation();
|
||||
Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W());
|
||||
theDI << aText;
|
||||
}
|
||||
else if (anArg == "-setlocation"
|
||||
|| anArg == "-location")
|
||||
{
|
||||
toPrintInfo = Standard_False;
|
||||
gp_Vec aLocVec;
|
||||
Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec);
|
||||
anArgIter += aNbParsed;
|
||||
if (aNbParsed != 0)
|
||||
{
|
||||
gp_Trsf aTrsf = anObj->LocalTransformation();
|
||||
aTrsf.SetTranslationPart (aLocVec);
|
||||
aContext->SetLocation (anObj, aTrsf);
|
||||
}
|
||||
else if (anArg == "-setlocation")
|
||||
{
|
||||
std::cout << "Syntax error at '" << anArg << "'\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
char aText[1024];
|
||||
const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart();
|
||||
Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z());
|
||||
theDI << aText;
|
||||
}
|
||||
else if (aCmdName == "vsetlocation")
|
||||
{
|
||||
// compatibility with old syntax
|
||||
gp_Vec aLocVec;
|
||||
Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec);
|
||||
if (aNbParsed == 0)
|
||||
{
|
||||
std::cout << "Syntax error at '" << anArg << "'\n";
|
||||
return 1;
|
||||
}
|
||||
anArgIter = anArgIter + aNbParsed - 1;
|
||||
|
||||
gp_Trsf aTrsf;
|
||||
aTrsf.SetTranslationPart (aLocVec);
|
||||
aContext->SetLocation (anObj, aTrsf);
|
||||
toPrintInfo = Standard_False;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3754,183 +4066,27 @@ static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/,
|
||||
}
|
||||
}
|
||||
|
||||
// find object
|
||||
const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
|
||||
Handle(AIS_InteractiveObject) anIObj;
|
||||
if (aMap.IsBound2 (aName))
|
||||
if (anObj.IsNull())
|
||||
{
|
||||
anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
|
||||
}
|
||||
if (anIObj.IsNull())
|
||||
{
|
||||
std::cout << "Error: object '" << aName << "' is not displayed!\n";
|
||||
std::cout << "Syntax error - wrong number of arguments\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
gp_Trsf aTrsf;
|
||||
aTrsf.SetTranslation (aLocVec);
|
||||
TopLoc_Location aLocation (aTrsf);
|
||||
aContext->SetLocation (anIObj, aLocation);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : TransformPresentation
|
||||
//purpose : Change transformation of AIS interactive object
|
||||
//=======================================================================
|
||||
static Standard_Integer LocalTransformPresentation (Draw_Interpretor& /*theDi*/,
|
||||
Standard_Integer theArgNb,
|
||||
const char** theArgVec)
|
||||
{
|
||||
if (theArgNb <= 1)
|
||||
else if (!toPrintInfo)
|
||||
{
|
||||
std::cout << "Error: too few arguments.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
|
||||
ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView());
|
||||
if (aContext.IsNull())
|
||||
{
|
||||
std::cout << "Error: no active view!\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
gp_Trsf aTrsf;
|
||||
Standard_Integer aLast = theArgNb;
|
||||
const char* aName = theArgVec[0];
|
||||
|
||||
Standard_Boolean isReset = Standard_False;
|
||||
Standard_Boolean isMove = Standard_False;
|
||||
|
||||
// Prefix 'vloc'
|
||||
aName += 4;
|
||||
|
||||
if (!strcmp (aName, "reset"))
|
||||
{
|
||||
isReset = Standard_True;
|
||||
}
|
||||
else if (!strcmp (aName, "move"))
|
||||
{
|
||||
if (theArgNb < 3)
|
||||
{
|
||||
std::cout << "Error: too few arguments.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
|
||||
|
||||
Handle(AIS_InteractiveObject) anIObj;
|
||||
if (aMap.IsBound2 (theArgVec[theArgNb - 1]))
|
||||
{
|
||||
anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[theArgNb - 1]));
|
||||
}
|
||||
|
||||
if (anIObj.IsNull())
|
||||
{
|
||||
std::cout << "Error: object '" << theArgVec[theArgNb - 1] << "' is not displayed!\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
isMove = Standard_True;
|
||||
|
||||
aTrsf = anIObj->Transformation();
|
||||
aLast = theArgNb - 1;
|
||||
}
|
||||
else if (!strcmp (aName, "translate"))
|
||||
{
|
||||
if (theArgNb < 5)
|
||||
{
|
||||
std::cout << "Error: too few arguments.\n";
|
||||
return 1;
|
||||
}
|
||||
aTrsf.SetTranslation (gp_Vec (Draw::Atof (theArgVec[theArgNb - 3]),
|
||||
Draw::Atof (theArgVec[theArgNb - 2]),
|
||||
Draw::Atof (theArgVec[theArgNb - 1])));
|
||||
aLast = theArgNb - 3;
|
||||
}
|
||||
else if (!strcmp (aName, "rotate"))
|
||||
{
|
||||
if (theArgNb < 9)
|
||||
{
|
||||
std::cout << "Error: too few arguments.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
aTrsf.SetRotation (
|
||||
gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[theArgNb - 7]),
|
||||
Draw::Atof (theArgVec[theArgNb - 6]),
|
||||
Draw::Atof (theArgVec[theArgNb - 5])),
|
||||
gp_Vec (Draw::Atof (theArgVec[theArgNb - 4]),
|
||||
Draw::Atof (theArgVec[theArgNb - 3]),
|
||||
Draw::Atof (theArgVec[theArgNb - 2]))),
|
||||
Draw::Atof (theArgVec[theArgNb - 1]) * (M_PI / 180.0));
|
||||
|
||||
aLast = theArgNb - 7;
|
||||
}
|
||||
else if (!strcmp (aName, "mirror"))
|
||||
{
|
||||
if (theArgNb < 8)
|
||||
{
|
||||
std::cout << "Error: too few arguments.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]),
|
||||
Draw::Atof(theArgVec[theArgNb - 5]),
|
||||
Draw::Atof(theArgVec[theArgNb - 4])),
|
||||
gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]),
|
||||
Draw::Atof(theArgVec[theArgNb - 2]),
|
||||
Draw::Atof(theArgVec[theArgNb - 1]))));
|
||||
aLast = theArgNb - 6;
|
||||
}
|
||||
else if (!strcmp (aName, "scale"))
|
||||
{
|
||||
if (theArgNb < 6)
|
||||
{
|
||||
std::cout << "Error: too few arguments.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
aTrsf.SetScale (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 4]),
|
||||
Draw::Atof(theArgVec[theArgNb - 3]),
|
||||
Draw::Atof(theArgVec[theArgNb - 2])),
|
||||
Draw::Atof(theArgVec[theArgNb - 1]));
|
||||
aLast = theArgNb - 4;
|
||||
}
|
||||
|
||||
for (Standard_Integer anIdx = 1; anIdx < aLast; anIdx++)
|
||||
{
|
||||
// find object
|
||||
const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
|
||||
Handle(AIS_InteractiveObject) anIObj;
|
||||
if (aMap.IsBound2 (theArgVec[anIdx]))
|
||||
{
|
||||
anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theArgVec[anIdx]));
|
||||
}
|
||||
if (anIObj.IsNull())
|
||||
{
|
||||
std::cout << "Error: object '" << theArgVec[anIdx] << "' is not displayed!\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (isReset)
|
||||
{
|
||||
// aTrsf already identity
|
||||
}
|
||||
else if (isMove)
|
||||
{
|
||||
aTrsf = anIObj->LocalTransformation() * anIObj->Transformation().Inverted() * aTrsf;
|
||||
}
|
||||
else
|
||||
{
|
||||
aTrsf = anIObj->LocalTransformation() * aTrsf;
|
||||
}
|
||||
|
||||
TopLoc_Location aLocation (aTrsf);
|
||||
aContext->SetLocation (anIObj, aLocation);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const gp_Trsf aTrsf = anObj->LocalTransformation();
|
||||
const gp_XYZ aLoc = aTrsf.TranslationPart();
|
||||
const gp_Quaternion aRot = aTrsf.GetRotation();
|
||||
char aText[4096];
|
||||
Sprintf (aText, "Location: %g %g %g\n"
|
||||
"Rotation: %g %g %g %g\n"
|
||||
"Scale: %g\n",
|
||||
aLoc.X(), aLoc.Y(), aLoc.Z(),
|
||||
aRot.X(), aRot.Y(), aRot.Z(), aRot.W(),
|
||||
aTrsf.ScaleFactor());
|
||||
theDI << aText;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -6411,9 +6567,29 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
|
||||
"vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n",
|
||||
__FILE__,VDrawSphere,group);
|
||||
|
||||
theCommands.Add ("vlocation",
|
||||
"vlocation name"
|
||||
"\n\t\t: [-reset]"
|
||||
"\n\t\t: [-copyFrom otherName]"
|
||||
"\n\t\t: [-translate X Y [Z]]"
|
||||
"\n\t\t: [-rotate x y z dx dy dz angle]"
|
||||
"\n\t\t: [-scale [X Y Z] scale]"
|
||||
"\n\t\t: [-mirror x y z dx dy dz]"
|
||||
"\n\t\t: [-setLocation X Y [Z]]"
|
||||
"\n\t\t: [-setRotation QX QY QZ QW]"
|
||||
"\n\t\t: [-setScale [X Y Z] scale]"
|
||||
"\n\t\t: Object local transformation management:"
|
||||
"\n\t\t: -reset reset transformation to identity"
|
||||
"\n\t\t: -translate translate object"
|
||||
"\n\t\t: -rotate applies rotation to local transformation"
|
||||
"\n\t\t: -scale applies scale to local transformation"
|
||||
"\n\t\t: -mirror applies mirror to local transformation"
|
||||
"\n\t\t: -setLocation assign object location"
|
||||
"\n\t\t: -setRotation assign object rotation (quaternion)"
|
||||
"\n\t\t: -setScale assign object scale factor",
|
||||
__FILE__, VSetLocation, group);
|
||||
theCommands.Add ("vsetlocation",
|
||||
"vsetlocation [-noupdate|-update] name x y z"
|
||||
"\n\t\t: Set new location for an interactive object.",
|
||||
"alias for vlocation",
|
||||
__FILE__, VSetLocation, group);
|
||||
|
||||
theCommands.Add (
|
||||
@@ -6562,36 +6738,6 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
|
||||
"\n",
|
||||
__FILE__, VPointCloud, group);
|
||||
|
||||
theCommands.Add("vlocreset",
|
||||
"vlocreset name1 name2 ...\n\t\t remove object local transformation",
|
||||
__FILE__,
|
||||
LocalTransformPresentation, group);
|
||||
|
||||
theCommands.Add("vlocmove",
|
||||
"vlocmove name1 name2 ... name\n\t\t set local transform to match transform of 'name'",
|
||||
__FILE__,
|
||||
LocalTransformPresentation, group);
|
||||
|
||||
theCommands.Add("vloctranslate",
|
||||
"vloctranslate name1 name2 ... dx dy dz\n\t\t applies translation to local transformation",
|
||||
__FILE__,
|
||||
LocalTransformPresentation, group);
|
||||
|
||||
theCommands.Add("vlocrotate",
|
||||
"vlocrotate name1 name2 ... x y z dx dy dz angle\n\t\t applies rotation to local transformation",
|
||||
__FILE__,
|
||||
LocalTransformPresentation, group);
|
||||
|
||||
theCommands.Add("vlocmirror",
|
||||
"vlocmirror name x y z dx dy dz\n\t\t applies mirror to local transformation",
|
||||
__FILE__,
|
||||
LocalTransformPresentation, group);
|
||||
|
||||
theCommands.Add("vlocscale",
|
||||
"vlocscale name x y z scale\n\t\t applies scale to local transformation",
|
||||
__FILE__,
|
||||
LocalTransformPresentation, group);
|
||||
|
||||
theCommands.Add("vpriority",
|
||||
"vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object",
|
||||
__FILE__,
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user