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

Refactor code. Fix bug #25208: Set highlight mode to 1. Update 'vselect' test command: add ability to specify shape names into input arguments.

This commit is contained in:
mgn 2014-09-04 15:47:04 +04:00
parent 5f16c30bf2
commit e1ac993bc2
3 changed files with 154 additions and 62 deletions

View File

@ -36,6 +36,7 @@ IMPLEMENT_STANDARD_RTTIEXT(AIS_PointCloud, AIS_InteractiveObject)
AIS_PointCloud::AIS_PointCloud() AIS_PointCloud::AIS_PointCloud()
: AIS_InteractiveObject() : AIS_InteractiveObject()
{ {
SetHilightMode (1);
} }
//======================================================================= //=======================================================================
@ -67,20 +68,16 @@ void AIS_PointCloud::SetPoints (const Handle(TColgp_HArray1OfPnt)& theCoords
Standard_Integer aNumPoints = theCoords->Length(); Standard_Integer aNumPoints = theCoords->Length();
Standard_Boolean hasColors = !theColors.IsNull() && aNumPoints == theColors->Length(); Standard_Boolean hasColors = !theColors.IsNull() && aNumPoints == theColors->Length();
Standard_Integer aDiffColors = 0;
if (hasColors)
aDiffColors = theColors->Lower() - theCoords->Lower();
myPoints = new Graphic3d_ArrayOfPoints (aNumPoints, hasColors); myPoints = new Graphic3d_ArrayOfPoints (aNumPoints, hasColors);
for (Standard_Integer aPntIter = theCoords->Lower(); aPntIter <= theCoords->Upper(); aPntIter++) for (Standard_Integer aPntIter = theCoords->Lower(); aPntIter <= theCoords->Upper(); aPntIter++)
{ {
myPoints->AddVertex (theCoords->Value (aPntIter)); myPoints->AddVertex (theCoords->Value (aPntIter));
} if (hasColors)
myPoints->SetVertexColor (myPoints->VertexNumber(), theColors->Value (aPntIter + aDiffColors));
if (hasColors)
{
Standard_Integer aNumVertex = 1;
for(Standard_Integer aColorIter = theColors->Lower(); aColorIter <= theColors->Upper(); aColorIter++)
{
myPoints->SetVertexColor (aNumVertex, theColors->Value (aColorIter));
aNumVertex++;
}
} }
} }
@ -125,23 +122,29 @@ void AIS_PointCloud::SetColor (const Quantity_Color& theColor)
//======================================================================= //=======================================================================
void AIS_PointCloud::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/, void AIS_PointCloud::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
const Handle(Prs3d_Presentation)& thePresentation, const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer /*theMode*/) const Standard_Integer theMode)
{ {
thePresentation->Clear(); thePresentation->Clear();
const Handle(Graphic3d_ArrayOfPoints) aPoints = GetPoints(); switch (theMode)
if (aPoints.IsNull() || !aPoints->IsValid())
return;
Handle(Graphic3d_AspectMarker3d) aMarkerAspect = myDrawer->PointAspect()->Aspect();
if (!myDrawer->HasPointAspect())
{ {
aMarkerAspect->SetType (Aspect_TOM_POINT); case 0:
} {
const Handle(Graphic3d_ArrayOfPoints) aPoints = GetPoints();
if (aPoints.IsNull() || !aPoints->IsValid())
return;
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation); Handle(Graphic3d_AspectMarker3d) aMarkerAspect = myDrawer->PointAspect()->Aspect();
aGroup->SetGroupPrimitivesAspect (aMarkerAspect); if (!myDrawer->HasPointAspect())
aGroup->AddPrimitiveArray (aPoints); aMarkerAspect->SetType (Aspect_TOM_POINT);
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
aGroup->SetGroupPrimitivesAspect (aMarkerAspect);
aGroup->AddPrimitiveArray (aPoints);
}
default:
break;
}
} }
//======================================================================= //=======================================================================

View File

