Ejemplo n.º 1
0
void DatabaseCanvas::OnShowComments(wxCommandEvent &WXUNUSED(event))
{
    ShapeList list;
    m_showComments = !m_showComments;
    m_pManager.GetShapes( CLASSINFO( CommentFieldShape ), list );
    for( ShapeList::iterator it = list.begin(); it != list.end(); ++it )
    {
        CommentFieldShape *shape = wxDynamicCast( (*it), CommentFieldShape );
        if( m_showComments )
        {
            shape->SetText( const_cast<Field *>( shape->GetFieldForComment() )->GetComment() );
        }
        else
        {
            shape->SetText( wxEmptyString );
        }
    }
    Refresh();
    list.clear();
    m_pManager.GetShapes( CLASSINFO( CommentTableShape ), list );
    for( ShapeList::iterator it = list.begin(); it != list.end(); ++it )
    {
        CommentTableShape *shape = wxDynamicCast( (*it), CommentTableShape );
        if( m_showComments )
        {
            shape->SetText( const_cast<DatabaseTable *>( shape->GetDatabaseTable() )->GetComment() );
        }
        else
        {
            shape->SetText( wxEmptyString );
        }
    }
    Refresh();
}
void udCPPClassElementProcessor::ProcessElement(wxSFShapeBase *element)
{	
    // check existing parent generator
    wxASSERT(m_pParentGenerator);
    if(!m_pParentGenerator) return;
	
	wxASSERT(element);
	if(!element) return;
	
	udClassElementItem *pClass = (udClassElementItem*) udPROJECT::GetDiagramElement( element, udfOMIT_LINKS );
	if( !pClass || !pClass->IsGenerated() ) return;
	
	udClassAlgorithm *pAlg = (udClassAlgorithm*) m_pParentGenerator->GetActiveAlgorithm();
	
	// check whether the class is already processed
    if( pAlg->GetProcessedElements().IndexOf(element) != wxNOT_FOUND ) return;
	
	// process child classes recursivelly first
	ShapeList lstBases;
	umlClassDiagram::GetOuterClasses( (umlClassItem*)element, lstBases );

	for( ShapeList::iterator it = lstBases.begin(); it != lstBases.end(); ++it )
	{
		ProcessElement( *it );
	}

	switch( pAlg->GetGenMode() )
	{
		case udGenerator::genDECLARATION:
			ProcessClassDeclaration( element );
			break;
			
		case udGenerator::genDEFINITION:
			ProcessClassDefinition( element );
			break;
			
		default:
			break;
	}
	
	// process template bindings
	ShapeList lstConnections;
	element->GetShapeManager()->GetAssignedConnections( element, CLASSINFO(umlTemplateBindItem), wxSFShapeBase::lineSTARTING, lstConnections );
	
	for( ShapeList::iterator it = lstConnections.begin(); it != lstConnections.end(); ++it )
	{
		udElementProcessor *pProcessor = pAlg->GetElementProcessor((*it)->GetClassInfo()->GetClassName());
		if(pProcessor)
		{
			pProcessor->ProcessElement(*it);
		}
	}

    // set the state as processes
	pAlg->GetProcessedElements().Append(element);
}
Ejemplo n.º 3
0
void wxSFLayoutMesh::DoLayout(ShapeList& shapes)
{
	int i = 0, cols = floor( sqrt( (float)shapes.GetCount() ) );
	
	double roffset, coffset, maxh = -m_HSpace;
	roffset = coffset = 0;

	wxRealPoint nStart = GetTopLeft( shapes );

	for( ShapeList::iterator it = shapes.begin(); it != shapes.end(); ++ it )
	{
		wxSFShapeBase *pShape = *it;
		
		if( i++ % cols == 0 )
		{
			coffset = 0;
			roffset += maxh + m_HSpace;
			maxh = 0;
		}
		
		pShape->MoveTo( nStart.x + coffset, nStart.y + roffset );
		
		wxRect rctBB = pShape->GetBoundingBox();
		coffset += rctBB.GetWidth() + m_VSpace;
		
		if( rctBB.GetHeight() > maxh ) maxh = rctBB.GetHeight();
	}
}
Ejemplo n.º 4
0
void TableSettings::OnInit(wxInitDialogEvent& event)
{
    m_textName->SetValue( m_pTable->GetName() );

    // fill database data types
    wxArrayString* pDbTypes = m_pDbAdapter->GetDbTypes();
    if( pDbTypes ) {
        wxArrayString choices;
        for (unsigned int i = 0; i < pDbTypes->GetCount(); ++i) {
            choices.Add( pDbTypes->Item(i) );
        }

        m_dvColumns->DeleteColumn( m_dvColumns->GetColumn(1) );
        m_dvColumns->InsertColumn( 1, new wxDataViewColumn( _("Type"), new wxDataViewChoiceRenderer( choices, wxDATAVIEW_CELL_EDITABLE, wxDVR_DEFAULT_ALIGNMENT), 1, -2, wxALIGN_LEFT));

        pDbTypes->Clear();
        delete pDbTypes;
    }

    // fill referenced tables
    ShapeList tables;
    m_choiceRefTable->Append( wxT("") );
    m_pDiagramManager->GetShapes( CLASSINFO(ErdTable), tables );
    for( ShapeList::iterator it = tables.begin(); it != tables.end(); ++it ) {
        Table *t = (Table*) (*it)->GetUserData();
        if( t && t->GetName() != m_pTable->GetName() ) m_choiceRefTable->Append( t->GetName() );
    }

    UpdateView();

    event.Skip();
}
Ejemplo n.º 5
0
void wxSFLayoutHorizontalTree::ProcessNode(wxSFShapeBase* node, double x)
{
	wxASSERT( node );
	
	if( node )
	{
		node->MoveTo( x, m_nMinY );
		
		wxRect rctBB = node->GetBoundingBox();
		if( rctBB.GetHeight() > m_nCurrMaxHeight ) m_nCurrMaxHeight = rctBB.GetHeight();
		
		ShapeList lstNeighbours;
		node->GetNeighbours( lstNeighbours, CLASSINFO(wxSFShapeBase), wxSFShapeBase::lineSTARTING );

		if( lstNeighbours.IsEmpty() )
		{
			m_nMinY += m_nCurrMaxHeight + m_VSpace;
		}
		else
		{
			for( ShapeList::iterator it = lstNeighbours.begin(); it != lstNeighbours.end(); ++it )
			{
				if( ! (*it)->GetParentShape() )	ProcessNode( *it, x + rctBB.GetWidth() + m_HSpace );
			}
		}
	}
}
Ejemplo n.º 6
0
bool DatabaseCanvas::IsTableDisplayed(const std::wstring &name)
{
    ShapeList listShapes;
    m_pManager.GetShapes( CLASSINFO( MyErdTable ), listShapes );
    bool found = false;
    for( ShapeList::iterator it = listShapes.begin(); it != listShapes.end() && !found; ++it )
    {
        if( dynamic_cast<MyErdTable *>( (*it) )->GetTableName() == name )
            found = true;
    }
    return found;
}
Ejemplo n.º 7
0
Table* TableSettings::GetRefTable(const wxString& name)
{
    ShapeList tables;
    m_pDiagramManager->GetShapes( CLASSINFO(ErdTable), tables );

    for( ShapeList::iterator it = tables.begin(); it != tables.end(); ++it ) {
        Table *t = (Table*) (*it)->GetUserData();
        if( t->GetName() == name ) return t;
    }

    return NULL;
}
Ejemplo n.º 8
0
wxSize wxSFLayoutAlgorithm::GetShapesExtent(const ShapeList& shapes)
{
	int nTotalWidth = 0, nTotalHeight = 0;
	
	for( ShapeList::const_iterator it = shapes.begin(); it != shapes.end(); ++ it )
	{
		wxRect rctBB = (*it)->GetBoundingBox();
		
		nTotalWidth += rctBB.GetWidth();
		nTotalHeight += rctBB.GetHeight();
	}
	
	return wxSize( nTotalWidth, nTotalHeight );
}
Ejemplo n.º 9
0
wxRealPoint wxSFLayoutAlgorithm::GetShapesCenter(const ShapeList& shapes)
{
	wxRealPoint nCenter;
	
	for( ShapeList::const_iterator it = shapes.begin(); it != shapes.end(); ++ it )
	{
		nCenter = nCenter + (*it)->GetAbsolutePosition();
	}
	
	nCenter.x /= shapes.GetCount();
	nCenter.y /= shapes.GetCount();
	
	return nCenter;
}
Ejemplo n.º 10
0
wxRealPoint wxSFLayoutAlgorithm::GetTopLeft(const ShapeList& shapes)
{
	double startx = INT_MAX, starty = INT_MAX;
	
	for( ShapeList::const_iterator it = shapes.begin(); it != shapes.end(); ++ it )
	{
		wxSFShapeBase *pShape = *it;
		
		wxRealPoint nPos = pShape->GetAbsolutePosition();
		if( nPos.x < startx ) startx = nPos.x;
		if( nPos.y < starty ) starty = nPos.y;
	}
	
	return wxRealPoint( startx, starty );
}
Ejemplo n.º 11
0
wxRect wxSFLayoutAlgorithm::GetBoundingBox(const ShapeList& shapes)
{
	wxRect rctBB;
	
	for( ShapeList::const_iterator it = shapes.begin(); it != shapes.end(); ++ it )
	{
		wxSFShapeBase *pShape = *it;
		
		if( it == shapes.begin() ) rctBB = pShape->GetBoundingBox();
		else
			rctBB.Union( pShape->GetBoundingBox() );
	}
	
	return rctBB;
}
Ejemplo n.º 12
0
	void Entity::init(const ShapeList & list, const MassProperties mass, const Transform t){
		std::vector< ::std::pair<size_t, Transform> > shapes;
		size_t compound;
		//Create the shapes
		for_each(list.begin(), list.end(), [&](const ShapeList::value_type & shape){
			switch(shape.first.type){
				case E_CAPSULE:
				case E_SPHERE:
				case E_BOX:
				case E_PLANE:
				{
					size_t s = createShape(
						shape.first.type,
						Math::Vec4ToVec3(shape.first.data),
						Math::VecLast(shape.first.data)
					);
					Transform t = shape.second;
					::std::pair<size_t, Transform> p(s,t);
					shapes.push_back(p);
				}
				break;
				case E_MESH:
				{
					size_t s = createShape(
						shape.first.type,
						shape.first.rawMesh
					);
					Transform t = shape.second;
					::std::pair<size_t, Transform> p(s,t);
					shapes.push_back(p);
				}
				break;
				default:
				{
					throw "Not valid shape type!";
				}
			}
		});
		//Got a list of shapes, make the compound shape
		compound = _world->compoundShapes(shapes);
		//Put it back on with the compound object first
		_shape_index.push_back(compound);
		for_each(shapes.begin(),shapes.end(),[&](decltype(shapes)::value_type s){
			_shape_index.push_back(s.first);
		});
		//create body
		makeBody(t, mass);
	}
