Logo Search packages:      
Sourcecode: ktechlab version File versions  Download package

void CircuitDocument::createSubcircuit (  )  [slot]

Creates a subcircuit from the currently selected components

Definition at line 741 of file circuitdocument.cpp.

References Document::activeView(), Subcircuits::addSubcircuit(), countExtCon(), ItemDocument::itemList(), and ItemGroup::items().

{
      ItemList itemList = m_selectList->items();
      const ItemList::iterator itemListEnd = itemList.end();
      for ( ItemList::iterator it = itemList.begin(); it != itemListEnd; ++it )
      {
            if ( !dynamic_cast<Component*>((Item*)*it) )
                  *it = 0l;
      }
      itemList.remove((Item*)0l);
      
      if ( itemList.isEmpty() )
      {
            KMessageBox::sorry( activeView(), i18n("No components were found in the selection.") );
            return;
      }
      
      // Number of external connections
      const int extConCount = countExtCon(itemList);
      if ( extConCount == 0 )
      {
            KMessageBox::sorry( activeView(), i18n("No External Connection components were found in the selection.") );
            return;
      }
      
      bool ok;
      const QString name = KInputDialog::getText( "Subcircuit", "Name", QString::null, &ok, activeView() );
      if (!ok)
            return;
      
      SubcircuitData subcircuit;
      subcircuit.addItems(itemList);
      subcircuit.addNodes( getCommonNodes(itemList) );
      subcircuit.addConnectors( getCommonConnectors(itemList) );
      
      Subcircuits::addSubcircuit( name, subcircuit.toXML() );
}


Generated by  Doxygen 1.6.0   Back to index