Ejemplo n.º 1
0
bool ViewProviderMeshNode::handleEvent(const SoEvent * const ev,Gui::View3DInventorViewer &Viewer)
{
  if ( m_bEdit )
  {
    unsetEdit();
    std::vector<SbVec2f> clPoly = Viewer.getPickedPolygon();
    if ( clPoly.size() < 3 )
      return true;
    if ( clPoly.front() != clPoly.back() )
      clPoly.push_back(clPoly.front());

    // get the normal of the front clipping plane
    SbVec3f b,n;
    Viewer.getNearPlane(b, n);
    Base::Vector3f cPoint(b[0],b[1],b[2]), cNormal(n[0],n[1],n[2]);
    SoCamera* pCam = Viewer.getCamera();  
    SbViewVolume  vol = pCam->getViewVolume (); 

    // create a tool shape from these points
    std::vector<MeshCore::MeshGeomFacet> aFaces;
    bool ok = ViewProviderMesh::createToolMesh( clPoly, vol, cNormal, aFaces );

    // Get the attached mesh property
    Mesh::PropertyMeshKernel& meshProp = ((Mesh::Feature*)pcObject)->Mesh;

    // Get the facet indices inside the tool mesh
    std::vector<unsigned long> indices;
    MeshCore::MeshKernel cToolMesh;
    cToolMesh = aFaces;
    MeshCore::MeshFacetGrid cGrid(meshProp.getValue().getKernel());
    MeshCore::MeshAlgorithm cAlg(meshProp.getValue().getKernel());
    cAlg.GetFacetsFromToolMesh(cToolMesh, cNormal, cGrid, indices);
    meshProp.deleteFacetIndices( indices );

      // update open edge display if needed
//      if ( pcOpenEdge ) 
//      {
//        showOpenEdges(false);
//        showOpenEdges(true);
//      }

    Viewer.render();
    if ( !ok ) // note: the mouse grabbing needs to be released
      //QMessageBox::warning(Viewer.getWidget(),"Invalid polygon","The picked polygon seems to have self-overlappings.\n\nThis could lead to strange rersults.");
      Base::Console().Message("The picked polygon seems to have self-overlappings. This could lead to strange results.");
  }

  return false;
}