-// Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
#include "OCCViewer_ViewModel.h"
-#include "OCCViewer.h"
-#include "OCCViewer_ViewWindow.h"
#include "OCCViewer_ViewFrame.h"
#include "OCCViewer_VService.h"
#include "OCCViewer_ViewPort3d.h"
#include <AIS_Axis.hxx>
#include <Prs3d_Drawer.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
+#include <StdSelect_ViewerSelector3d.hxx>
#include <Graphic3d_Texture2Dmanual.hxx>
#include <Graphic3d_MaterialAspect.hxx>
#include <Basics_OCCTVersion.hxx>
+namespace
+{
+ void setCappingColor(const Handle(Graphic3d_ClipPlane)& plane, const QColor& color)
+ {
+ Quantity_Color qcolor( color.redF(), color.greenF(), color.blueF(), Quantity_TOC_RGB );
+#if OCC_VERSION_LARGE < 0x07040000
+ Graphic3d_MaterialAspect aspect;
+ aspect.SetColor( qcolor );
+ plane->SetCappingMaterial( aspect );
+#else
+ plane->SetCappingColor( qcolor );
+#endif
+ }
+}
+
/*!
Get data for supported background modes: gradient types, identifiers and supported image formats
*/
*/
OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
: SUIT_ViewModel(),
- myBackgrounds(4, Qtx::BackgroundData( Qt::black )),
myIsRelative(true),
- myTopLayerId( 0 ),
+ myTopLayerId(0),
myTrihedronSize(100),
-#if OCC_VERSION_LARGE <= 0x07030000
- myIsUseLocalSelection(false),
-#endif
- myClippingDlg (NULL),
+ myBackgrounds(4, Qtx::BackgroundData(Qt::black)),
+ myClippingDlg(0),
myFitter(0)
{
// init CasCade viewers
- myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() );
+ myV3dViewer = OCCViewer_VService::CreateViewer();
//myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
setDefaultLights();
myAISContext = new AIS_InteractiveContext( myV3dViewer );
myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_LocalSelected)->SetColor( Quantity_NOC_WHITE );
myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_Selected)->SetColor( Quantity_NOC_WHITE );
-
+
// display isoline on planar faces (box for ex.)
myAISContext->IsoOnPlane( true );
// create color scale
myColorScale = new AIS_ColorScale();
myColorScale->SetZLayer( Graphic3d_ZLayerId_TopOSD );
+#if OCC_VERSION_LARGE < 0x07070000
myColorScale->SetTransformPersistence( Graphic3d_TransformPers::FromDeprecatedParams( Graphic3d_TMF_2d, gp_Pnt(-1, -1, 0) ) );
-
+#else
+ myColorScale->SetTransformPersistence( new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER) );
+#endif
+
/* create trihedron */
if ( DisplayTrihedron )
{
Handle(Prs3d_Drawer) drawer = myTrihedron->Attributes();
if (drawer->HasOwnDatumAspect()) {
Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
- daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
- daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
- daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
+ daspect->LineAspect(Prs3d_DP_XAxis)->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
+ daspect->LineAspect(Prs3d_DP_YAxis)->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
+ daspect->LineAspect(Prs3d_DP_ZAxis)->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
}
}
// set projection type to orthographic
myProjectionType = 0;
- mySelectionStyle = 0;
+ mySelectionStyle = OCCViewer_ViewWindow::RectStyle;
// set stereo parameters
myStereoType = 0;
myAnaglyphFilter = 0;
/*!
SLOT: called on mouse button press, stores current mouse position as start point for transformations
*/
-void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
+void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* /*theWindow*/, QMouseEvent* theEvent)
{
myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
}
myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
- if (!aHasShift) {
- myAISContext->ClearCurrents( false );
- emit deselection();
- }
-
if (myStartPnt == myEndPnt)
{
+ if (!aHasShift) {
+ myAISContext->ClearCurrents( false ); // todo: ClearCurrents is deprecated
+ emit deselection();
+ }
if ( !isPreselectionEnabled() ) {
Handle(V3d_View) aView3d = aView->getViewPort()->getView();
if ( !aView3d.IsNull() ) {
- myAISContext->MoveTo( myEndPnt.x(), myEndPnt.y(), aView3d, Standard_True );
+ myAISContext->MoveTo( myEndPnt.x(), myEndPnt.y(), aView3d, Standard_True );
}
}
myAISContext->ShiftSelect( Standard_True );
else
myAISContext->Select( Standard_True );
+ emit selectionChanged();
}
- else
- {
- if (aHasShift && myMultiSelectionEnabled)
- myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
- myEndPnt.x(), myEndPnt.y(),
- aView->getViewPort()->getView(), Standard_False );
- else
- myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
- myEndPnt.x(), myEndPnt.y(),
- aView->getViewPort()->getView(), Standard_False );
-
- int Nb = myAISContext->NbSelected();
- if( Nb>1 && !myMultiSelectionEnabled )
- {
- myAISContext->InitSelected();
- Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
- if( !anOwner.IsNull() )
- {
- myAISContext->ClearSelected( Standard_False );
- myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
- }
- }
- myAISContext->UpdateCurrentViewer();
- }
- emit selectionChanged();
+ //else
+ //{
+ // if (aHasShift && myMultiSelectionEnabled)
+ // myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
+ // myEndPnt.x(), myEndPnt.y(),
+ // aView->getViewPort()->getView(), Standard_False );
+ // else
+ // myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
+ // myEndPnt.x(), myEndPnt.y(),
+ // aView->getViewPort()->getView(), Standard_False );
+
+ // int Nb = myAISContext->NbSelected();
+ // if( Nb>1 && !myMultiSelectionEnabled )
+ // {
+ // myAISContext->InitSelected();
+ // Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
+ // if( !anOwner.IsNull() )
+ // {
+ // myAISContext->ClearSelected( Standard_False );
+ // myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
+ // }
+ // }
+
+ // myAISContext->UpdateCurrentViewer();
+ //}
}
/*!
switch ( theEvent->key() ) {
case Qt::Key_S:
if (!aHasShift) {
- myAISContext->ClearCurrents( false );
+ myAISContext->ClearCurrents( false ); // todo: ClearCurrents is deprecated
emit deselection();
}
break;
case Qt::Key_N:
if ( isPreselectionEnabled() ) {
-#if OCC_VERSION_LARGE <= 0x07030000
- if ( useLocalSelection() )
-#endif
- getAISContext()->HilightNextDetected( aView->getViewPort()->getView() );
+ getAISContext()->HilightNextDetected( aView->getViewPort()->getView() );
}
break;
case Qt::Key_P:
if ( isPreselectionEnabled() ) {
-#if OCC_VERSION_LARGE <= 0x07030000
- if ( useLocalSelection() )
-#endif
- getAISContext()->HilightPreviousDetected( aView->getViewPort()->getView() );
+ getAISContext()->HilightPreviousDetected( aView->getViewPort()->getView() );
}
break;
default:
}
-int OCCViewer_Viewer::selectionStyle() const
+OCCViewer_ViewWindow::SelectionStyle OCCViewer_Viewer::selectionStyle() const
{
return mySelectionStyle;
}
-void OCCViewer_Viewer::setSelectionStyle(const int theMode)
+void OCCViewer_Viewer::setSelectionStyle(OCCViewer_ViewWindow::SelectionStyle theMode)
{
if (mySelectionStyle != theMode) {
mySelectionStyle = theMode;
if( myInternalClipPlanes.IsEmpty() )
return;
- Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
- aMaterialAspect.SetColor( Quantity_Color( theColor.redF(), theColor.greenF(),
- theColor.blueF(), Quantity_TOC_RGB ) );
-#if OCC_VERSION_LARGE <= 0x07030000
- for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
- myInternalClipPlanes.Value(i)->SetCappingMaterial( aMaterialAspect );
-#else
for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
- aPlaneIt.Value()->SetCappingMaterial( aMaterialAspect );
-#endif
+ setCappingColor( aPlaneIt.Value(), theColor );
+
update();
}
Handle(Graphic3d_Texture2Dmanual) aTexture =
initClippingTexture( myDefaultTextureUsed, myClippingTexture,
myTextureModulated, myClippingTextureScale );
-#if OCC_VERSION_LARGE <= 0x07030000
- for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
- myInternalClipPlanes.Value(i)->SetCappingTexture( aTexture );
-#else
for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
aPlaneIt.Value()->SetCappingTexture( aTexture );
-#endif
update();
}
bool hilight, bool update )
{
if( !obj.IsNull() ) {
-#if OCC_VERSION_LARGE <= 0x07030000
- if( !myAISContext->HasOpenedContext() )
- {
-#endif
- if ( hilight && !myAISContext->IsSelected( obj ) )
- myAISContext->AddOrRemoveSelected( obj, false );
- else if ( !hilight && myAISContext->IsSelected( obj ) )
- myAISContext->AddOrRemoveSelected( obj, false );
-#if OCC_VERSION_LARGE <= 0x07030000
- }
-#endif
+ if ( hilight && !myAISContext->IsSelected( obj ) )
+ myAISContext->AddOrRemoveSelected( obj, false );
+ else if ( !hilight && myAISContext->IsSelected( obj ) )
+ myAISContext->AddOrRemoveSelected( obj, false );
}
if ( update )
*/
bool OCCViewer_Viewer::unHighlightAll( bool updateviewer, bool unselect )
{
-#if OCC_VERSION_LARGE <= 0x07030000
- if ( myAISContext->HasOpenedContext() ) {
-#endif
- if ( unselect ) {
- myAISContext->ClearSelected( updateviewer );
- } else {
- myAISContext->UnhilightSelected( updateviewer );
- }
-#if OCC_VERSION_LARGE <= 0x07030000
+ if ( unselect ) {
+ myAISContext->ClearSelected( updateviewer );
} else {
- if ( unselect ) {
- myAISContext->ClearCurrents( updateviewer );
- } else {
- myAISContext->UnhilightCurrents( updateviewer );
- }
+ myAISContext->UnhilightSelected( updateviewer );
}
-#endif
return false;
}
\param onlyInViewer - search object only in viewer (so object must be displayed)
*/
bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
- bool onlyInViewer )
+ bool /*onlyInViewer*/ )
{
AIS_ListOfInteractive List;
myAISContext->DisplayedObjects(List);
0 /*wireframe*/,
-1 /* selection mode */,
Standard_True /* update viewer*/,
- Standard_False /* allow decomposition */,
AIS_DS_Displayed /* display status */);
myAISContext->Deactivate( myTrihedron );
}
return new OCCViewer_ViewWindow(0, this);
}
-#if OCC_VERSION_LARGE <= 0x07030000
-/*!
- Sets using local selection state
- \param theIsUseLocalSelection - state
-*/
-void OCCViewer_Viewer::setUseLocalSelection(bool theIsUseLocalSelection)
-{
- myIsUseLocalSelection = theIsUseLocalSelection;
-}
-
-/*
- * Returns true if local context is opened or view model local state is set
- */
-bool OCCViewer_Viewer::useLocalSelection() const
-{
- if (myIsUseLocalSelection)
- return true;
- Handle(AIS_InteractiveContext) ic = getAISContext();
- return !ic.IsNull() && ic->HasOpenedContext();
-}
-#endif
-
// obsolete
QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
{
float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("3DViewer","trihedron_size", 100.);
- static float EPS = 5.0E-3;
+ static float EPS = 5.0E-3f;
theSize = getTrihedron()->Size();
theNewSize = aMaxSide*aSizeInPercents / 100.0;
aGraphic3dPlane->SetCapping( Standard_True );
// set capping color
- Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
- aMaterialAspect.SetColor( Quantity_Color( myClippingColor.redF(), myClippingColor.greenF(),
- myClippingColor.blueF(), Quantity_TOC_RGB ) );
- aGraphic3dPlane->SetCappingMaterial( aMaterialAspect );
+ setCappingColor( aGraphic3dPlane, myClippingColor );
// set capping texture
aGraphic3dPlane->SetCappingTexture( initClippingTexture( myDefaultTextureUsed, myClippingTexture,
Handle(AIS_InteractiveObject) anObj = anIter.Value();
Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (anObj);
if (!aShape.IsNull() && aShape->IsClippable()) {
- aShape->SetClipPlanes(myInternalClipPlanes);
+ aShape->SetClipPlanes(new Graphic3d_SequenceOfHClipPlane(myInternalClipPlanes)); // todo: store clipping planes in a handle?
}
}
}
Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (theObject);
if (!aShape.IsNull() && aShape->IsClippable())
{
- aShape->SetClipPlanes (myInternalClipPlanes);
+ aShape->SetClipPlanes (new Graphic3d_SequenceOfHClipPlane(myInternalClipPlanes)); // todo: store clipping planes in a handle?
}
}