Ejemplo n.º 13
0
void DatabaseCanvas::AddQuickQueryFields(const wxString &tbl, std::vector<Field *> &quickSelectFields, bool quickSelect)
{
    ShapeList shapes;
    m_pManager.GetShapes( CLASSINFO( FieldShape ), shapes );
    for( ShapeList::iterator it = shapes.begin (); it != shapes.end (); ++it )
    {
        auto fld = wxDynamicCast( (*it), FieldShape );
        auto fieldName = wxDynamicCast( (*it), FieldShape )->GetField()->GetFieldName();
        auto found = false;
        for( std::vector<Field *>::iterator it2 = quickSelectFields.begin(); it2 < quickSelectFields.end() && !false; ++it2 )
        {
            if( (*it2)->GetFieldName() == fieldName )
            {
                found = true;
                (*it)->Select( true );
                dynamic_cast<DrawingView *>( m_view )->AddFieldToQuery( *fld, fld->IsSelected(), tbl.ToStdWstring(), quickSelect );
            }
        }
    }
    Refresh();
}
Ejemplo n.º 14
0
void wxSFLayoutCircle::DoLayout(ShapeList& shapes)
{
	wxSize sizeShapes = GetShapesExtent( shapes );
	wxRealPoint nCenter = GetShapesCenter( shapes );
	
	double x, y;
	double step = 360.0 / shapes.GetCount();
	double degree = 0;
	double rx = ( sizeShapes.x / 2 ) * m_DistanceRatio;
	double ry = ( sizeShapes.y / 2 ) * m_DistanceRatio;
	
	for( ShapeList::iterator it = shapes.begin(); it != shapes.end(); ++ it )
	{
		wxSFShapeBase *pShape = *it;
		
		x = nCenter.x + cos( degree * wxSF::PI / 180 ) * rx;
		y = nCenter.y + sin( degree * wxSF::PI / 180 ) * ry;
		degree += step;
		
		pShape->MoveTo( x, y );
	}
}
Ejemplo n.º 15
0
void wxSFLayoutHorizontalTree::DoLayout(ShapeList& shapes)
{
	ShapeList lstConnections;
	ShapeList lstRoots;
	
	wxRealPoint nStart = GetTopLeft( shapes );
	m_nMinY = nStart.y;
	
	// find root items
	for( ShapeList::iterator it = shapes.begin(); it != shapes.end(); ++ it )
	{
		wxSFShapeBase *pShape = *it;
		
		lstConnections.Clear();
		pShape->GetAssignedConnections( CLASSINFO(wxSFLineShape), wxSFShapeBase::lineENDING, lstConnections );
		
		if( lstConnections.IsEmpty() )
		{
			m_nCurrMaxHeight = 0;
			ProcessNode( pShape, nStart.x );
		}
	}
}
Ejemplo n.º 16
0
void udCPPClassElementProcessor::ProcessClassDeclaration(wxSFShapeBase* element)
{
	udLanguage *pLang = m_pParentGenerator->GetActiveLanguage();
	udClassAlgorithm *pAlg = (udClassAlgorithm*) m_pParentGenerator->GetActiveAlgorithm();
	
	// get base classes if exists
	ShapeList lstBases;
	umlClassDiagram::GetBaseClasses( (umlClassItem*)element, lstBases );
	
	int nTemplateIndex = 0;
	
	wxString sBases;
	for( ShapeList::iterator it = lstBases.begin(); it != lstBases.end(); ++it )
	{
		if( it != lstBases.begin() ) sBases << wxT(", ");
		
		sBases << pLang->MakeValidIdentifier( udPROJECT::GetDiagramElement(*it)->GetName() );
		
		// add template parameter if exists
		umlClassTemplateItem *pTemplate = wxDynamicCast( *it, umlClassTemplateItem );
		if( pTemplate )
		{
			// find corespondent template binding connection
			ShapeList lstConnections;
			element->GetShapeManager()->GetAssignedConnections( element, CLASSINFO(umlTemplateBindItem), wxSFShapeBase::lineSTARTING, lstConnections );
			if( !lstConnections.IsEmpty() )
			{
				// append bind type to the base name
				udTemplateBindElementItem *pBindElement = wxDynamicCast( udPROJECT::GetDiagramElement( lstConnections.Item(nTemplateIndex)->GetData() ), udTemplateBindElementItem );
				if( pBindElement )
				{
					sBases << wxT("<") << pBindElement->GetBindType() << wxT(">");
				}
			}
			nTemplateIndex++;
		}
	}
	
	udClassElementItem *pClass = (udClassElementItem*) udPROJECT::GetDiagramElement(element);
	
	//generate comment if requested
	pLang->WriteCodeBlocks( udGenerator::GetComment( pClass, pLang) );
	
	// write template definition if needed
	udClassTemplateElementItem *pClassTempl = wxDynamicCast( pClass, udClassTemplateElementItem );
	if( pClassTempl )
	{
		pLang->WriteCodeBlocks( wxT("template <typename ") + pClassTempl->GetTemplateName() + wxT(">") );
	}
	
	// generate class declaration
	pLang->ClassDeclCmd( pLang->MakeValidIdentifier( pClass->GetName() ), sBases );
	
	pLang->BeginCmd();
	
	// declare class members
	int nAccessType = 0;
	wxClassInfo *pPrevType;
	
	SerializableList lstMembers;
	ShapeList lstAssocs;
	
	while( pLang->GetAccessTypeString( (udLanguage::ACCESSTYPE) nAccessType ) != wxEmptyString )
	{
		pLang->WriteCodeBlocks( pLang->GetAccessTypeString( (udLanguage::ACCESSTYPE) nAccessType ) + wxT(":") );
		pLang->IncIndentation();
		
		lstMembers.Clear();
		lstAssocs.Clear();
		pPrevType = NULL;
		
		// process associations
		umlClassDiagram::GetClassAssociations( (umlClassItem*) element, CLASSINFO(wxSFLineShape), wxSFLineShape::lineSTARTING, (udLanguage::ACCESSTYPE) nAccessType, lstAssocs );
		for( ShapeList::iterator it = lstAssocs.begin(); it != lstAssocs.end(); ++it )
		{
			udElementProcessor *pProcessor = pAlg->GetElementProcessor( (*it)->GetClassInfo()->GetClassName() );
			if( pProcessor ) pProcessor->ProcessElement( *it );
		}
		
		// process class members
		umlClassDiagram::GetClassMembers( (umlClassItem*) element, CLASSINFO(udMemberDataLinkItem), (udLanguage::ACCESSTYPE) nAccessType, lstMembers);
		umlClassDiagram::GetClassMembers( (umlClassItem*) element, CLASSINFO(udMemberFunctionLinkItem), (udLanguage::ACCESSTYPE) nAccessType, lstMembers);
		for( SerializableList::iterator it = lstMembers.begin(); it != lstMembers.end(); ++it )
		{
			if( pPrevType && ((*it)->GetClassInfo() != pPrevType) ) pLang->NewLine();
			
			// generate comment
			pLang->WriteCodeBlocks( udGenerator::GetComment( ((udCodeLinkItem*)*it)->GetOriginal(), pLang ) );
			// generate function decl
			pLang->WriteCodeBlocks( ((udCodeLinkItem*)*it)->ToString( udCodeItem::cfDECLARATION, pLang ) );
			
			pPrevType = (*it)->GetClassInfo();
		}
		
		nAccessType++;
		
		pLang->DecIndentation();
		pLang->NewLine();
	}
	
	// insert class ending with delimiter
	pLang->PushCode();
	pLang->EndCmd();
	wxString sEnding = pLang->GetCodeBuffer().Trim() + pLang->Delimiter();
	pLang->PopCode();
	
	pLang->WriteCodeBlocks( sEnding );
	
	pLang->NewLine();	
}
Ejemplo n.º 17
0
void DatabaseCanvas::OnRightDown(wxMouseEvent &event)
{
    FieldShape *erdField = NULL;
    MyErdTable *erdTable = NULL;
    ConstraintSign *erdSign = NULL;
    wxPoint pt = event.GetPosition();
    ShapeList selection;
    this->GetSelectedShapes( selection );
    for( ShapeList::iterator it = selection.begin(); it != selection.end(); ++it )
    {
        MyErdTable *table = wxDynamicCast( (*it), MyErdTable );
        if( table )
            m_realSelectedShape = table;
    }
    wxMenu mnu;
    int allSelected = 0;
    mnu.Bind( wxEVT_COMMAND_MENU_SELECTED, &DatabaseCanvas::OnDropTable, this, wxID_DROPOBJECT );
    mnu.Bind( wxEVT_COMMAND_MENU_SELECTED, &DatabaseCanvas::OnDropTable, this, wxID_TABLECLOSE );
    m_selectedShape = GetShapeUnderCursor();
    ViewType type = dynamic_cast<DrawingView *>( m_view )->GetViewType();
    if( m_selectedShape )
    {
        ShapeList list;
        GetShapesAtPosition( pt, list );
        if( type == DatabaseView )
            if( m_selectedShape->IsKindOf( CLASSINFO( MyErdTable ) ) )
                DeselectAll();
        wxRect tableRect;
        bool fieldSelected = false;
        bool signSelected = false;
        for( ShapeList::iterator it = list.begin(); it != list.end(); ++it )
        {
            MyErdTable *table = wxDynamicCast( (*it), MyErdTable );
            if( table )
            {
                if( type == DatabaseView )
                    table->Select( true );
                tableRect = table->GetBoundingBox();
                erdTable = table;
            }
            else
            {
                FieldShape *field = wxDynamicCast( (*it), FieldShape );
                if( field )
                {
                    if( type == DatabaseView )
                        field->Select( true );
                    field->SetParentRect( tableRect );
                    fieldSelected = true;
                    erdField = field;
                }
                else
                {
                    ConstraintSign *sign = wxDynamicCast( (*it), ConstraintSign );
                    if( sign )
                    {
                        if( type == DatabaseView )
                            sign->Select( true );
                        signSelected = true;
                        erdSign = sign;
                    }
                }
            }
        }
        if( type == DatabaseView && list.empty() )
        {
            MyErdTable *table = wxDynamicCast( m_selectedShape, MyErdTable );
            if( table )
            {
                table->Select( true );
            }
            else
            {
                table = wxDynamicCast( m_selectedShape->GetParentShape()->GetParentShape(), MyErdTable );
                table->Select( true );
            }
        }
        if( type == QueryView )
        {
            size_t selectedCount = 0;
            SerializableList tableFields;
			if( erdTable )
			{
                erdTable->GetChildrenRecursively( CLASSINFO( FieldShape ), tableFields );
                SerializableList::compatibility_iterator node = tableFields.GetFirst();
                while( node )
                {
                    FieldShape *shape = dynamic_cast<FieldShape *>( node->GetData() );
                    if( shape->IsSelected() )
                        selectedCount++;
                    node = node->GetNext();
                }
                if( selectedCount == const_cast<DatabaseTable &>( erdTable->GetTable() ).GetFields().size() )
                    allSelected = 1;
                else
                    allSelected = -1;
			}
        }
        Refresh();
        if( type == DatabaseView )
        {
            if( !fieldSelected && !signSelected )
            {
                mnu.Append( wxID_TABLECLOSE, _( "Close" ), _( "Close Table" ), false );
                mnu.AppendSeparator();
                mnu.Append( wxID_TABLEALTERTABLE, _( "Alter Table" ), _( "Alter Table" ), false );
                mnu.Append( wxID_PROPERTIES, _( "Properties..." ), _( "Table Properties" ), false );
                mnu.AppendSeparator();
                wxMenu *newObjectMenu = new wxMenu();
                newObjectMenu->Append( wxID_OBJECTNEWINDEX, _( "Index..." ), _( "New Index" ) );
                newObjectMenu->Append( wxID_OBJECTNEWFF, _( "Foreign Key..." ), _( "New Foreign Key" ) );
                mnu.AppendSubMenu( newObjectMenu, _( "New" ), _( "New" ) );
                mnu.AppendSeparator();
                mnu.Append( wxID_DROPOBJECT, _( "Drop Table" ), _( "Drop Table" ), false );
                mnu.AppendSeparator();
                mnu.Append( wxID_TABLEEDITDATA, _( "Edit Data" ), _( "Edit Data" ), false );
                mnu.AppendSeparator();
                mnu.Append( wxID_TABLEDATATRANSFER, _( "Data Transfer" ), _( "Data Transfer" ), false );
                mnu.AppendSeparator();
                mnu.Append( wxID_TABLEPRINTDEFINITION, _( "Print Definition" ), _( "Print Definition" ), false );
            }
            else if( fieldSelected )
            {
                mnu.Append( wxID_FIELDDEFINITION, _( "Definition" ), _( "Edit definition of selected object" ), false );
                mnu.Append( wxID_FIELDPROPERTIES, _( "Properties..." ), _( "Show properties of selected object" ), false );
            }
            else
            {
                mnu.Append( wxID_FKDEFINITION, _( "Definition..." ), _( "Edit definition of selected object" ) );
                mnu.Append( wxID_FKOPENREFTABLE, _( "Open Referenced Table" ), _( "Open Referenced Table" ) );
                mnu.Append( wxID_DROPOBJECT, _( "Drop Foreign Key..." ), _( "Drop Foreign Key for the table" ) );
            }
        }
        else
        {
            if( erdTable )
            {
                mnu.Append( wxID_SELECTALLFIELDS, _( "Select All" ), _( "Select all columns for display" ) );
                mnu.Append( wxID_DESELECTALLFIELDS, _("Deselect All" ), _( "Deselect all columns for display" ) );
                mnu.Append( wxID_TABLECLOSE, _( "Close" ), _( "Close Table" ), false );
                if( !allSelected )
                    mnu.FindItem( wxID_DESELECTALLFIELDS )->Enable( false );
                else if( allSelected == 1 )
                    mnu.FindItem( wxID_SELECTALLFIELDS )->Enable( false );
            }
        }
    }
    else
    {
        if( type == DatabaseView )
        {
            mnu.Append( wxID_SELECTTABLE, _( "Select Table..." ), _( "Select Table" ), false );
            mnu.Append( wxID_VIEWARRANGETABLES, _( "Arramge Tables..." ), _( "Arrange Tables" ), false );
            mnu.AppendCheckItem( wxID_VIEWSHOWCOMMENTS, _( "Show Comments" ), _( "Show Comments" ) );
            mnu.AppendCheckItem( wxID_VIEWSHOWINDEXKEYS, _( "Show Index Keys" ), _( "Show Index Keys" ) );
            mnu.AppendCheckItem( wxID_VIEWSHOWINTEGRITY, _( "Show Referential Integrity" ), _( "Show Referential Integrity" ) );
            if( m_showComments )
                mnu.Check( wxID_VIEWSHOWCOMMENTS, true );
            if( m_showIndexKeys )
                mnu.Check( wxID_VIEWSHOWINDEXKEYS, true );
            if( m_showIntegrity )
                mnu.Check( wxID_VIEWSHOWINTEGRITY, true );
        }
        else
        {
            mnu.Append( wxID_SELECTTABLE, _( "Select Table..." ), _( "Select addtional tables for the query" )  );
            mnu.Append( wxID_ARRANGETABLES, _( "Arrange Tables" ), _( "Arrange Tables" ) );
            wxMenu *showMenu = new wxMenu();
            showMenu->AppendCheckItem( wxID_SHOWDATATYPES, _( "Datatypes" ), _( "Datatypes" ) );
            showMenu->AppendCheckItem( wxID_SHOWLABELS, _( "Labels" ), _( "Labels" ) );
            showMenu->AppendCheckItem( wxID_VIEWSHOWCOMMENTS, _( "Comments" ), _( "Comments" ) );
            showMenu->AppendCheckItem( wxID_SHOWSQLTOOLBOX, _( "SQL Toolbox" ), _( "SQL Toolbox" ) );
            mnu.AppendSubMenu( showMenu, _( "Show" ) );
            if( m_showDataTypes )
                showMenu->Check( wxID_SHOWDATATYPES, true );
            if( m_showLabels )
                showMenu->Check( wxID_SHOWLABELS, true );
            if( m_showComments )
                showMenu->Check( wxID_VIEWSHOWCOMMENTS, true );
            if( m_showToolBox )
                showMenu->Check( wxID_SHOWSQLTOOLBOX, true );
        }
    }
    int rc = GetPopupMenuSelectionFromUser( mnu, pt );
    if( rc == wxID_NONE && erdField )
    {
//        if( field )
        {
            erdField->Select( false );
            erdTable->GetFieldGrid()->Refresh();
            erdTable->Refresh();
        }
    }
    else
    {
        if( erdField )
        {
            erdField->Select( false );
            erdTable->GetFieldGrid()->Refresh();
            erdTable->Refresh();
        }
        wxCommandEvent evt( wxEVT_MENU, rc );
        if( erdField )
            evt.SetEventObject( erdField );
        else
            evt.SetEventObject( erdTable );
        if( rc == wxID_SHOWSQLTOOLBOX || rc == wxID_VIEWSHOWCOMMENTS )
            GetEventHandler()->ProcessEvent( evt );
        else
            m_view->ProcessEvent( evt );
    }
}
Ejemplo n.º 18
0
void DatabaseCanvas::OnDropTable(wxCommandEvent &event)
{
    ShapeList list;
    bool isTable;
    int answer;
    MyErdTable *erdTable = NULL;
    DatabaseTable *table = NULL;
    wxString name;
    ConstraintSign *sign = NULL;
    Constraint *constraint = NULL;
    DrawingDocument *doc = (DrawingDocument *) m_view->GetDocument();
    Database *db = doc->GetDatabase();
    std::vector<std::wstring> errors, localColumns, refColumn;
    std::vector<FKField *> newFK;
    std::wstring command;
    int match = 0;
    GetSelectedShapes( list );
    if( list.size() == 1 )
        isTable = true;
    else
        isTable = false;
    for( ShapeList::iterator it = list.begin(); it != list.end(); it++ )
    {
        MyErdTable *tbl = wxDynamicCast( (*it), MyErdTable );
        if( tbl )
            erdTable = tbl;
        ConstraintSign *s = wxDynamicCast( (*it), ConstraintSign );
        if( s )
            sign = s;
    }
    if( isTable )
    {
        table = &( const_cast<DatabaseTable &>( erdTable->GetTable() ) );
        name = const_cast<DatabaseTable &>( erdTable->GetTable() ).GetTableName();
    }
    else
    {
        constraint = sign->GetConstraint();
        constraint->GetLocalColumns( localColumns );
        constraint->GetRefColumns( refColumn );
        match = constraint->GetPGMatch();
    }
    int eventId = event.GetId();
    if( eventId == wxID_DROPOBJECT )
    {
        wxString message = _( "You are about to delete " );
        if( isTable )
            message += _( "table " ) + name + _( ". Are you sure?" );
        else
        {
            message += _( "foreign key " );
            wxString fkName = constraint->GetName();
            if( !fkName.empty() )
                message += fkName;
            else
                message += _( " on " ) + const_cast<DatabaseTable *>( constraint->GetFKTable() )->GetTableName() + _( " references " ) + constraint->GetRefTable() + _( ". Are you sure?" );
        }
        answer = wxMessageBox( message, _( "Database" ), wxYES_NO | wxNO_DEFAULT );
    }
    else
        answer = wxYES;
    if( answer == wxYES )
    {
        if( isTable && ( ( eventId == wxID_DROPOBJECT && !db->DeleteTable( name.ToStdWstring(), errors ) ) || eventId != wxID_DROPOBJECT ) )
        {
            if( m_realSelectedShape == m_selectedShape )
            {
                m_realSelectedShape = NULL;
                ShapeList listShapes;
                m_pManager.GetShapes( CLASSINFO( MyErdTable ), listShapes );
                int size = listShapes.size();
                if( listShapes.size() == 1 )
                    m_realSelectedShape = NULL;
                else
                {
                    MyErdTable *tableToRemove = (MyErdTable *) ( listShapes.Item( size - 1 )->GetData() );
                    if( tableToRemove == erdTable )
                        m_realSelectedShape = (MyErdTable *) ( listShapes.Item( size - 2 )->GetData() );
                    else
                    {
                        bool found = false;
                        int i;
                        for( i = 0; i < size - 1 || !found; i++ )
                            if( listShapes.Item( i )->GetData() == erdTable )
                                found = true;
                        m_realSelectedShape = listShapes.Item( i + 1 )->GetData();
                    }
                }
            }
            m_pManager.RemoveShape( erdTable );
/*            for( ShapeList::iterator it = listShapes.begin(); it != listShapes.end() || !nextShapeFound; ++it )
            {
                CommentFieldShape *shape = wxDynamicCast( (*it), CommentFieldShape );
                if( m_showComments )
                {
                    shape->SetText( const_cast<Field *>( shape->GetFieldForComment() )->GetComment() );
                }
                else
                {
                    shape->SetText( wxEmptyString );
                }
            }*/
            std::map<std::wstring, std::vector<DatabaseTable *> > tables = db->GetTableVector().m_tables;
            std::vector<DatabaseTable *> tableVec = tables.at( db->GetTableVector().m_dbName );
            std::vector<std::wstring> &names = doc->GetTableNameVector();
            if( event.GetId() == wxID_DROPOBJECT )
            {
                tableVec.erase( std::remove( tableVec.begin(), tableVec.end(), table ), tableVec.end() );
            }
            else
                names.erase( std::remove( names.begin(), names.end(), table->GetTableName() ), names.end() );
/*            if( m_realSelectedShape == m_selectedShape )
            {
                
            }
            else
            {*/
                if( m_realSelectedShape )
                    m_realSelectedShape->Select( true );
//            }
        }
        else if( !isTable && !db->ApplyForeignKey( command, constraint->GetName().ToStdWstring(), *( const_cast<DatabaseTable *>( constraint->GetFKTable() ) ), localColumns, constraint->GetRefTable().ToStdWstring(), refColumn, constraint->GetOnDelete(), constraint->GetOnUpdate(), false, newFK, false, match, errors ) )
        {
            sign->DeleteConstraint();
            m_pManager.RemoveShape( sign->GetParentShape() );
            Refresh();
        }
        else
        {
            for( std::vector<std::wstring>::iterator it = errors.begin(); it < errors.end(); it++ )
            {
                wxMessageBox( (*it) );
            }
        }
    }
    Refresh();
}
Ejemplo n.º 19
0
void DatabaseCanvas::OnLeftDoubleClick(wxMouseEvent& event)
{
    int result;
    std::vector<std::wstring> errors;
    m_selectedShape = GetShapeUnderCursor();
    std::vector<FKField *> newFK;
    ViewType type = dynamic_cast<DrawingView *>( m_view )->GetViewType();
    ConstraintSign *sign = NULL;
    if( m_selectedShape )
    {
        ShapeList list;
        GetShapesAtPosition( event.GetPosition(), list );
        bool found = false;
        for( ShapeList::iterator it = list.begin(); it != list.end() && !found; it++ )
        {
            sign = wxDynamicCast( (*it), ConstraintSign );
            if( sign )
                found = true;
        }
        if( type == DatabaseView && !sign )
            DeselectAll();
        if( sign && type == DatabaseView )
        {
            bool logOnly;
            Constraint *constraint = sign->GetConstraint();
            std::wstring kName = constraint->GetName().ToStdWstring(), refTable, fkTable;
            std::vector<std::wstring> foreignKeyFields, refKeyFields;
            constraint->GetLocalColumns( foreignKeyFields );
            constraint->GetRefColumns( refKeyFields );
            DatabaseTable *table = const_cast<DatabaseTable *>( constraint->GetFKTable() );
            wxString refTableName = constraint->GetRefTable();
            int match = constraint->GetPGMatch();
            bool found1 = false, found2 = false;
            for( std::vector<MyErdTable *>::iterator it = m_displayedTables.begin(); it < m_displayedTables.end() && !found1 && !found2; it++ )
            {
                if( const_cast<DatabaseTable &>( (*it)->GetTable() ).GetTableName() == const_cast<DatabaseTable *>( constraint->GetFKTable() )->GetTableName() )
                {
                    (*it)->Select( true );
                    fkTable = const_cast<DatabaseTable &>( (*it)->GetTable() ).GetTableName();
                    found1 = true;
                }
                if( const_cast<DatabaseTable &>( (*it)->GetTable() ).GetTableName() == refTableName )
                {
                    refTable = const_cast<DatabaseTable *>( &(*it)->GetTable() )->GetTableName();
                    found2 = true;
                }
            }
            int deleteProp, updateProp;
            FK_ONUPDATE actionUpdate;
            FK_ONDELETE actionDelete;
            Constraint::constraintAction action = constraint->GetOnDelete();
            if( action == Constraint::restrict )
            {
                deleteProp = 1;
                actionDelete = RESTRICT_DELETE;
            }
            if( action == Constraint::cascade )
            {
                deleteProp = 2;
                actionDelete = CASCADE_DELETE;
            }
            if( action == Constraint::setNull )
            {
                deleteProp = 3;
                actionDelete = SET_NULL_DELETE;
            }
            if( action == Constraint::noAction )
            {
                deleteProp = 0;
                actionDelete = NO_ACTION_DELETE;
            }
            if( action == Constraint::setDefault )
            {
                deleteProp = 4;
                actionDelete = SET_DEFAULT_DELETE;
            }
            action = constraint->GetOnUpdate();
            if( action == Constraint::restrict )
            {
                updateProp = 1;
                actionUpdate = RESTRICT_UPDATE;
            }
            if( action == Constraint::cascade )
            {
                updateProp = 2;
                actionUpdate = CASCADE_UPDATE;
            }
            if( action == Constraint::setNull )
            {
                updateProp = 3;
                actionUpdate = SET_NULL_UPDATE;
            }
            if( action == Constraint::noAction )
            {
                updateProp = 0;
                actionUpdate = NO_ACTION_UPDATE;
            }
            if( action == Constraint::setDefault )
            {
                updateProp = 4;
                actionUpdate = SET_DEFAULT_UPDATE;
            }
/*            int id = 0;
            std::vector<std::wstring>::iterator it1 = refKeyFields.begin();
            for( std::vector<std::wstring>::iterator it = foreignKeyFields.begin(); it < foreignKeyFields.end(); it++ )
            {
                newFK.push_back( new FKField( id, kName, L"", const_cast<DatabaseTable *>( constraint->GetFKTable() )->GetTableName(), (*it), L"", constraint->GetRefTable().ToStdWstring(),  (*it1), actionUpdate, actionDelete ) );
                id++;
                it1++;
            }*/
            wxDynamicLibrary lib;
#ifdef __WXMSW__
            lib.Load( "dialogs" );
#elif __WXMAC__
            lib.Load( "liblibdialogs.dylib" );
#else
            lib.Load( "libdialogs" );
#endif
            wxString constraintName = constraint->GetName();
//                std::wstring refTableName = constraint->GetRefTable().ToStdWstring();
            if( lib.IsLoaded() )
            {
                CREATEFOREIGNKEY func = (CREATEFOREIGNKEY) lib.GetSymbol( "CreateForeignKey" );
                result = func( m_view->GetFrame(), constraintName, table, foreignKeyFields, refKeyFields, const_cast<std::wstring &>( refTableName.ToStdWstring() ), deleteProp, updateProp, dynamic_cast<DrawingDocument *>( m_view->GetDocument() )->GetDatabase(),  logOnly, true, newFK, match );
                if( result != wxID_CANCEL )
                {
                    std::wstring command = L"";
                    int res = ((DrawingDocument *) m_view->GetDocument())->GetDatabase()->ApplyForeignKey( command, kName, *table, foreignKeyFields, refTableName.ToStdWstring(), refKeyFields, deleteProp, updateProp, logOnly, newFK, false, match, errors );
                    if( res )
                    {
                        for( std::vector<std::wstring>::iterator it = errors.begin(); it < errors.end(); it++ )
                        {
                            wxMessageBox( (*it), _( "Error" ), wxOK | wxICON_ERROR );
                        }
                    }
                    else if( logOnly )
                    {
                        dynamic_cast<DrawingView *>( m_view )->GetTextLogger()->AppendText( command );
                        dynamic_cast<DrawingView *>( m_view )->GetTextLogger()->AppendText( "\n\r\n\r" );
                        if( !dynamic_cast<DrawingView *>( m_view )->GetLogWindow()->IsShown() )
                            dynamic_cast<DrawingView *>( m_view )->GetLogWindow()->Show();
                    }
                    else
                    {
                        sign->DeleteConstraint();
                        m_pManager.RemoveShape( sign->GetParentShape() );
//                        Refresh();
//                        m_pManager.RemoveShape( sign );
                        if( newFK.size() > 0 )
                            CreateFKConstraint( table, newFK );
                        Refresh();
                    }
                }
                for( std::vector<FKField *>::iterator it = newFK.begin(); it < newFK.end(); ++it )
                {
                    delete (*it);
                    (*it) = NULL;
                }
                newFK.clear();
            }
        }
        else if( sign && type == QueryView )
        {
            wxDynamicLibrary lib;
#ifdef __WXMSW__
            lib.Load( "dialogs" );
#elif __WXMAC__
            lib.Load( "liblibdialogs.dylib" );
#else
            lib.Load( "libdialogs" );
#endif
            QueryConstraint *constraint = (QueryConstraint *) sign->GetConstraint();
            int type = constraint->GetSign();
            SELECTJOINTYPE func = (SELECTJOINTYPE) lib.GetSymbol( "SelectJoinType" );
            result = func( m_view->GetFrame(), const_cast<DatabaseTable *>( constraint->GetFKTable() )->GetTableName(), constraint->GetRefTable(), constraint->GetLocalColumn(), constraint->GetRefColumn(), type );
            if( type != constraint->GetSign () )
            {
                switch( type )
                {
                case 0:
                case 1:
                case 2:
                    sign->SetSign( "=" );
                    break;
                case 3:
                    sign->SetSign( "<" );
                    break;
                case 4:
                    sign->SetSign( ">" );
                    break;
                case 5:
                    sign->SetSign( "<=" );
                    break;
                case 6:
                    sign->SetSign( "<>" );
                    break;
                }
                constraint->SetSign( type );
                ((DrawingView *) m_view)->UpdateQueryFromSignChange( constraint );
            }
            sign->Select( false );
            Refresh();
        }
        m_oldSelectedSign = NULL;
    }
}