open cascade Questions about the display

hello

Active CAD practitioner
TopoDS_Shape t_topo_box = BRepPrimAPI_MakeBox(1, 1, 1).Shape();
Handle(AIS_Shape) t_ais_box = new AIS_Shape(t_topo_box);
t_ais_box->SetColor(Quantity_NOC_CHOCOLATE);
m_context->Display(t_ais_box,true);

This code runs and displays normally in the MainWindow

MainWindow * a;
a =new MainWindow();
TopoDS_Shape t_topo_box = BRepPrimAPI_MakeBox(1, 1, 1).Shape();
Handle(AIS_Shape) t_ais_box = new AIS_Shape(t_topo_box);
t_ais_box->SetColor(Quantity_NOC_CHOCOLATE);
a->getContext()->Display(t_ais_box,true);
I have defined the MainWindow pointer ain pipeLayout as normal, running this code with no error but no display
 

natalia

Moderator
Staff member
Hi, hello)

Could you please explain in more details what the 'MainWindow' is?
Is it an instance of QMainWindow widget or some object from OCCT examples or a python instance or some else?
If you share some code how you organize the pipeLayout, it also be helpful.

Regards, Natalia
 

hello

Active CAD practitioner
Hi, hello)

Could you please explain in more details what the 'MainWindow' is?
Is it an instance of QMainWindow widget or some object from OCCT examples or a python instance or some else?
If you share some code how you organize the pipeLayout, it also be helpful.

Regards, Natalia
I can only call Display in the mainwindow. cpp and C3DView.cpp files to Display primitives. Calling display in other cpp files of the project will work, but I cannot display primitives in the Mainwindow window. Do you understand if I say this? I look forward to your reply. Thank you
 

natalia

Moderator
Staff member
Your code looks correct. There should not be a problem using display out of these classes.
Your case requires some debug and investigations.

What happens if you change background of the viewer instead of calling 'Display' for a presentation? Let's firstly check that your UI control is repainted out of these methods?

Regards, Natalia
 
Last edited:

hello

Active CAD practitioner
Your code looks correct. There should not be a problem using display out of these classes.
Your case requires some debug and investigations.

What happens if you change background of the viewer instead of calling 'Display' for a presentation? Let's firstly check that your UI control is repainted out of these methods?

Regards, Natalia
I'm sorry, I don't quite follow you. Could you be more specific?
 

natalia

Moderator
Staff member
Hi, hello

Add the next code out of the mentioned classes, in place, where your 'Display' doesn't provide the presentation display:

C++:
const Handle(V3d_Viewer)& viewer = GetContext()->CurrentViewer();
const Handle(V3d_View)& view = aViewer->ActiveViewIterator().Value();
view->SetBackgroundColor(Quantity_NOC_YELLOW);

Let's check if the viewer is updated correctly.
Regards, Natalia
 

hello

Active CAD practitioner
Thank you for your response, unfortunately the view was not updated correctly
 

Attachments

  • 1693208877684.png
    1693208877684.png
    29.1 KB · Views: 2

natalia

Moderator
Staff member
Hi hello

You know, for Qt-based applications, we usually implement own class, inherited from QWidget or QGLWidget with some special code to manage OCCT viewer.
The minimum example is available here: ‘https://gitlab.com/ssv/lessons’. It's the ViewerWidget in Lesson18_Qt_Widgets or in extras_viewerNative.
Also, there is example in OCCT samples, it's View.h, that is placed in occt/samples/qt/Common/src/View.hxx/.cxx.

The main thing is custom definition of 'paintEvent' that moves painting into OCCT viewer and setting some custom attributes for the widget.

These samples are not UI-based. To use this class in UI-controls, it's possible to create an empty widget in UI and set this widget inside it using C++ code.

Regards, Natalia
 

hello

Active CAD practitioner
I carefully reviewed the information you recommended, but I didn't understand what you were trying to get me to know. Or do you have a problem guessing what my code is
 

natalia

Moderator
Staff member
Hi hello,

I meant, what if to try using View or ViewerWidget instead of your C3DView for start. The goal is to avoid defining the widget for view as a UI designer class.

Regards, Natalia
 

kaviraj

Looking around for some CAD
1698493659118.png


i defined my canvas display inside a qhorizontal layout, but my problem is , while running its always getting displyaed in a minimized version
only after some resize event occurs on that window(like if if minimize or resize the screen), the problem is getting solved like below

1698493751998.png



def initialise_canvas_display_requirements(self):
self.canvas = qtDisplay.qtViewer3d(self.ui.centralwidget)
# self.canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # Set size policy
# self.canvas.setMinimumSize(1400,900)
# self.canvas.resize(1466,890)
# self.canvas.setMinimumSize(1450,900)
self.canvas.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding)
self.canvas.InitDriver()
self.display = self.canvas._display
self.display.View.SetBgGradientColors(
Quantity_Color(Quantity_NOC_WHITE),
Quantity_Color(Quantity_NOC_WHITE),
2,
True,
)
self.display.display_triedron()



self.ui.layout_random.addWidget(self.canvas)
self.display.register_select_callback(self.canvas_clicked_callback)
self.display.Viewer.SetDefaultLights()
self.display.Viewer.SetLightOn()
self.display.View.FitAll()

# self.mainwindow.showNormal()
# self.mainwindow.showMaximized()
# sys.exit(self.app.exec_())
# self.mainwindow.resize(self.mainwindow.width() + 100, self.mainwindow.height()) # Increase width by 1 pixel
# self.mainwindow.resize(self.mainwindow.width() - 100, self.mainwindow.height()) # Decrease width by 1 pixel




def display_shape_requirements(self,filepath):
self.data_obj=data_handle("project_data",filepath)
self.display.EraseAll()
self.data_obj.read_file()
self.shap=get_step_shape(self.data_obj.get_project_data("stepfile_path"))

# self.display.DisplayShape(self.shap)
self.display.DisplayColoredShape(self.shap,OCCViewer.rgb_color(80/255, 80/255, 80/255))
self.display.FitAll()
# self.display.EraseAll()
self.face_list=Get_from_topods_shape.topods_faces(self.shap)
self.display.SetSelectionMode(mode=TopAbs_FACE)


this is how i am initializing and displaying the canvas
i even tried automatically maximizing the screen , but it doesn't works

also fixing the screen size works , but each system's screen size is getting varied, so we can't follow that

anyone with solution for this ?
 

natalia

Moderator
Staff member
Hello @kaviraj
A very similar problem was processed in OpenCascade long time ago in the following issue: https://tracker.dev.opencascade.org/view.php?id=26603.

The solution to your problem is placed in implementation of 'paintEvent' and 'resizeEvent' of redefined widget.
For an example, take a look at the OpenCascade samples (View class) or tools (View_Widget class).
Or, with the implementation suggested in the lesson mentioned above: 'https://gitlab.com/ssv/lessons'

Regards, Natalia
 
Top