@ -5054,7 +5054,7 @@ static Standard_Integer VPointCloud (Draw_Interpretor& /*theDI*/,
Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
if (anAISContext.IsNull()) if (anAISContext.IsNull())
{ {
std::cerr << "Call 'vinit' before!\n"; std::cout << "Call 'vinit' before!" << std::endl;
return 1; return 1;
} }
@ -5191,7 +5191,7 @@ static Standard_Integer VPointCloud (Draw_Interpretor& /*theDI*/,
// Set array of points in point cloud object // Set array of points in point cloud object
aPointCloud->SetPoints (anArrayPoints); aPointCloud->SetPoints (anArrayPoints);
} }
else if (aModeSetPoints = 1) else if (aModeSetPoints == 1)
{ {
Handle(TColgp_HArray1OfPnt) aCoords = new TColgp_HArray1OfPnt (1, aNumberOfPoints); Handle(TColgp_HArray1OfPnt) aCoords = new TColgp_HArray1OfPnt (1, aNumberOfPoints);
for (Standard_Integer i = 1; i <= aNumberOfPoints; i++) for (Standard_Integer i = 1; i <= aNumberOfPoints; i++)
@ -5393,7 +5393,7 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
theCommands.Add ("vpointcloud", theCommands.Add ("vpointcloud",
"vpointcloud [name]" "vpointcloud [name]"
"\n\t\t: [-setmode ModeSetPoints]" "\n\t\t: [-mode ModeSetPoints]"
"\n\t\t: [-nbpointsonside NumberPointsOnSide]" "\n\t\t: [-nbpointsonside NumberPointsOnSide]"
"\n\t\t: [-markertype TypeOfMarker]" "\n\t\t: [-markertype TypeOfMarker]"
"\n\t\t: [-color ColorName]" "\n\t\t: [-color ColorName]"

View File

@ -50,6 +50,7 @@
#include <NIS_View.hxx> #include <NIS_View.hxx>
#include <NIS_Triangulated.hxx> #include <NIS_Triangulated.hxx>
#include <NIS_InteractiveContext.hxx> #include <NIS_InteractiveContext.hxx>
#include <AIS_LocalContext.hxx>
#include <AIS_InteractiveContext.hxx> #include <AIS_InteractiveContext.hxx>
#include <Draw_Interpretor.hxx> #include <Draw_Interpretor.hxx>
#include <Draw.hxx> #include <Draw.hxx>
@ -4355,61 +4356,147 @@ static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const
//purpose : Emulates different types of selection by mouse: //purpose : Emulates different types of selection by mouse:
// 1) single click selection // 1) single click selection
// 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2) // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
// 3) selection with polygon having corners at // 3) selection with polygon having corners at pixel positions (x1,y1),...,(xn,yn)
// pixel positions (x1,y1),...,(xn,yn) // 4) selection of specified shape(s)
// 4) any of these selections with shift button pressed // 5) any of these selections with shift button pressed
//======================================================================= //=======================================================================
static Standard_Integer VSelect (Draw_Interpretor& di, static Standard_Integer VSelect (Draw_Interpretor& /*theDI*/,
Standard_Integer argc, Standard_Integer theArgNum,
const char ** argv) const char ** theArgs)
{ {
if(argc < 3) if (theArgNum < 2)
{ {
di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n"; std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help "
<< theArgs[0] << "' for more information." << std::cout;
return 1; return 1;
} }
Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
if(myAIScontext.IsNull()) if (anAISContext.IsNull())
{ {
di << "use 'vinit' command before " << argv[0] << "\n"; std::cout << "Call 'vinit' before!" << std::endl;
return 1; return 1;
} }
const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); Standard_Integer anArgIter = 1;
aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2])); Standard_Boolean toSelectShape = Standard_False;
if(argc <= 4) Standard_Boolean isShift = Standard_False;
TCollection_AsciiString anArgum (theArgs[anArgIter]);
if (!anArgum.IsIntegerValue() && !anArgum.IsRealValue())
toSelectShape = Standard_True;
NCollection_Sequence<TCollection_AsciiString> aParams;
for (; anArgIter < theArgNum; ++anArgIter)
{ {
if(isShiftSelection) TCollection_AsciiString anArgum (theArgs[anArgIter]);
aCurrentEventManager->ShiftSelect(); anArgum.LowerCase();
else
aCurrentEventManager->Select(); if (anArgum == "-shift")
{
isShift = Standard_True;
continue;
}
if (!anArgum.IsEmpty())
aParams.Append (anArgum);
} }
else if(argc <= 6)
if (toSelectShape)
{ {
if(isShiftSelection) NCollection_Sequence<TCollection_AsciiString>::Iterator aParamIter (aParams);
aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4])); for (; aParamIter.More(); aParamIter.Next())
else {
aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4])); TCollection_AsciiString aShapeName = aParamIter.Value();
if (!GetMapOfAIS().IsBound2 (aShapeName))
{
std::cout << "Warning: no object with name '" << aShapeName << "' found." << std::endl;
continue;
}
const Handle(Standard_Transient) anObject = GetMapOfAIS().Find2 (aShapeName);
if (!anObject->IsKind (STANDARD_TYPE (AIS_InteractiveObject)))
{
std::cout << "Warning: no shape with type '" << STANDARD_TYPE (AIS_InteractiveObject)->Name()
<< "' found." << std::endl;
continue;
}
const Handle(AIS_InteractiveObject) anInterObject = Handle(AIS_InteractiveObject)::DownCast (anObject);
if (anInterObject.IsNull())
{
std::cout << "Error: 3D object is expected to be an AIS_InteractiveObject" << std::endl;
continue;
}
if (anAISContext->HasOpenedContext())
{
if (isShift)
anAISContext->LocalContext()->AddOrRemoveSelected (anInterObject);
else
anAISContext->LocalContext()->SetSelected (anInterObject);
}
else
{
if (isShift)
anAISContext->AddOrRemoveCurrentObject (anInterObject);
else
anAISContext->SetCurrentObject (anInterObject);
}
}
} }
else else
{ {
Standard_Integer anUpper = 0; Standard_Integer aNumParams = aParams.Length();
if (aNumParams < 2 || aNumParams % 2 != 0)
{
std::cout << "Error: no X Y defined." << std::endl;
return 1;
}
if(isShiftSelection) Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
anUpper = (argc-1)/2; aCurrentEventManager->MoveTo (Draw::Atoi (aParams (1).ToCString()),
Draw::Atoi (aParams (2).ToCString()));
if (aNumParams == 2)
{
if (isShift)
aCurrentEventManager->ShiftSelect();
else
aCurrentEventManager->Select();
}
else if (aNumParams == 4)
{
if (isShift)
aCurrentEventManager->ShiftSelect (Draw::Atoi (aParams (1).ToCString()),
Draw::Atoi (aParams (2).ToCString()),
Draw::Atoi (aParams (3).ToCString()),
Draw::Atoi (aParams (4).ToCString()));
else
aCurrentEventManager->Select (Draw::Atoi (aParams (1).ToCString()),
Draw::Atoi (aParams (2).ToCString()),
Draw::Atoi (aParams (3).ToCString()),
Draw::Atoi (aParams (4).ToCString()));
}
else else
anUpper = argc/2; {
TColgp_Array1OfPnt2d aPolyline(1,anUpper); Standard_Integer anUpper = 0;
if (isShift)
anUpper = (aNumParams - 1) / 2;
else
anUpper = aNumParams / 2;
TColgp_Array1OfPnt2d aPolyline (1, anUpper);
for(Standard_Integer i=1;i<=anUpper;++i) for (Standard_Integer i = 1; i <= anUpper; ++i)
aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i]))); aPolyline.SetValue (i, gp_Pnt2d (Draw::Atoi (aParams (2*i - 1).ToCString()),
Draw::Atoi (aParams (2*i).ToCString())));
if(isShiftSelection) if (isShift)
aCurrentEventManager->ShiftSelect(aPolyline); aCurrentEventManager->ShiftSelect (aPolyline);
else else
aCurrentEventManager->Select(aPolyline); aCurrentEventManager->Select (aPolyline);
}
} }
return 0; return 0;
} }
@ -6298,12 +6385,14 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
"diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]", "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
__FILE__, VDiffImage, group); __FILE__, VDiffImage, group);
theCommands.Add ("vselect", theCommands.Add ("vselect",
"vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n" "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-shift]\n"
"vselect name1 [name2 [name3 ... nameN]] [-shift]\n"
"- emulates different types of selection:\n" "- emulates different types of selection:\n"
"- 1) single click selection\n" "- 1) single click selection\n"
"- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n" "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
"- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n" "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
"- 4) any of these selections with shift button pressed", "- 4) selection of specified shape(s)\n"
"- 5) any of these selections with shift button pressed",
__FILE__, VSelect, group); __FILE__, VSelect, group);
theCommands.Add ("vmoveto", theCommands.Add ("vmoveto",
"vmoveto x y" "vmoveto x y"