Commit d479b40c authored by Jonathan Wiedemann's avatar Jonathan Wiedemann
Browse files

add grader semaine 01

parent 87fb427f
......@@ -54,6 +54,7 @@ def make_result(r):
else:
result = 0
if DEBUG:print(u'result = ', result)
if DEBUG:print(u'End check')
return result
......@@ -103,6 +104,12 @@ def document_presence(name=None, label=None):
return make_result(r)
def get_object_by_typeId(doc=None, typeId=None):
for obj in doc.Objects:
if obj.TypeId==typeId:
return obj
break
def document_save(name=None):
'''check if a doc is saved'''
......@@ -176,10 +183,11 @@ def body_features(body):
pass
def primitive_presence(doc=None, label=None, type=None, dimensions=None, support=None, offset=None):
def primitive_presence(doc=None, label=None, typeId=None, dimensions=None, support=None, offset=None):
'''check the presence of datum plane'''
'''type : 'PartDesign::SubstractiveCylinder'
'PartDesign::AdditiveBox' '''
if DEBUG:print(u'Check primitive presence')
r=[]
doc = get_document(doc)
reference = None
......@@ -188,12 +196,13 @@ def primitive_presence(doc=None, label=None, type=None, dimensions=None, support
if label != None:
reference = doc.getObject(label)
else:
if DEBUG:print("TODO: make list of datum_plane")
pass
#if DEBUG:print(u'label is None')
reference = get_object_by_typeId(doc, typeId)
#pass
if reference:
if type != None:
if DEBUG:print(type, reference.TypeId )
if reference.TypeId == type:
if DEBUG:print(u'target',typeId,u'actual',reference.TypeId )
if reference.TypeId == typeId:
r.append(1)
else:
r.append(0)
......@@ -698,15 +707,15 @@ def mirrored_pattern_presence(doc=None, name=None, plane_name=None, plane_axis=N
result = 0
return result
def boundbox_dimensions(doc=None, name=None, obj_type=None, x=None, y=None, z=None):
def boundbox_dimensions(doc=None, name=None, typeId=None, x=None, y=None, z=None):
'''Check the length's dimensions of boundbox'''
r = []
doc = get_document(doc)
features_list = []
if doc:
for feature in doc.Objects:
if obj_type:
if feature.TypeId == obj_type:
if typeId:
if feature.TypeId == typeId:
features_list.append(feature)
else:
features_list.append(feaure)
......@@ -735,23 +744,27 @@ def boundbox_dimensions(doc=None, name=None, obj_type=None, x=None, y=None, z=No
r.append(0)
return make_result(r)
def volume(doc=None, name=None, obj_type=None, target=None):
def volume(doc=None, name=None, typeId=None, target=None):
'''Check the project volume'''
if DEBUG:print('Check volume')
r=[]
doc = get_document(doc)
features_list = []
if doc:
for feature in doc.Objects:
if obj_type:
if feature.TypeId == obj_type:
if typeId:
if feature.TypeId == typeId:
features_list.append(feature)
else:
features_list.append(feaure)
if features_list:
if features_list and target:
got_it = 0
for feature in features_list:
if not feature.Shape.isNull():
if round(target,0) == round(feature.Shape.Volume,0):
if DEBUG:print('actual volume is : ', feature.Shape.Volume)
if DEBUG:print('target volume is between : ', target - 10, u'and' , target + 10)
if (target - 10) < feature.Shape.Volume < (target + 10):
#if round(target,0) == round(feature.Shape.Volume,0):
got_it = 1
if got_it == 1:
r.append(1)
......
# coding: utf-8
################################################
#
# MoocPlayer.py
#
# Copyright 2018 Jonathan Wiedemann <contact at freecad-france dot com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
################################################
__title__="MOOC Workbench"
__author__ = "Jonathan Wiedemann"
__url__ = "http://www.freecadweb.org"
# import freecad and its gui
import FreeCAD as app
import FreeCADGui as gui
# for handling paths
import os, moocwb_locator
def get_title():
title = u'[FR] Exercice Socle (Semaine 1)'
return title
def get_description():
description = u'''[FR] Part Design Primitives Semaine 1 : Cette semaine nous \
allons voir comment modéliser le Korrigans de Steven Akoun à l'aide d'esquisses \
et de fonctions d'ajout et d'enlèvement de matière.'''
return description
def grader(doc_name):
print("MOOC FreeCAD - Grader 01 ")
print("importing MoocChecker")
# import MoocChecker
import MoocChecker
# make sure MoocChecker is reloaded
try :
reload(MoocChecker)
except NameError:
import importlib
importlib.reload(MoocChecker)
# name MoocChecker
Check = MoocChecker
grader_dict = {"notes": [], "messages": []}
doc = app.getDocument(doc_name)
step_id = 0
# Check for a Body presence
grader_dict["notes"].append(Check.body_presence(doc))
if grader_dict["notes"][step_id] == 1 :
grader_dict["messages"].append(u"Il y a un corps de pièce.")
elif grader_dict["notes"][step_id] == 0 :
grader_dict["messages"].append(u"Il n'y a pas de corps de pièce.")
step_id += 1
# Check for a Pad presence
grader_dict["notes"].append(Check.primitive_presence(doc, typeId='PartDesign::AdditiveBox'))
if grader_dict["notes"][step_id] == 1 :
grader_dict["messages"].append(u"Il y a un cube additif.")
elif grader_dict["notes"][step_id] == 0 :
grader_dict["messages"].append(u"Il n'y a pas de cube additif.")
step_id += 1
# Check for a Pocket presence
grader_dict["notes"].append(Check.primitive_presence(doc, typeId='PartDesign::AdditiveCylinder'))
if grader_dict["notes"][step_id] == 1 :
grader_dict["messages"].append(u"Il y a un cylindre additif.")
elif grader_dict["notes"][step_id] == 0 :
grader_dict["messages"].append(u"Il n'y a pas de cylindre additif.")
step_id += 1
# Check volume
grader_dict["notes"].append(Check.primitive_presence(doc, typeId='PartDesign::SubtractiveCylinder'))
if grader_dict["notes"][step_id] == 1 :
grader_dict["messages"].append(u"Il y a un cylindre soustractif.")
elif grader_dict["notes"][step_id] == 0 :
grader_dict["messages"].append(u"Il n'y a pas de cylindre soustractif.")
step_id += 1
# Check boundbox
grader_dict["notes"].append(Check.primitive_presence(doc, typeId='PartDesign::SubtractiveBox'))
if grader_dict["notes"][step_id] == 1 :
grader_dict["messages"].append(u"Il y a un cube soustractif.")
elif grader_dict["notes"][step_id] == 0 :
grader_dict["messages"].append(u"Il n'y a pas de cube soustractif.")
step_id += 1
grader_dict["notes"].append(Check.boundbox_dimensions(doc, typeId='PartDesign::Body', x = 190, y = 90, z = 15))
if grader_dict["notes"][step_id] == 1 :
grader_dict["messages"].append(u"Les dimensions extérieures correspondent avec l'objectif.")
elif grader_dict["notes"][step_id] == 0 :
grader_dict["messages"].append(u"Les dimensions extérieures ne correspondent pas avec l'objectif.")
step_id += 1
grader_dict["notes"].append(Check.volume(doc, typeId='PartDesign::Body', target=82134))
if grader_dict["notes"][step_id] == 1 :
grader_dict["messages"].append(u"Le volume du corps de pièce correspond avec l'objectif.")
elif grader_dict["notes"][step_id] == 0 :
grader_dict["messages"].append(u"Le volume du corps de pièce ne correspond pas avec l'objectif.")
return grader_dict
......@@ -315,37 +315,37 @@ def CheckResult(step_id):
if step_id == 2:
results = []
results.append(Check.primitive_presence(label="Box", type='PartDesign::AdditiveBox', dimensions=[100,80,140], support="XY_Plane", offset=[0,0,0,0,0,1,0]))
results.append(Check.primitive_presence(label="Box", typeId='PartDesign::AdditiveBox', dimensions=[100,80,140], support="XY_Plane", offset=[0,0,0,0,0,1,0]))
return results
if step_id == 3:
results = []
results.append(Check.primitive_presence(label="Cylinder", type='PartDesign::AdditiveCylinder', dimensions=[40,140], support="XY_Plane", offset=[0,40,0,0,0,1,0]))
results.append(Check.primitive_presence(label="Cylinder", typeId='PartDesign::AdditiveCylinder', dimensions=[40,140], support="XY_Plane", offset=[0,40,0,0,0,1,0]))
return results
if step_id == 4:
results = []
results.append(Check.primitive_presence(label="Cylinder001", type='PartDesign::AdditiveCylinder', dimensions=[40,140], support="XY_Plane", offset=[100,40,0,0,0,1,0]))
results.append(Check.primitive_presence(label="Cylinder001", typeId='PartDesign::AdditiveCylinder', dimensions=[40,140], support="XY_Plane", offset=[100,40,0,0,0,1,0]))
return results
if step_id == 5:
results = []
results.append(Check.primitive_presence(label="Box001", type='PartDesign::SubtractiveBox', dimensions=[80,80,20], support="XY_Plane", offset=[10.0,0.0,0.0,0.0,0.0,1.0,0.0]))
results.append(Check.primitive_presence(label="Box001", typeId='PartDesign::SubtractiveBox', dimensions=[80,80,20], support="XY_Plane", offset=[10.0,0.0,0.0,0.0,0.0,1.0,0.0]))
return results
if step_id == 6:
results = []
results.append(Check.primitive_presence(label="Cylinder002", type='PartDesign::SubtractiveCylinder', dimensions=[36,30], support="XY_Plane", offset=[0,40,110,0,0,1,0]))
results.append(Check.primitive_presence(label="Cylinder002", typeId='PartDesign::SubtractiveCylinder', dimensions=[36,30], support="XY_Plane", offset=[0,40,110,0,0,1,0]))
return results
if step_id == 7:
results = []
results.append(Check.primitive_presence(label="Cylinder003", type='PartDesign::SubtractiveCylinder', dimensions=[36,30], support="XY_Plane", offset=[100,40,110,0,0,1,0]))
results.append(Check.primitive_presence(label="Cylinder003", typeId='PartDesign::SubtractiveCylinder', dimensions=[36,30], support="XY_Plane", offset=[100,40,110,0,0,1,0]))
return results
if step_id == 8:
results = []
results.append(Check.primitive_presence(label="Box002", type='PartDesign::SubtractiveBox', dimensions=[100,72,30], support="XY_Plane", offset=[0,4,110,0,0,1,0]))
results.append(Check.primitive_presence(label="Box002", typeId='PartDesign::SubtractiveBox', dimensions=[100,72,30], support="XY_Plane", offset=[0,4,110,0,0,1,0]))
return results
if step_id == 9:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment