clean code

This commit is contained in:
jfa 2009-11-04 11:12:32 +00:00
parent 2d7fa83c28
commit 1f857b0585
2 changed files with 112 additions and 134 deletions

View File

@ -25,19 +25,20 @@
#include "GroupGUI_GroupDlg.h" #include "GroupGUI_GroupDlg.h"
#include <DlgRef.h>
#include <GEOMBase.h>
#include <GeometryGUI.h>
#include <GEOM_Displayer.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
#include <LightApp_SelectionMgr.h> #include <LightApp_SelectionMgr.h>
#include <SUIT_ResourceMgr.h> #include <SUIT_ResourceMgr.h>
#include <SUIT_Desktop.h> #include <SUIT_Desktop.h>
#include <SUIT_OverrideCursor.h> #include <SUIT_OverrideCursor.h>
#include <SUIT_Session.h> #include <SUIT_Session.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
#include <DlgRef.h>
#include <GEOMBase.h>
#include <GeometryGUI.h>
#include <GEOMImpl_Types.hxx>
#include <GEOM_Displayer.h>
#include <QLabel> #include <QLabel>
#include <QListWidget> #include <QListWidget>
@ -48,6 +49,8 @@
#include <TColStd_MapOfInteger.hxx> #include <TColStd_MapOfInteger.hxx>
#include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx> #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
#include <GEOMImpl_Types.hxx>
enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2, SUBSHAPES_OF_INVISIBLE_SHAPE2 }; enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2, SUBSHAPES_OF_INVISIBLE_SHAPE2 };
GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent) GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
@ -275,6 +278,7 @@ bool GroupGUI_GroupDlg::ClickOnApply()
} }
else else
activateSelection(); activateSelection();
return true; return true;
} }
@ -292,24 +296,6 @@ void GroupGUI_GroupDlg::ActivateThisDialog()
activateSelection(); activateSelection();
} }
//=================================================================================
// function : LineEditReturnPressed()
// purpose :
//=================================================================================
void GroupGUI_GroupDlg::LineEditReturnPressed()
{
QLineEdit* send = (QLineEdit*)sender();
if (send == myMainName && !myEditCurrentArgument) {
myEditCurrentArgument = myMainName;
activateSelection();
}
else
GEOMBase_Skeleton::LineEditReturnPressed();
updateState();
}
//================================================================================= //=================================================================================
// function : SetEditCurrentArgument() // function : SetEditCurrentArgument()
// purpose : // purpose :
@ -322,13 +308,13 @@ void GroupGUI_GroupDlg::SetEditCurrentArgument()
myEditCurrentArgument = myMainName; myEditCurrentArgument = myMainName;
myShape2Name->setText(""); myShape2Name->setText("");
} }
else if (send == mySelAllBtn) else if (send == mySelAllBtn) {
myEditCurrentArgument = 0; myEditCurrentArgument = 0;
}
else if (send == mySelBtn2 || sender() == mySelectionWayGroup) { else if (send == mySelBtn2 || sender() == mySelectionWayGroup) {
setInPlaceObj(GEOM::GEOM_Object::_nil()); setInPlaceObj(GEOM::GEOM_Object::_nil());
myShape2Name->setText(""); myShape2Name->setText("");
if (subSelectionWay() != ALL_SUBSHAPES) if (subSelectionWay() != ALL_SUBSHAPES) {
{
myEditCurrentArgument = myShape2Name; myEditCurrentArgument = myShape2Name;
} }
else { else {
@ -338,9 +324,8 @@ void GroupGUI_GroupDlg::SetEditCurrentArgument()
activateSelection(); activateSelection();
if (send == mySelAllBtn) { if (send == mySelAllBtn)
selectAllSubShapes(); selectAllSubShapes();
}
else else
updateState(); updateState();
} }
@ -582,8 +567,9 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
//================================================================================= //=================================================================================
void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId) void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
{ {
if (!myIsShapeType && getConstructorId() != constructorId) if (getConstructorId() != constructorId)
setConstructorId(constructorId); setConstructorId(constructorId);
myIsShapeType = true; myIsShapeType = true;
myIdList->clear(); myIdList->clear();
activateSelection(); activateSelection();
@ -597,17 +583,16 @@ void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
//================================================================================= //=================================================================================
void GroupGUI_GroupDlg::selectAllSubShapes() void GroupGUI_GroupDlg::selectAllSubShapes()
{ {
if (CORBA::is_nil(myMainObj)) if (CORBA::is_nil(myMainObj) || !myIsShapeType)
return; return;
GEOM::ListOfLong_var aSubShapes; GEOM::ListOfLong_var aSubShapes;
if (subSelectionWay() == ALL_SUBSHAPES)
{
if (!myIsShapeType)
return;
myIdList->clear();
GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId()); GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false); aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
if (aSubShapes->length() > 0) {
if (subSelectionWay() == ALL_SUBSHAPES)
{
myIdList->clear();
if (!aShOp->IsDone()) if (!aShOp->IsDone())
return; return;
@ -643,6 +628,7 @@ void GroupGUI_GroupDlg::selectAllSubShapes()
myIdList->blockSignals(isBlocked); myIdList->blockSignals(isBlocked);
highlightSubShapes(); highlightSubShapes();
}
} }
//================================================================================= //=================================================================================
@ -651,24 +637,19 @@ void GroupGUI_GroupDlg::selectAllSubShapes()
//================================================================================= //=================================================================================
void GroupGUI_GroupDlg::add() void GroupGUI_GroupDlg::add()
{ {
TColStd_MapOfInteger aMap; SalomeApp_Application* app = myGeomGUI->getApp();
for (int i = 0, n = myIdList->count(); i < n; i++) if (!app) return;
aMap.Add(myIdList->item(i)->text().toInt()); LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
if (!aSelMgr) return;
TColStd_IndexedMapOfInteger aMapIndex; TColStd_IndexedMapOfInteger aMapIndex;
LightApp_SelectionMgr::MapEntryOfMapOfInteger aMapSubOwners;
aSelMgr->selectedSubOwners(aMapSubOwners);
if (aMapSubOwners.Size() == 1)
aMapIndex = LightApp_SelectionMgr::MapEntryOfMapOfInteger::Iterator(aMapSubOwners).Value();
SALOME_ListIO aSelIOs;
SalomeApp_Application* app = myGeomGUI->getApp();
if (app) {
LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
if (aSelMgr) {
LightApp_SelectionMgr::MapEntryOfMapOfInteger aMap;
aSelMgr->selectedSubOwners(aMap);
if (aMap.Size() == 1)
aMapIndex = LightApp_SelectionMgr::MapEntryOfMapOfInteger::Iterator(aMap).Value();
}
}
GEOM::ListOfGO anObjects; GEOM::ListOfGO anObjects;
// get selected sub-shapes of myInPlaceObj // get selected sub-shapes of myInPlaceObj
if (aMapIndex.Extent() > 0 && !myInPlaceObj->_is_nil()) if (aMapIndex.Extent() > 0 && !myInPlaceObj->_is_nil())
{ {
@ -684,8 +665,11 @@ void GroupGUI_GroupDlg::add()
// try to find out and process the object browser selection or InPlace sub-shapes // try to find out and process the object browser selection or InPlace sub-shapes
if (!aMapIndex.Extent()) if (!aMapIndex.Extent())
{ {
if (anObjects.length() == 0) if (anObjects.length() == 0) {
SALOME_ListIO aSelIOs;
aSelMgr->selectedObjects(aSelIOs);
GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects); GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
}
GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId()); GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId()); GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
@ -719,6 +703,10 @@ void GroupGUI_GroupDlg::add()
} }
} }
TColStd_MapOfInteger aMap;
for (int i = 0, n = myIdList->count(); i < n; i++)
aMap.Add(myIdList->item(i)->text().toInt());
if (aMapIndex.Extent() >= 1) { if (aMapIndex.Extent() >= 1) {
bool isBlocked = myIdList->signalsBlocked(); bool isBlocked = myIdList->signalsBlocked();
myIdList->blockSignals(true); myIdList->blockSignals(true);
@ -794,7 +782,12 @@ void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
case TopAbs_SOLID: anId = 3; break; case TopAbs_SOLID: anId = 3; break;
} }
setConstructorId(anId); setConstructorId(anId);
if (!myIsShapeType)
{
myIsShapeType = true; myIsShapeType = true;
// workaround to avoid set checked button 0
setConstructorId(anId);
}
} }
//================================================================================= //=================================================================================
@ -806,10 +799,10 @@ void GroupGUI_GroupDlg::activateSelection()
globalSelection(GEOM_ALLSHAPES); globalSelection(GEOM_ALLSHAPES);
// local selection // local selection
if (!myMainObj->_is_nil() && !myEditCurrentArgument if (!myMainObj->_is_nil() &&
&& myIsShapeType) // check if shape type is already choosen by user !myEditCurrentArgument &&
myIsShapeType) // check if shape type is already choosen by user
{ {
if (subSelectionWay() == ALL_SUBSHAPES) if (subSelectionWay() == ALL_SUBSHAPES)
localSelection(myMainObj, getShapeType()); localSelection(myMainObj, getShapeType());
else if (!myInPlaceObj->_is_nil()) else if (!myInPlaceObj->_is_nil())
@ -825,25 +818,24 @@ void GroupGUI_GroupDlg::activateSelection()
//================================================================================= //=================================================================================
void GroupGUI_GroupDlg::updateState() void GroupGUI_GroupDlg::updateState()
{ {
bool isAdd = false; SalomeApp_Application* app = myGeomGUI->getApp();
if (!app) return;
LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
if (!aSelMgr) return;
TColStd_IndexedMapOfInteger aMapIndex; TColStd_IndexedMapOfInteger aMapIndex;
LightApp_SelectionMgr::MapEntryOfMapOfInteger aMapSubOwners;
aSelMgr->selectedSubOwners(aMapSubOwners);
if (aMapSubOwners.Size() == 1)
aMapIndex = LightApp_SelectionMgr::MapEntryOfMapOfInteger::Iterator(aMapSubOwners).Value();
SALOME_ListIO aSelIOs; bool isAdd = false;
SalomeApp_Application* app = myGeomGUI->getApp();
if (app) {
LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
if (aSelMgr) {
LightApp_SelectionMgr::MapEntryOfMapOfInteger aMap;
aSelMgr->selectedSubOwners(aMap);
if (aMap.Size() == 1)
aMapIndex = LightApp_SelectionMgr::MapEntryOfMapOfInteger::Iterator(aMap).Value();
}
}
// try to find out and process the object browser selection // try to find out and process the object browser selection
if (!aMapIndex.Extent() && !CORBA::is_nil(myMainObj)) { if (!aMapIndex.Extent() && !CORBA::is_nil(myMainObj)) {
GEOM::ListOfGO anObjects; GEOM::ListOfGO anObjects;
SALOME_ListIO aSelIOs;
aSelMgr->selectedObjects(aSelIOs);
GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects); GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId()); GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
@ -897,12 +889,14 @@ void GroupGUI_GroupDlg::updateState()
} }
isAdd = aMapIndex.Extent() > 0; isAdd = aMapIndex.Extent() > 0;
myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd); myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
bool hasSel = myIdList->selectedItems().count() > 0; bool hasSel = myIdList->selectedItems().count() > 0;
myRemBtn->setEnabled(hasSel); myRemBtn->setEnabled(hasSel);
mySelectionWayGroupBox->setEnabled(!CORBA::is_nil(myMainObj)); mySelectionWayGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj)); mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
mySelBtn2->setEnabled( subSelectionWay() != ALL_SUBSHAPES); mySelBtn2->setEnabled( subSelectionWay() != ALL_SUBSHAPES);
myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES); myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
if (subSelectionWay() == ALL_SUBSHAPES) if (subSelectionWay() == ALL_SUBSHAPES)
@ -1077,18 +1071,3 @@ bool GroupGUI_GroupDlg::execute(ObjectList& objects)
return true; return true;
} }
//================================================================
// Function : getFather
// Purpose : Get father object for object to be added in study
// (called with addInStudy method)
//================================================================
GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
{
GEOM::GEOM_Object_var aFatherObj;
if (theObj->GetType() == GEOM_GROUP) {
GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
aFatherObj = anOp->GetMainShape(theObj);
}
return aFatherObj._retn();
}

View File

@ -22,7 +22,7 @@
// GEOM GEOMGUI : GUI for Geometry component // GEOM GEOMGUI : GUI for Geometry component
// File : GroupGUI_GroupDlg.h // File : GroupGUI_GroupDlg.h
// Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com) // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
//
#ifndef GROUPGUI_GROUPDLG_H #ifndef GROUPGUI_GROUPDLG_H
#define GROUPGUI_GROUPDLG_H #define GROUPGUI_GROUPDLG_H
@ -58,7 +58,6 @@ protected:
virtual GEOM::GEOM_IOperations_ptr createOperation(); virtual GEOM::GEOM_IOperations_ptr createOperation();
virtual bool isValid( QString& ); virtual bool isValid( QString& );
virtual bool execute( ObjectList& ); virtual bool execute( ObjectList& );
virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr );
void closeEvent( QCloseEvent* ); void closeEvent( QCloseEvent* );