Archived discussion

Temporary Shape Visualization

VisualizationTue, 12/23/2025 - 14:372 replies

Browse this forum
QuestionAuthor

Hello everyone. I am new to this repo. I am trying to create temporary shape visual while drawing line for my mini CAD program. This is my code snippet that updates and redisplays line while mouse moving. But if i move mouse fastly, it crashes. How to solve this problem properly? Thanks.

bool showTempPreview(const gp_Pnt &startPnt, const gp_Pnt &endPnt)
{
    // Early null checks
    if (context_.IsNull() || view_.IsNull())
    {
        return false;
    }

    // Check if points are too close (would create invalid edge)
    double dist = startPnt.Distance(endPnt);
    if (dist < 0.001)
    {
        return false;
    }

    // Create the temporary edge
    BRepBuilderAPI_MakeEdge edgeBuilder(startPnt, endPnt);
    if (!edgeBuilder.IsDone())
    {
        return false;
    }
    TopoDS_Edge tempEdge = edgeBuilder.Edge();
    if (tempEdge.IsNull())
    {
        return false;
    }

    if (!tempPreviewActive_)
    {
        // First time: create new line object
        tempLine_ = new AIS_Shape(tempEdge);

        // Set dashed line style
        Handle(Prs3d_LineAspect) lineAspect = new Prs3d_LineAspect(
            Quantity_NOC_CYAN, Aspect_TOL_DASH, 2.0);
        tempLine_->Attributes()->SetLineAspect(lineAspect);
        tempLine_->SetDisplayMode(AIS_WireFrame);

        context_->Display(tempLine_, AIS_WireFrame, -1, false);
        tempPreviewActive_ = true;
    }
    else if (!tempLine_.IsNull())
    {
        // Update existing line
        tempLine_->SetShape(tempEdge);
        context_->Redisplay(tempLine_, true);
    }

    return true;
}

Discussion

2 archived replies

Posts are displayed in their archived order.

01Commenter-1

There is nothing obviously wrong withing the give code snippet.

Consider building application and OCCT with debug symbols and catching stack trace to figure our where problem actually happens.

02Author

Thanks for your reply. Problem was updating properties too much to make shape temporary look. It was crashing. I solved it with using OpenGl for temporary view.

Thanks for your reply.

Have a nice day.