//
// addPedigreesFromDataTable():
//
void PedigreeSet::addPedigreesFromDataTable(const DataTable * p_pedigreeTable, unsigned tableIndex,const std::string& sortField){
	
	//
	// Use const reference for convenience:
	// (so I don't have to change the code
	//  since the parameter has changed from a
	//  const DataTable & to a const DataTable * )
	//
	const DataTable & pedigreeTable = (*p_pedigreeTable);
	
	std::cout << "Start of addPedigreesFromDataTable" << std::endl;
	
	//
	// Get all the core columns from the datatable:
	//
	DataColumn *familyIdColumn = pedigreeTable.getColumn( pedigreeTable.labels.FamilyIdField );
	//familyIdColumn->printData();
	DataColumn *individualIdColumn = pedigreeTable.getColumn( pedigreeTable.labels.IndividualIdField );
	//individualIdColumn->printData();
	DataColumn *motherIdColumn = pedigreeTable.getColumn( pedigreeTable.labels.MotherIdField );
	DataColumn *fatherIdColumn = pedigreeTable.getColumn( pedigreeTable.labels.FatherIdField );
	DataColumn *genderColumn   = pedigreeTable.getColumn( pedigreeTable.labels.GenderField );
	//
	// Insert the Pedigrees in a set:
	//
	std::string currentFamily;
	int numberOfRows = familyIdColumn->getNumberOfRows();
	int index=0;
	while(index < numberOfRows){
		
		currentFamily = familyIdColumn->get(index);
		if(currentFamily == "."){
			Warning("PedigreeSet::addPedigreesFromDataTable()",
			        "Family Id is missing for individual %s and will be ignored.",
			        individualIdColumn->get(index).c_str()
			);
			index++;
			continue;
		}
		std::pair<std::set<Pedigree*,comparePedigrees>::iterator,bool> pp;
		pp = _pedigrees.insert(new Pedigree(currentFamily,tableIndex));
		if(pp.second){
			for(int i=0;i<familyIdColumn->getNumberOfRows();i++) { 
				if(currentFamily.compare(familyIdColumn->get(i)) == 0){
					(*pp.first)->addIndividual(individualIdColumn->get(i),motherIdColumn->get(i),fatherIdColumn->get(i),genderColumn->get(i),i,tableIndex,pedigreeTable);
				}
			}
		}
		index++;
	}
	
	// Set the core optional fields on the individuals
	_setCoreOptionalFields(p_pedigreeTable);
	
	_establishConnections();
	
	bool dobPresent = false;
	if(pedigreeTable.getDOBColumnIndex() != DataTable::COLUMN_IS_MISSING){
		_checkParentChildDOB();
		dobPresent = true;
	}
	_determineFoundingGroups();
	
	bool sortFieldPresent = false;
	if(sortField != std::string("") && sortField != pedigreeTable.labels.DOBField){
		// Check to see if the field actually exists in the data table
		if(pedigreeTable.columnExists(sortField)){
			_computeWidths(sortField);
			sortFieldPresent = true;
		}else{
			Warning("PedigreeSet::addPedigreesFromDataTable()",
			        "Field '%s' specified for sorting the siblings does not exist in the Pedigree Table. Default ordering will be used.",
			        sortField.c_str()
			);
		}
	}
	if(!sortFieldPresent){
		if(dobPresent){
			std::cout << "Siblings are ordered by DOB." << std::endl;
			_computeWidths(pedigreeTable.labels.DOBField,true);
			DrawingMetrics::setDisplayBirthOrder(true);
		}else{    
			std::cout << "Default ordering of siblings." << std::endl;
			_computeWidths(std::string(""));
			
		}
	}
	std::cout << "End of addPedigreesFromDataTable" << std::endl;
	
}
Beispiel #2
0
onelabGroup::onelabGroup(int x, int y, int w, int h, const char *l)
  : Fl_Group(x, y, w, h, l), _stop(false), _enableTreeWidgetResize(false)
{
  int col = FL_BACKGROUND2_COLOR;
  color(col);

  box(GMSH_SIMPLE_RIGHT_BOX);
  int dx = Fl::box_dx(box());
  int dy = Fl::box_dy(box());
  int dw = Fl::box_dw(box());
  int dh = Fl::box_dh(box());

  _tree = new Fl_Tree(x + dx, y + dy, w - dw, h - dh - BH - 2 * WB - 6*BH);
  _tree->color(col);
  // TODO _tree->callback(onelab_tree_cb);
  _tree->connectorstyle(FL_TREE_CONNECTOR_SOLID);
  _tree->showroot(0);
  _tree->box(FL_FLAT_BOX);
  _tree->scrollbar_size(std::max(10, FL_NORMAL_SIZE - 2));
  _tree->add("0Post-processing/");
  _tree->end();

  _computeWidths();
  _widgetLabelRatio = 0.48;

  int BB2 = BB / 2 + 4;
  _butt[0] = new Fl_Button(x + w - 3 * WB - 3 * BB2, y + h - WB - BH, BB2, BH, "Check");
  _butt[0]->callback(onelab_cb, (void*)"check");

  _butt[1] = new Fl_Button(x + w - 2 * WB - 2 * BB2, y + h - WB - BH, BB2, BH, "Run");
  _butt[1]->callback(onelab_cb, (void*)"compute");

  _gear = new Fl_Menu_Button(x + w - WB - BB2, y + h - WB - BH, BB2, BH);
#if defined(__APPLE__)
  _gear->label("@-1gmsh_gear");
#else
  _gear->image(new Fl_Bitmap(gear_bits, gear_width, gear_height));
#endif
  _gear->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
  _gear->add("Reset database", 0, onelab_cb, (void*)"reset");
  _gear->add("Save database...", 0, onelab_cb, (void*)"save");
  _gear->add("_Load database...", 0, onelab_cb, (void*)"load");

  _minWindowWidth = 3 * BB2 + 4 * WB;
  _minWindowHeight = 2 * BH + 3 * WB;

  _gearOptionsStart = _gear->menu()->size();

  _gear->add("Save && load database automatically", 0, onelab_option_cb, (void*)"save",
             FL_MENU_TOGGLE);
  _gear->add("Archive output files automatically", 0, onelab_option_cb, (void*)"archive",
             FL_MENU_TOGGLE);
  _gear->add("Check model after each change", 0, onelab_option_cb, (void*)"check",
             FL_MENU_TOGGLE);
  _gear->add("Remesh automatically", 0, onelab_option_cb, (void*)"mesh",
             FL_MENU_TOGGLE);
  _gear->add("Merge results automatically", 0, onelab_option_cb, (void*)"merge",
             FL_MENU_TOGGLE);
  _gear->add("Show new views", 0, onelab_option_cb, (void*)"show",
             FL_MENU_TOGGLE);
  _gear->add("Always show last step", 0, onelab_option_cb, (void*)"step",
             FL_MENU_TOGGLE);
  _gear->add("_Show hidden parameters", 0, onelab_option_cb, (void*)"invisible",
             FL_MENU_TOGGLE);

  _gearOptionsEnd = _gear->menu()->size();

  //_gear->add("Add new solver...", 0, onelab_add_solver_cb);

  end();

  Fl_Box *resbox = new Fl_Box(x + WB, y + WB, WB, WB);
  resizable(resbox);

  rebuildSolverList();

  if(!OnelabDatabase::instance()->isNetworkClient()) OnelabDatabase::instance()->useAsClient()->setCallback(this);
}
//
// addPedigreesFromDataTable():
//
void PedigreeSet::addPedigreesFromDataTable(const DataTable * p_pedigreeTable, unsigned tableIndex,const std::string& sortField){
	
	//
	// Use const reference for convenience:
	// (so I don't have to change the code
	//  since the parameter has changed from a
	//  const DataTable & to a const DataTable * )
	//
	const DataTable & pedigreeTable = (*p_pedigreeTable);
	
	//std::cout << vt100::startBlue << "┏ Start of    addPedigreesFromDataTable ┓" << vt100::stopColor << std::endl;
	
	//
	// Get all the core columns from the datatable:
	//
	DataColumn *familyIdColumn = pedigreeTable.getColumn( pedigreeTable.labels.FamilyIdField );
	//familyIdColumn->printData();
	DataColumn *individualIdColumn = pedigreeTable.getColumn( pedigreeTable.labels.IndividualIdField );
	//individualIdColumn->printData();
	DataColumn *motherIdColumn = pedigreeTable.getColumn( pedigreeTable.labels.MotherIdField );
	DataColumn *fatherIdColumn = pedigreeTable.getColumn( pedigreeTable.labels.FatherIdField );
	DataColumn *genderColumn   = pedigreeTable.getColumn( pedigreeTable.labels.GenderField );
	
	DataColumn *collapsedColumn= 0;
	if(pedigreeTable.columnExists(pedigreeTable.labels.CollapsedField)){
		// 2015.11.30.ET ADDENDA:
		collapsedColumn=pedigreeTable.getColumn( pedigreeTable.labels.CollapsedField );
	}
	//
	// Insert the Pedigrees in a set:
	//
	std::string currentFamily;
	int numberOfRows = familyIdColumn->getNumberOfRows();
	int index=0;
	
	std::map<std::string,Individual *> collapsedIndicatorSet;
	Individual * collapsedIndividual=0;
	
	while(index < numberOfRows){
		
		currentFamily = familyIdColumn->get(index);
		if(currentFamily == "."){
			Warning("PedigreeSet::addPedigreesFromDataTable()",
			        "Family Id is missing for individual %s and will be ignored.",
			        individualIdColumn->get(index).c_str()
			);
			index++;
			continue;
		}
		std::pair<std::set<Pedigree*,comparePedigrees>::iterator,bool> pp;
		pp = _pedigrees.insert(new Pedigree(currentFamily,tableIndex));
		if(pp.second){
			for(int i=0;i<familyIdColumn->getNumberOfRows();i++) { 
				if(currentFamily.compare(familyIdColumn->get(i)) == 0){
					///////////////////////////////////
					//
					// Handle "collapsing":
					//
					///////////////////////////////////
					if(DrawingMetrics::getCollapsible() && collapsedColumn){
						std::string indicator=collapsedColumn->get(i);
						if(indicator=="."){
							// Add normal, non-collapsed individual, as usual:
							(*pp.first)->addIndividual(individualIdColumn->get(i),motherIdColumn->get(i),fatherIdColumn->get(i),genderColumn->get(i),i,tableIndex,pedigreeTable);
						}else{
							//
							// Handling collapsed individuals:
							//
							std::map<std::string,Individual *>::iterator it=collapsedIndicatorSet.find(indicator);
							if(it==collapsedIndicatorSet.end()){
								//
								// Indicator not yet present in set, so add the first marked individual
								// as the token individual:
								//
								collapsedIndividual = (*pp.first)->addIndividual(individualIdColumn->get(i),motherIdColumn->get(i),fatherIdColumn->get(i),genderColumn->get(i),i,tableIndex,pedigreeTable);
								collapsedIndividual->incrementCollapsedCount();
								collapsedIndicatorSet.insert(std::pair<std::string,Individual *>(indicator,collapsedIndividual));
								// 2015.12.01.ET DEBUG
								std::cout << "*** Individual " << individualIdColumn->get(i) << " used for collapsed group " << indicator << std::endl;
							}else{
								//////////////////////////////////////////////////
								//
								// Is gender of new person consistent?
								// 
								// Note: using Gender.getEnum() guarantees 
								// symbolic equivalency across different
								// string representations, e.g. "M"=="male", 
								// "♀"=="female", etc.
								//
								//////////////////////////////////////////////////
								if( it->second->getGender().getEnum() != Gender(genderColumn->get(i)).getEnum() ){
									// Change to missing on token individual:
									it->second->setGender(".");
								}
								//////////////////////////////////////////////////
								//
								// Is affection status of new person consistent?
								//
								//////////////////////////////////////////////////
								
								//////////////////////////////////////////////////
								//
								// increment collapsed count:
								//
								//////////////////////////////////////////////////
								it->second->incrementCollapsedCount();
								// 2015.12.01.ET DEBUG
								// std::cout << "*** Individual " << it->second->getId() << " with indicator " << indicator << " incremented to " << it->second->getCollapsedCount() << std::endl;
							}
						}
					}else{
						// CollapsedState OFF or Collapsed column not present, so just add everybody:
						(*pp.first)->addIndividual(individualIdColumn->get(i),motherIdColumn->get(i),fatherIdColumn->get(i),genderColumn->get(i),i,tableIndex,pedigreeTable);
					}
				}
			}
		}
		index++;
	}
	
	// Set the core optional fields on the individuals
	_setCoreOptionalFields(p_pedigreeTable);
	
	_establishConnections();
	
	bool dobPresent = false;
	if(pedigreeTable.getDOBColumnIndex() != DataTable::COLUMN_IS_MISSING){
		_checkParentChildDOB();
		dobPresent = true;
	}
	
	if(pedigreeTable.getPregnancyColumnIndex() != DataTable::COLUMN_IS_MISSING){
		_checkPregnancyStateValidity();
	}
	
	_determineFoundingGroups();
	
	bool sortFieldPresent = false;
	if(sortField != std::string("") && sortField != pedigreeTable.labels.DOBField){
		// Check to see if the field actually exists in the data table
		if(pedigreeTable.columnExists(sortField)){
			_computeWidths(sortField);
			sortFieldPresent = true;
		}else{
			Warning("PedigreeSet::addPedigreesFromDataTable()",
			        "Field '%s' specified for sorting the siblings does not exist in the Pedigree Table. Default ordering will be used.",
			        sortField.c_str()
			);
		}
	}
	if(!sortFieldPresent){
		if(dobPresent){
			//std::cout << "Siblings are ordered by DOB." << std::endl;
			_computeWidths(pedigreeTable.labels.DOBField,true);
			DrawingMetrics::setDisplayBirthOrder(true);
		}else{    
			//std::cout << "Default ordering of siblings." << std::endl;
			_computeWidths(std::string(""));
			
		}
	}
	//std::cout << vt100::startBlue << "┗ End of      addPedigreesFromDataTable ┛" << vt100::stopColor << std::endl;
	
}